Skip to content

Commit

Permalink
Update docstrings for readthedocs
Browse files Browse the repository at this point in the history
- Add numpydoc
- Split submodule pages and add overview page
- Update afids_utils.io
- Update afids_utils.transforms
  • Loading branch information
kaitj committed Jun 30, 2023
1 parent c25700f commit 769f017
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 48 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
6 changes: 6 additions & 0 deletions docs/api/io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## afids_utils.io

```{eval-rst}
.. automodule:: afids_utils.io
:members:
```
9 changes: 0 additions & 9 deletions docs/api/main.md → docs/api/transform.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# API

## afids_utils.io

```{eval-rst}
.. automodule:: afids_utils.io
:members:
```

## afids_utils.transforms

```{eval-rst}
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,
# }
33 changes: 33 additions & 0 deletions docs/general/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Overview

The purpose of the `afids_utils` package is to provide commonly used utility
functions (written in Python) that is applicable to a various anatomical
fiducial (AFIDS) projects. The `afids_utils` documentation provides a
comprehensive reference guide designed to assist users and developers in
effectively utilizing the functionalities provided by the package's
application programming interface (API). It serves as a centralized resource
that offers detailed information about the various modules, classes, functions,
and constants available within the `afids_utils` package.

Following the introduction, the API Reference pages provide a structured
organization of the package's modules and classes. Each module is described, explaining its role and the specific functionalities it offers. Detailed
information is provided for each class, including its methods, attributes, and
inheritance hierarchy, along with explanations of their purposes and usage.

Additionally, the API page includes comprehensive documentation for the
functions and constants within the package. It describes the parameters
expected by each function, their data types, and their respective return
values. The documentation also highlights any optional parameters, default
values, and notable exceptions that may be raised.

To assist developers in understanding and effectively utilizing the
`afids_utils` package, the API page may include code examples that
demonstrate the practical usage of the various modules, classes, functions,
and constants. These examples showcase common use cases, allowing developers
to grasp the concepts quickly and integrate them into their own projects.

Furthermore, the API page may provide guidelines and best practices specific to
the `afids_utils` package. It may include recommendations on code structure,
error handling, performance optimization, and any other considerations that can
enhance the developer experience and ensure reliable and efficient usage of the
package.
15 changes: 13 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
```

```{toctree}
:caption: Reference
:caption: General
:name: general
:hidden:
:maxdepth: 2
general/main
```

```{toctree}
:caption: API Reference
:name: api_reference
:hidden:
:maxdepth: 1
api/main
api/io
api/transform
```
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 769f017

Please sign in to comment.