Developers - API
Internal configuration system
A Python module to maintain unique, run-wide QSIPrep settings.
This module implements the memory structures to keep a consistent, singleton config.
Settings are passed across processes via filesystem, and a copy of the settings for
each run and subject is left under
<output_dir>/sub-<participant_id>/log/<run_unique_id>/qsiprep.toml
.
Settings are stored using ToML.
The module has a to_filename()
function to allow writing out
the settings to hard disk in ToML format, which looks like:
[environment]
cpu_count = 1
exec_env = "docker"
free_mem = 52.2
overcommit_policy = "heuristic"
overcommit_limit = "50%"
nipype_version = "1.9.1"
templateflow_version = "23.1.0"
version = "1.0.0rc2.dev29+gdee1425.d20250113"
[execution]
bids_dir = "/tmp/src/qsiprep/.circleci/data/forrest_gump"
bids_database_dir = "/tmp/src/qsiprep/.circleci/work/forrest_gump/20250113-154517_1f7046f7-c5b1-4151-84ca-755a96dfbb55/bids_db"
bids_description_hash = "86891931159357fa937a6724ac27013f79ca56859100547ed9793245866312cd"
boilerplate_only = false
sloppy = true
debug = []
layout = "BIDS Layout: ...ep/.circleci/data/forrest_gump | Subjects: 1 | Sessions: 1 | Runs: 0"
log_dir = "/tmp/src/qsiprep/.circleci/out/forrest_gump/logs"
log_level = 15
low_mem = false
notrack = true
output_dir = "/tmp/src/qsiprep/.circleci/out/forrest_gump"
reports_only = false
run_uuid = "20250113-154517_1f7046f7-c5b1-4151-84ca-755a96dfbb55"
participant_label = [ "01",]
processing_list = [ "01:forrestgump",]
skip_anat_based_spatial_normalization = false
templateflow_home = "/home/qsiprep/.cache/templateflow"
work_dir = "/tmp/src/qsiprep/.circleci/work/forrest_gump"
write_graph = true
[workflow]
anat_modality = "T1w"
anat_only = false
anatomical_template = "MNI152NLin2009cAsym"
b0_threshold = 100
b0_motion_corr_to = "iterative"
b0_to_t1w_transform = "Rigid"
b1_biascorrect_stage = "none"
denoise_after_combining = false
denoise_method = "none"
distortion_group_merge = "none"
dwi_denoise_window = "auto"
dwi_no_biascorr = false
dwi_only = false
fmap_bspline = false
force_syn = false
hmc_model = "eddy"
hmc_transform = "Affine"
ignore = []
infant = false
intramodal_template_iters = 0
intramodal_template_transform = "BSplineSyN"
subject_anatomical_reference = "first-alphabetically"
longitudinal = false
no_b0_harmonization = false
output_resolution = 5.0
pepolar_method = "TOPUP"
separate_all_dwis = false
shoreline_iters = 2
use_syn_sdc = false
spaces = "MNI152NLin2009cAsym"
[nipype]
crashfile_format = "txt"
get_linked_libs = false
nprocs = 4
omp_nthreads = 4
plugin = "MultiProc"
remove_unnecessary_outputs = true
resource_monitor = false
stop_on_first_crash = true
[seeds]
master = 20506
ants = 2720
numpy = 32806
[execution.derivatives]
[execution.dataset_links]
raw = "/tmp/src/qsiprep/.circleci/data/forrest_gump"
templateflow = "/home/qsiprep/.cache/templateflow"
[nipype.plugin_args]
maxtasksperchild = 1
raise_insufficient = false
[execution.bids_filters.t1w]
reconstruction = "autobox"
[execution.bids_filters.t2w]
reconstruction = "autobox"
This config file is used to pass the settings across processes,
using the load()
function.
Configuration sections
- class qsiprep.config.environment[source]
Read-only options regarding the platform and environment.
Crawls runtime descriptive settings (e.g., default FreeSurfer license, execution environment, nipype and QSIPrep versions, etc.). The
environment
section is not loaded in from file, only written out when settings are exported. This config section is useful when reporting issues, and these variables are tracked whenever the user does not opt-out using the--notrack
argument.- cpu_count = 2
Number of available CPUs.
- exec_docker_version = None
Version of Docker Engine.
- exec_env = 'posix'
A string representing the execution platform.
- free_mem = 6.0
Free memory at start.
- nipype_version = '1.9.1'
Nipype’s current version.
- overcommit_limit = '50%'
Linux’s kernel virtual memory overcommit limits.
- overcommit_policy = 'heuristic'
Linux’s kernel virtual memory overcommit policy.
- templateflow_version = '24.2.2'
The TemplateFlow client version installed.
- version = '1.0.2.dev2+g00c73c4'
QSPrep’s version.
- class qsiprep.config.execution[source]
Configure run-level settings.
- bids_database_dir = None
Path to the directory containing SQLite database indices for the input BIDS dataset.
- bids_description_hash = None
Checksum (SHA256) of the
dataset_description.json
of the BIDS dataset.
- bids_dir = None
An existing path to the dataset, which must be BIDS-compliant.
- bids_filters = None
A dictionary of BIDS selection filters.
- boilerplate_only = False
Only generate a boilerplate.
- dataset_links = {}
A dictionary of dataset links to be used to track Sources in sidecars.
- debug = []
Debug mode(s).
- derivatives = {}
Path(s) to search for pre-computed derivatives
- log_dir = None
The path to a directory that contains execution logs.
- log_level = 25
Output verbosity.
- low_mem = None
Utilize uncompressed NIfTIs and other tricks to minimize memory allocation.
- notrack = False
Do not collect telemetry information for QSIPrep.
- output_dir = None
Folder where derivatives will be stored.
- output_layout = None
Layout of derivatives within output_dir.
- participant_label = None
List of participant identifiers that are to be preprocessed.
- processing_list = []
List of (subject_id, [session_id, …]) to be preprocessed together.
- reports_only = False
Only build the reports, based on the reportlets found in a cached working directory.
- run_uuid = '20250409-164410_ad156e64-e259-4ed4-87f9-a8168cc22e38'
Unique identifier of this particular run.
- session_id = None
List of session identifiers that are to be preprocessed
- skip_anat_based_spatial_normalization = False
Should we skip normalizing the anatomical data to a template?
- sloppy = False
Run in sloppy mode (meaning, suboptimal parameters that minimize run-time).
- templateflow_home = PosixPath('/home/docs/.cache/templateflow')[source]
The root folder of the TemplateFlow client.
- work_dir = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/qsiprep/checkouts/latest/docs/work')[source]
Path to a working directory where intermediate results will be available.
- write_graph = False
Write out the computational graph corresponding to the planned preprocessing.
- class qsiprep.config.workflow[source]
Configure the particular execution graph of this workflow.
- anat_modality = None
Modality to use as the anatomical reference. Images of this contrast will be skull stripped and segmented for use in the visual reports. If –infant, T2w is forced.
- anat_only = False
Execute the anatomical preprocessing only.
- anatomical_template = None
Anatomical template to use. This field doesn’t include the cohort.
- b0_motion_corr_to = None
Perform SHORELine’s initial b=0-based registration to first volume? Or make a template? Either ‘iterative’ or ‘first’
- b0_threshold = None
Any value in the .bval file less than this will be considered a b=0 image.
- b0_to_t1w_transform = None
Transformation model for intramodal registration.
- b1_biascorrect_stage = None
The stage of processing at which to apply B1 bias correction. Either “final” (after resampling), “none” (skipped entirely) or “legacy” (before concatenation).
- denoise_after_combining = False
Run
dwidenoise
after combining dwis, but before motion correction.
- denoise_method = None
Image-based denoising method. Either “dwidenoise” (MRtrix), “patch2self” (DIPY) or “none”.
- distortion_group_merge = None
How to combine images across distortion groups (concatenate, average or none).
- dwi_denoise_window = None
Window size in voxels for image-based denoising, integer or “auto”.
- dwi_no_biascorr = None
see –b1-biascorrect-stage.
- Type:
DEPRECATED
- dwi_only = False
True if anat_modality is ‘none’.
- Type:
DEPRECATED
- eddy_config = None
Configuration for running Eddy.
- fmap_bspline = None
Regularize fieldmaps with a field of B-Spline basis.
- fmap_demean = None
Remove the mean from fieldmaps.
- force_syn = None
Run fieldmap-less susceptibility-derived distortions estimation.
- hmc_model = None
Model used to generate target images for hmc.
- hmc_transform = None
Transformation to be used in SHORELine.
- ignore = None
Ignore particular steps for QSIPrep.
- infant = False
Configure pipelines specifically for infant brains
- intramodal_template_iters = None
Number of iterations for intramodal template construction.
- intramodal_template_transform = None
Transformation used for building the intramodal template.
- longitudinal = False
Run FreeSurfer
recon-all
with the-longitudinal
flag. [Deprecated]
- no_b0_harmonization = False
Skip re-scaling dwi scans to have matching b=0 intensities.
- output_resolution = None
Isotropic voxel size for outputs.
- pepolar_method = None
SDC method to be used for PEPOLAR fieldmaps.
- separate_all_dwis = False
Process all dwis separately - do not attempt concatenation.
- shoreline_iters = None
How many iterations to run SHORELine.
- subject_anatomical_reference = None
sessionwise, unbiased or first-alphabetically
- Type:
How should the anatomical space be defined
- unringing_method = None
Method for Gibbs-ringing removal. Either “none”, “mrdegibbs” or “rpg”.
- use_syn_sdc = None
Run fieldmap-less susceptibility-derived distortions estimation in the absence of any alternatives.
- class qsiprep.config.nipype[source]
Nipype settings.
- crashfile_format = 'txt'
The file format for crashfiles, either text (txt) or pickle (pklz).
- get_linked_libs = False
Run NiPype’s tool to enlist linked libraries for every interface.
- memory_gb = None
Estimation in GB of the RAM this workflow can allocate at any given time.
- nprocs = 2
Number of processes (compute tasks) that can be run in parallel (multiprocessing only).
- omp_nthreads = None
Number of CPUs a single process can access for multithreaded execution.
- plugin = 'MultiProc'
NiPype’s execution plugin.
- plugin_args = {'maxtasksperchild': 1, 'raise_insufficient': False}
Settings for NiPype’s execution plugin.
- remove_unnecessary_outputs = True
Clean up unused outputs after running
- resource_monitor = False
Enable resource monitor.
- stop_on_first_crash = True
Whether the workflow should stop or continue after the first error.
Usage
A config file is used to pass settings and collect information as the execution graph is built across processes.
from qsiprep import config
config_file = config.execution.work_dir / '.qsiprep.toml'
config.to_filename(config_file)
# Call build_workflow(config_file, retval) in a subprocess
with Manager() as mgr:
from .workflow import build_workflow
retval = mgr.dict()
p = Process(target=build_workflow, args=(str(config_file), retval))
p.start()
p.join()
config.load(config_file)
# Access configs from any code section as:
value = config.section.setting
Logging
Other responsibilities
The config
is responsible for other conveniency actions.
Switching Python’s
multiprocessing
to forkserver mode.Set up a filter for warnings as early as possible.
Automated I/O magic operations. Some conversions need to happen in the store/load processes (e.g., from/to
Path
<->str
,BIDSLayout
, etc.)
- qsiprep.config.from_dict(settings, init=True, ignore=None)[source]
Read settings from a flat dictionary.
- qsiprep.config.load(filename, skip=None, init=True)[source]
Load settings from file.
- Parameters:
filename (
os.PathLike
) – TOML file containing QSIPrep configuration.skip (dict or None) – Sets of values to ignore during load, keyed by section name
init (bool or
Container
) – Initialize all, none, or a subset of configurations.
Library API
Preprocessing Workflows
- qsiprep.workflows.base module
- qsiprep.workflows.anatomical package
- qsiprep.workflows.dwi package
- Pre-processing q-space Image workflows
- Submodules
- qsiprep.workflows.dwi.base module
- qsiprep.workflows.dwi.confounds module
- qsiprep.workflows.dwi.derivatives module
- qsiprep.workflows.dwi.distortion_group_merge module
- qsiprep.workflows.dwi.finalize module
- qsiprep.workflows.dwi.fsl module
- qsiprep.workflows.dwi.hmc module
- qsiprep.workflows.dwi.hmc_sdc module
- qsiprep.workflows.dwi.intramodal_template module
- qsiprep.workflows.dwi.merge module
- qsiprep.workflows.dwi.pre_hmc module
- qsiprep.workflows.dwi.qc module
- qsiprep.workflows.dwi.registration module
- qsiprep.workflows.dwi.resampling module
- qsiprep.workflows.dwi.util module
- qsiprep.workflows.fieldmap package
- Fieldmap estimation and unwarping workflows
- Automatic selection of the appropriate SDC method
init_sdc_wf()
- Phase Encoding POLARity (PEPOLAR) techniques
init_extended_pepolar_report_wf()
init_pepolar_unwarp_wf()
init_prepare_dwi_epi_wf()
- Phase-difference B0 estimation
init_phdiff_wf()
- Direct B0 mapping sequences
init_fmap_wf()
- Fieldmap-less estimation (experimental)
ThreshAndBin
init_syn_sdc_wf()
- Unwarping
init_fmap_unwarp_report_wf()
init_sdc_unwarp_wf()
init_drbuddi_wf()
init_fmap_unwarp_report_wf()
init_pepolar_unwarp_wf()
init_sdc_unwarp_wf()
init_sdc_wf()
init_syn_sdc_wf()
- Submodules
- qsiprep.workflows.fieldmap.base module
- qsiprep.workflows.fieldmap.drbuddi module
- qsiprep.workflows.fieldmap.fmap module
- qsiprep.workflows.fieldmap.pepolar module
- qsiprep.workflows.fieldmap.phdiff module
- qsiprep.workflows.fieldmap.syn module
- qsiprep.workflows.fieldmap.unwarp module
- qsiprep.workflows.fieldmap.utils module
- Fieldmap estimation and unwarping workflows
Other Utilities
- qsiprep.interfaces package
AboutSummary
AddTSVHeader
BIDSDataGrabber
BIDSInfo
ConcatAffines
Conform
ConformDwi
DMRISummary
DerivativesDataSink
DerivativesMaybeDataSink
FieldToHz
FieldToRadS
GatherConfounds
IntraModalMerge
Phasediff2Fieldmap
Phases2Fieldmap
StructuralReference
SubjectSummary
ValidateImage
- Submodules
- qsiprep.interfaces.anatomical module
- qsiprep.interfaces.ants module
- qsiprep.interfaces.bids module
- qsiprep.interfaces.confounds module
- qsiprep.interfaces.denoise module
- qsiprep.interfaces.dipy module
- qsiprep.interfaces.dsi_studio module
- qsiprep.interfaces.dwi_merge module
AveragePEPairs
MergeDWIs
MergeFinalConfounds
PhaseToRad
SplitResampledDWIs
StackConfounds
angle_between()
average_bvec()
average_carpetplots()
average_image_pairs()
combine_bvals()
combine_bvecs()
combine_metadata()
combined_bval_array()
combined_bvec_array()
create_provenance_dataframe()
find_image_pairs()
get_nvols()
get_worst()
harmonize_b0s()
subset_bvals()
subset_bvecs()
unit_vector()
- qsiprep.interfaces.eddy module
- qsiprep.interfaces.epi_fmap module
- qsiprep.interfaces.fmap module
ApplyScalingImages
B0RPEFieldmap
FieldToHz
FieldToRadS
PEPOLARReport
ParallelTOPUP
Phasediff2Fieldmap
Phases2Fieldmap
add_epi_fmaps_to_dwi_b0s()
eddy_inputs_from_dwi_files()
get_distortion_grouping()
get_ees()
get_evenly_spaced_b0s()
get_topup_inputs_from()
get_trt()
load_epi_dwi_fieldmaps()
phases2fmap()
phdiff2fmap()
plot_fa_reg()
plot_pepolar()
read_nifti_sidecar()
topup_inputs_from_4d_file()
- qsiprep.interfaces.freesurfer module
- qsiprep.interfaces.gradients module
CombineMotions
ComposeTransforms
ExtractB0s
GradientRotation
LocalGradientRotation
MatchTransforms
RemoveDuplicates
SliceQC
aattp_rotate_vec()
bvec_rotation()
compose_affines()
concatenate_bvals()
concatenate_bvecs()
create_tensor_image()
get_fsl_motion_params()
get_vector_nii()
local_bvec_rotation()
match_transforms()
reorient_tensor_image()
write_concatenated_fsl_gradients()
- qsiprep.interfaces.images module
- qsiprep.interfaces.itk module
- qsiprep.interfaces.mrtrix module
- qsiprep.interfaces.nilearn module
- qsiprep.interfaces.niworkflows module
- qsiprep.interfaces.qc module
- qsiprep.interfaces.reports module
- qsiprep.interfaces.shoreline module
- qsiprep.interfaces.tortoise module
- qsiprep.interfaces.utils module
- qsiprep.utils package
check_deps()
collect_data()
- Submodules
- qsiprep.utils.bids module
- qsiprep.utils.brainsuite_shore module
BrainSuiteShoreFit
BrainSuiteShoreFit.__init__()
BrainSuiteShoreFit.alpha
BrainSuiteShoreFit.cnr
BrainSuiteShoreFit.fitted_signal()
BrainSuiteShoreFit.msd()
BrainSuiteShoreFit.odf()
BrainSuiteShoreFit.odf_sh()
BrainSuiteShoreFit.pdf()
BrainSuiteShoreFit.pdf_grid()
BrainSuiteShoreFit.predict()
BrainSuiteShoreFit.r2
BrainSuiteShoreFit.regularization
BrainSuiteShoreFit.rtop_pdf()
BrainSuiteShoreFit.rtop_signal()
BrainSuiteShoreFit.shore_coeff
BrainSuiteShoreModel
brainsuite_shore_basis()
brainsuite_shore_matrix_pdf()
create_rspace()
shore_index_matrix()
shore_matrix_odf()
shore_matrix_pdf()
- qsiprep.utils.bspline module
- qsiprep.utils.debug module
- qsiprep.utils.grouping module
- Utilities to group scans based on their acquisition parameters
find_fieldmaps_from_other_dwis()
get_concatenated_bids_name()
get_entity_groups()
get_highest_priority_fieldmap()
group_by_warpspace()
group_dwi_scans()
group_for_concatenation()
group_for_eddy()
merge_dwi_groups()
split_by_phase_encoding_direction()
- qsiprep.utils.maths module
- qsiprep.utils.misc module
- qsiprep.utils.sentry module
- qsiprep.utils.shm module
SphHarmFit
SphHarmModel
anisotropic_power()
bootstrap_data_array()
bootstrap_data_voxel()
calculate_max_order()
forward_sdeconv_mat()
gen_dirac()
hat()
lazy_index()
lcr_matrix()
normalize_data()
order_from_ncoef()
randint()
real_sph_harm()
real_sym_sh_basis()
real_sym_sh_brainsuite()
real_sym_sh_mrtrix()
sf_to_sh()
sh_to_rh()
sh_to_sf()
sh_to_sf_matrix()
smooth_pinv()
sph_harm_ind_list()
spherical_harmonics()
- qsiprep.utils.testing module
- qsiprep.viz package