Skip to content

Commit

Permalink
Update docstrings for readthedocs
Browse files Browse the repository at this point in the history
- Add numpydoc
- Update afids_utils.io
- Update afids_utils.transforms
  • Loading branch information
kaitj committed Jun 30, 2023
1 parent c25700f commit 3236d18
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 37 deletions.
12 changes: 4 additions & 8 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
---
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Build documentation with MkDocs
#mkdocs:
# mkdocs:
# configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF
formats:
- pdf

formats: [pdf]
build:
os: 'ubuntu-20.04'
os: ubuntu-20.04
tools:
python: '3.10'

python:
install:
- requirements: docs/requirements.txt
Expand Down
32 changes: 26 additions & 6 deletions afids_utils/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Methods for loading and saving nifti files"""
"""Methods for loading and saving files associated with AFIDs"""
from __future__ import annotations

import csv
Expand Down Expand Up @@ -34,12 +34,20 @@ def get_afid(
) -> NDArray[np.single]:
"""
Extract specific fiducial's spatial coordinates
Parameters
----------
fcsv_path : os.PathLike[str] | str
Path to .fcsv file to extract AFID coordinates from
fid_num : int
Unique fiducial number to extract from .fcsv file
Returns
-------
NDArray[np.single]
Floating-point array containing spatial coordinates (x, y, z) of single
AFID.
numpy.ndarray[shape=(3,), dtype=np.single]
NumPy array containing spatial coordinates (x, y, z) of single AFID
coordinate
"""
if fid_num < 1 or fid_num > 32:
raise InvalidFiducialNumberError(fid_num)
Expand All @@ -59,7 +67,19 @@ def afids_to_fcsv(
afid_coords: NDArray[np.single],
fcsv_output: PathLike[str] | str,
) -> None:
"""AFIDS to Slicer-compatible .fcsv file"""
"""
Save AFIDS to Slicer-compatible .fcsv file
Parameters
----------
afid_coords : numpy.ndarray[shape=(N, 3), dtype=np.single]
Floating-point NumPy array containing spatial coordinates (x, y, z) of
`N` AFIDs
fcsv_output : os.PathLike[str] | str
Path of file (including filename and extension) to save AFIDs to
"""
# Read in fcsv template
with resources.open_text(
"afids_utils.resources", "template.fcsv"
Expand Down
20 changes: 19 additions & 1 deletion afids_utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ def afid_world2voxel(
afid_world: NDArray[np.float_],
nii_affine: NDArray[np.float_],
) -> NDArray[np.int_]:
"""Transform fiducials in world coordinates to voxel coordinates"""
"""
Transform fiducials from world coordinates to voxel coordinates
Parameters
----------
afid_world : numpy.ndarray[shape=(3,), dtype=numpy.float_]
NumPy array containing floating-point spatial coordinates (x, y, z) to
transform
nii_affine : numpy.ndarray[shape=(4, 4), dtype=numpy.float_]
NumPy array containing affine transformation associated with
NifTI image
Returns
-------
numpy.ndarray[shape=(3,), dtype=numpy.float_]
NumPy array containing indices corresponding to voxel location along
spatial dimensions
"""

# Translation
afid_voxel = afid_world.T - nii_affine[:3, 3:4]
Expand Down
25 changes: 8 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# -- Project information -----------------------------------------------------

project = "AFIDs Utils"
release = ilm.version("afids_utils")
copyright = f"{datetime.date.today().year}, Anatomical Fiducials"
author = "Anatomical Fiducials Contributors"

Expand All @@ -32,15 +33,15 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx_copybutton",
"sphinx_design",
"sphinx_reredirects",
"sphinxarg.ext",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinxcontrib.asciinema",
"myst_parser",
"sphinx_copybutton",
"sphinx_reredirects",
"sphinx_design",
"numpydoc",
]


Expand All @@ -62,15 +63,10 @@

autodoc_member_order = "bysource"
autodoc_typehints = "description"
# autodoc_type_aliases = {
# "ZipList": "snakebids.types.ZipList",
# "ZipListLike": "snakebids.types.ZipListLike",
# "InputsConfig": "snakebids.types.InputsConfig",
# }
# autodoc_type_aliases = {}
autodoc_typehints_format = "short"
autosummary_imported_members = True


# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand All @@ -84,6 +80,7 @@

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/1.24", None),
}


Expand All @@ -110,9 +107,3 @@
# redirects = {
# "migration/0.5_to_0.6.md": "migration/0.5_to_0.8.html",
# }

# sphinxcontrib_asciinema_defaults = {
# "preload": 1,
# "rows": 24,
# "speed": 3,
# }
10 changes: 5 additions & 5 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sphinx-argparse>=0.4.0,<0.5
sphinxcontrib-asciinema>=0.3.7,<0.4
myst-parser>=1.0.0,<2.0
furo>=2023.3.23,<2024
sphinx_copybutton>=0.5.1,<0.6
sphinx-copybutton>=0.5.1,<0.6
sphinx-design>=0.4.1,<0.5.0
sphinx-reredirects>=0.1,<0.2
sphinx_design>=0.4.1,<0.5.0
furo>=2023.3.23,<2024
myst-parser>=1.0.0,<2.0
numpydoc>=1.5.0,<1.6

0 comments on commit 3236d18

Please sign in to comment.