Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Page #8

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# .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:
# configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF
formats: [pdf]
build:
os: ubuntu-20.04
tools:
python: '3.10'
python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Anatomical Fiducials (AFIDs) Utility Tools

[![Documentation Status](https://readthedocs.org/projects/afids-utils/badge/?version=latest)](https://afids-utils.readthedocs.io/en/latest/?badge=latest)

The `afids_utils` package provides common utilities for projects involving
anatomical fiducials (AFIDs). For a comprehensive list of available utilities
refer to the [documentation](https://afids-utils.readthedocs.io/en/stable)
page.
34 changes: 31 additions & 3 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 @@ -32,7 +32,23 @@
def get_afid(
fcsv_path: PathLike[str] | str, fid_num: int
) -> NDArray[np.single]:
"""Extract specific fiducial's spatial coordinates"""
"""
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
-------
numpy.ndarray[shape=(3,), dtype=numpy.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)
fcsv_df = pl.scan_csv(
Expand All @@ -51,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=numpy.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
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
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:
```
6 changes: 6 additions & 0 deletions docs/api/transform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## afids_utils.transforms

```{eval-rst}
.. automodule:: afids_utils.transforms
:members:
```
109 changes: 109 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# flake8: noqa
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

import datetime
import importlib.metadata as ilm

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys

sys.path.insert(0, os.path.abspath("../"))

# -- Project information -----------------------------------------------------

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


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# 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",
"myst_parser",
"numpydoc",
]


myst_enable_extensions = [
"attrs_block",
]
myst_enable_extensions = [
"attrs_block",
"attrs_inline",
"tasklist",
"deflist",
"fieldlist",
]
myst_number_code_blocks = ["python", "yaml"]


napoleon_google_docstring = False
napoleon_numpy_docstring = True

autodoc_member_order = "bysource"
autodoc_typehints = "description"
# 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"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


master_doc = "index"

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


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"
html_theme_options = {
"source_repository": "https://github.com/afids/afids-utils",
"source_branch": "main",
"source_directory": "docs/",
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
# templates_path = ["_templates"]

html_css_files = ["css/typealiases.css"]

# redirects = {
# "migration/0.5_to_0.6.md": "migration/0.5_to_0.8.html",
# }
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```{include} ../README.md
```

```{toctree}
:caption: API Reference
:name: api_reference
:hidden:
:maxdepth: 1

api/io
api/transform
```
7 changes: 7 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sphinx-argparse>=0.4.0,<0.5
sphinx-copybutton>=0.5.1,<0.6
sphinx-design>=0.4.1,<0.5.0
sphinx-reredirects>=0.1,<0.2
furo>=2023.3.23,<2024
myst-parser>=1.0.0,<2.0
numpydoc>=1.5.0,<1.6