For developers

Contributing

NiFreeze is a project of the NiPreps Community, which specifies the contributing guidelines. Before delving into the code, please make sure you have read all the guidelines offered online.

Documentation

Documentation sources are found under the docs/ folder, and builds are archived in the gh-pages branch of the repository. With GitHub Pages, the documentation is posted under https://www.nipreps.org/nifreeze. The documentation is versioned by release series: folder <major>.<minor>/ holds the latest release of that series, or its latest pre-release until the release. For example, 0.1/ holds the documents of the latest 0.1.x release, and a tag such as 26.0.0rc1 publishes 26.0/, which 26.0.0 then replaces. A pre-release never replaces a release. With every commit (or merge commit) to main, the development version of the documentation under the folder main/ is updated too. The site’s root and its version menu send visitors to the latest release, and the pages of the development version, of pre-releases and of older releases say so in a banner. The Docs workflow maintains the gh-pages branch with tools/docs_versions.py, which also writes the list of versions (versions.json) and the root and 404 pages. Please, do not commit manually to gh-pages: each deploy replaces it with a single commit, without history (.github/actions/gh-pages-deploy). The same workflow builds the documentation of every pull request, and the job summary links the HTML (the docs-html artifact).

To build the documentation locally:

cd <nifreeze-repository>/
pip install -e .[doc]
python -m hatch version  # This will generate ``src/nifreeze/_version.py``
python tools/fetch_gallery.py  # The gallery's pages (needs ``gh auth``); placeholders otherwise
make -C docs/ html

The citation page includes docs/_static/citation.txt, which CI generates from CITATION.cff (.github/scripts/generate_citation_artifact.sh).

Benchmarking

NiFreeze uses asv for performance benchmarking. Benchmarking code is found under the benchmarks/ folder. Maintaining reasonable runtime and memory consumption of core NiFreeze components (e.g., models, data I/O, estimator) is critical for the efficiency of pipelines using it.

The benchmarks measure the memory that operations allocate, their peak resident memory, their CPU time and their wall time. Every pull request that changes the package, its dependencies or the benchmarks is benchmarked together with the tip of main in the same job, and fails if it makes a benchmark regress past the threshold of its kind; the job summary lists every result. The results of each commit to main are published in the nifreeze dashboard. benchmarks/README.rst describes the thresholds, how to run the benchmarks locally, and how to write new ones.

Slow tests

Tests marked slow check exhaustive grids of cases, such as every combination of rotations and translations in test_ANTs_config_b0. A plain pytest runs them. The test workflow deselects them on pull requests and pushes, and runs them weekly and on demand. To deselect them locally:

pytest -m "not e2e and not slow"

End-to-end tests

test/test_e2e_motion.py moves every diffusion-weighted volume of DIPY’s Sherbrooke dataset by a known random rigid transform, runs the command line with several models, and compares the estimated motion with the ground truth. On a copy with eddy currents too, it runs a cascade of models and then an eddy-current pass (--eddy), and compares the head motion, the eddy currents and the whole mapping with their ground truth. These tests are deselected by default. They register with the default backend, or with the one NIFREEZE_E2E_REGISTRATION names, and run with:

NIFREEZE_E2E_REGISTRATION=ants pytest -m e2e test/test_e2e_motion.py

The End-to-end tests workflow runs them weekly, on demand, and on pull requests that change them, and lists the errors of every model and of the cascade in its job summary. Every run registers with elastix, and the weekly run with ANTs as well.

Library API (application program interface)

Information on specific functions, classes, and methods.