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.
- nifreeze.analysis package
- Submodules
- nifreeze.analysis.filtering module
- nifreeze.analysis.measure_agreement module
- nifreeze.analysis.motion module
- nifreeze.analysis.phantoms module
- nifreeze.analysis.registration module
- nifreeze.analysis.sensitivity module
- nifreeze.analysis.similarity module
- Submodules
- nifreeze.cli package
- nifreeze.data package
load()- Subpackages
- nifreeze.data.dmri package
- dMRI data representation
DWIfrom_nii()- Submodules
- nifreeze.data.dmri.base module
- nifreeze.data.dmri.io module
- nifreeze.data.dmri.utils module
BVEC_FRAMESBVEC_FRAME_ERROR_MSGDEFAULT_GRADIENT_ATOLDEFAULT_HIGHB_THRESHOLDDEFAULT_LOWB_THRESHOLDDEFAULT_MAX_S0DEFAULT_MIN_S0DEFAULT_MULTISHELL_BIN_COUNT_THRDEFAULT_NUM_BINSDTI_MIN_ORIENTATIONSGRADIENT_ABSENCE_ERROR_MSGGRADIENT_EXPECTED_COLUMNS_ERROR_MSGGRADIENT_NDIM_ERROR_MSGGRADIENT_OBJECT_ERROR_MSGGRADIENT_VOLUME_DIMENSIONALITY_MISMATCH_ERRORPHASE_ENCODING_DIRECTIONSPHASE_ENCODING_ERROR_MSGbvecs_from_ras()bvecs_to_ras()find_shelling_scheme()format_gradients()format_phase_encoding()realign_bvecs()
- nifreeze.data.pet package
- PET data representation
PETfrom_nii()- Submodules
- nifreeze.data.pet.base module
- nifreeze.data.pet.io module
- nifreeze.data.pet.utils module
- nifreeze.data.dmri package
- Submodules
- nifreeze.data.base module
AFFINE_ABSENCE_ERROR_MSGAFFINE_NDIM_ERROR_MSGAFFINE_OBJECT_ERROR_MSGAFFINE_SHAPE_ERROR_MSGBRAINMASK_SHAPE_MISMATCH_ERROR_MSGBaseDatasetBaseDataset.ESTIMATESBaseDataset.__len__()BaseDataset.affineBaseDataset.brainmaskBaseDataset.datahdrBaseDataset.dataobjBaseDataset.from_filename()BaseDataset.get_filename()BaseDataset.get_transform()BaseDataset.motionBaseDataset.realign_into()BaseDataset.realigned()BaseDataset.set_estimates()BaseDataset.set_transform()BaseDataset.shape3dBaseDataset.size3dBaseDataset.to_filename()BaseDataset.to_nifti()
DATAOBJ_ABSENCE_ERROR_MSGDATAOBJ_NDIM_ERROR_MSGDATAOBJ_OBJECT_ERROR_MSGESTIMATES_FIELD_ERROR_MSGImageGridNFHDF5_RASB_VERSIONNFHDF5_VERSIONto_nifti()validate_affine()validate_dataobj()
- nifreeze.data.filtering module
BVAL_ATOLCLIPPING_DEGENERATE_RANGE_ERROR_MSGCLIPPING_EMPTY_SELECTION_ERROR_MSGCLIPPING_INVALID_THRESHOLDS_ERROR_MSGCLIPPING_NONFINITE_THRESHOLDS_ERROR_MSGClippingValueErrorDEFAULT_CLIP_PERCENTILEDEFAULT_DTYPEadvanced_clip()dwi_select_shells()grand_mean_normalization()robust_minmax_normalization()robust_window()
- nifreeze.data.splitting module
- nifreeze.data.utils module
- nifreeze.data.base module
- nifreeze.estimator module
- nifreeze.exceptions module
- nifreeze.model package
AverageDWIModelBSplinePETModelDKIModelDTIModelExpectationModelGPLOOModelGPModelGQIKRRModelModelFactoryTrivialModel- Submodules
- nifreeze.model.base module
- nifreeze.model.dki module
- nifreeze.model.dmri module
- nifreeze.model.gpr module
- nifreeze.model.gqi module
- nifreeze.model.lovo module
- nifreeze.model.pet module
- nifreeze.registration package
RegistrationRegistrationFactory- Submodules
- nifreeze.registration.ants module
- nifreeze.registration.base module
- nifreeze.registration.elastix module
- nifreeze.registration.itk_backend module
- nifreeze.registration.utils module
- nifreeze.testing package
- Submodules
- nifreeze.testing.perturbations module
- nifreeze.testing.phantoms module
- nifreeze.testing.simulations module
BOUNDS_2FIBERS_DOMINANT_VF1BOUNDS_2FIBERS_NONDOMINANT_VF1BOUNDS_3FIBERS_VF1BOUNDS_3FIBERS_VF2BOUNDS_LAMBDA1BOUNDS_LAMBDA23add_b0()compute_pet_noise_sd()create_diffusion_encoding_gradient_dirs()create_random_diffusivity_eigenvalues()create_random_polar_angles()create_random_polar_coordinates()create_single_fiber_evecs()create_single_shell_gradient_table()create_three_fiber_random_volume_fractions()create_two_fiber_dominant_random_volume_fractions()create_two_fiber_nondominant_random_volume_fractions()get_query_vectors()group_values()serialize_dmri()serialize_dwi()serialize_gtab()simulate_multifiber_voxels()simulate_one_fiber_multivoxel()simulate_three_fiber_multivoxel()simulate_two_fiber_multivoxel()simulate_voxels()single_fiber_voxel()srtm()
- Submodules
- nifreeze.utils package
- Submodules
- nifreeze.utils.iterators module
BVALS_KWARGDEFAULT_ROUND_DECIMALSITERATOR_MULTIPLICITY_ERROR_MSGITERATOR_SIZE_ERROR_MSGMODALITY_SPECIFIC_SIZE_KEYSSIZE_KEYSSIZE_KWARGSTART_INDEX_DATA_LENGTH_ERROR_MSGSTART_INDEX_KWARGSTART_INDEX_POSITIVITY_ERROR_MSGSTOP_INDEX_DATA_LENGTH_ERROR_MSGSTOP_INDEX_KWARGSTOP_INDEX_ORDERING_ERROR_MSGUPTAKE_KWARGcentralsym_iterator()linear_iterator()monotonic_value_iterator()random_iterator()
- nifreeze.utils.ndimage module
- nifreeze.utils.iterators module
- Submodules
- nifreeze.viz package