This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
sMRIPrep is a structural MRI preprocessing pipeline in the NiPreps ecosystem (alongside fMRIPrep, dMRIPrep). It preprocesses T1w/T2w/FLAIR anatomical MRI data following BIDS conventions. It uses Nipype workflow engine, FreeSurfer, ANTs, FSL, and Connectome Workbench.
# Run full test suite (uses pytest-xdist for parallelism)
tox
# Run tests for a specific Python version
tox -e py312-latest
# Run a single test file
pytest src/smriprep/interfaces/tests/test_surf.py
# Run a single test
pytest src/smriprep/interfaces/tests/test_surf.py::test_function_name
# Note: default pytest addopts include -svx, --doctest-modules, --cov
# To skip doctests when running a subset:
pytest --override-ini="addopts=" src/smriprep/interfaces/tests/test_surf.py# Check style (ruff lint + format check)
tox -e style
# Auto-fix style issues
tox -e style-fix
# Spell check
tox -e spellcheck
# Direct ruff usage
ruff check --diff
ruff format --difftox -e build- Formatter/Linter: Ruff (line length 99, single quotes)
- Quote style: Single quotes everywhere
- Black is explicitly disabled
Uses src/ layout: all source code lives under src/smriprep/.
The core of the pipeline. All workflows are Nipype pe.Workflow objects built by init_*_wf() factory functions.
base.py— Top-level orchestratorinit_smriprep_wf()→ creates per-subject workflowsanatomical.py— Core anatomical pipelineinit_anat_preproc_wf(): validation → conformance → bias correction (N4) → skull stripping (ANTs) → segmentation (FAST) → spatial normalization → optional FreeSurfer surface reconstructionsurfaces.py— Surface processing: FreeSurfer recon, GIFTI conversion, fsLR registration (MSM), grayordinates (CIFTI), HCP morphometricsoutputs.py— BIDS-Derivatives output writing viaDerivativesDataSinkfit/registration.py— Spatial normalization (registration to standard templates)
Custom Nipype interfaces wrapping external tools (FreeSurfer, FSL, Workbench, MSM) and internal operations (GIFTI/CIFTI manipulation, TemplateFlow queries, surface operations).
BIDS-App compliant command-line interface. Entry point: smriprep.cli.run:main.
- niworkflows — Shared NiPreps building blocks (brain extraction, image utilities, BIDS I/O)
- templateflow — Standardized neuroimaging templates
- nireports — Visual QC reports
- nitransforms — Spatial transforms
- Workflow factory functions:
init_<name>_wf() - Workflow variables end in
_wf - Node names must match their variable names (aids debugging working directories)
- PR titles use prefixes:
ENH,FIX,TST,DOC,STY,REF,CI,MAINT
Key variables passed through tox: TEMPLATEFLOW_HOME, FREESURFER_HOME, SUBJECTS_DIR, FS_LICENSE, TEST_DATA_HOME, TEST_OUTPUT_DIR, TEST_WORK_DIR.