qsi
tit.pre.qsi ¶
QSI (QSIPrep / QSIRecon) integration for TI-Toolbox.
Provides Docker-out-of-Docker (DooD) integration for running QSIPrep and QSIRecon as sibling containers from within the SimNIBS container. The primary use case is preprocessing DWI data to extract DTI tensors for SimNIBS anisotropic conductivity simulations.
Public API¶
run_qsiprep Run the QSIPrep DWI preprocessing pipeline. run_qsirecon Run the QSIRecon DWI reconstruction pipeline. extract_dti_tensor Extract a DTI tensor and register it to the SimNIBS T1 grid. check_dti_tensor_exists Check whether an extracted DTI tensor already exists.
Configuration Classes¶
QSIPrepConfig Configuration dataclass for QSIPrep runs. QSIReconConfig Configuration dataclass for QSIRecon runs. ResourceConfig Resource allocation (CPU, memory, OMP threads) for QSI containers. ReconSpec Enum of available QSIRecon reconstruction specifications. QSIAtlas Enum of available atlases for connectivity analysis.
See Also¶
tit.pre : Parent preprocessing package. tit.pre.structural.run_pipeline : Full pipeline that can invoke QSI steps.
QSIPrepConfig
dataclass
¶
QSIPrepConfig(subject_id: str, output_resolution: float = QSI_DEFAULT_OUTPUT_RESOLUTION, resources: ResourceConfig = ResourceConfig(), image_tag: str = QSI_QSIPREP_IMAGE_TAG, skip_bids_validation: bool = True, denoise_method: str = 'dwidenoise', unringing_method: str = 'mrdegibbs', distortion_group_merge: str = 'none')
Configuration for a QSIPrep run.
Attributes¶
subject_id : str Subject identifier (without 'sub-' prefix). output_resolution : float Target output resolution in mm (default: 2.0). resources : ResourceConfig Resource allocation settings. image_tag : str Docker image tag for QSIPrep. skip_bids_validation : bool Whether to skip BIDS validation (useful for non-BIDS datasets). denoise_method : str Denoising method: 'dwidenoise', 'patch2self', or 'none'. unringing_method : str Unringing method: 'mrdegibbs', 'rpg', or 'none'. distortion_group_merge : str Method for merging distortion groups: 'concatenate', 'average', or 'none'. The legacy/internal value 'concatenate' is translated to QSIPrep's current CLI value 'concat' when building the Docker command.
QSIReconConfig
dataclass
¶
QSIReconConfig(subject_id: str, recon_specs: list[str] = (lambda: [QSI_DEFAULT_RECON_SPEC])(), atlases: list[str] | None = None, use_gpu: bool = False, resources: ResourceConfig = ResourceConfig(), image_tag: str = QSI_QSIRECON_IMAGE_TAG, skip_odf_reports: bool = True)
Configuration for a QSIRecon run.
Attributes¶
subject_id : str Subject identifier (without 'sub-' prefix). recon_specs : list[str] List of reconstruction specs to run. Defaults to ['dsi_studio_gqi']. atlases : list[str] | None List of atlases for connectivity analysis. None (default) = no connectivity. Set to e.g. ['4S156Parcels', 'AAL116'] if needed. use_gpu : bool Whether to enable GPU acceleration (requires NVIDIA Docker runtime). resources : ResourceConfig Resource allocation settings. image_tag : str Docker image tag for QSIRecon. skip_odf_reports : bool Whether to skip ODF report generation (saves time).
ReconSpec ¶
QSIAtlas ¶
ResourceConfig
dataclass
¶
ResourceConfig(cpus: int | None = None, memory_gb: int | None = None, omp_threads: int = QSI_DEFAULT_OMP_THREADS)
Resource allocation configuration for QSI containers.
Attributes¶
cpus : int Number of CPUs to allocate to the container. memory_gb : int Memory limit in gigabytes. omp_threads : int Number of OpenMP threads (affects ANTS, MRtrix, etc.).
run_qsiprep ¶
run_qsiprep(project_dir: str, subject_id: str, *, logger: Logger, output_resolution: float = QSI_DEFAULT_OUTPUT_RESOLUTION, cpus: int | None = None, memory_gb: int | None = None, omp_threads: int = QSI_DEFAULT_OMP_THREADS, image_tag: str = QSI_QSIPREP_IMAGE_TAG, skip_bids_validation: bool = True, denoise_method: str = 'dwidenoise', unringing_method: str = 'mrdegibbs', runner: CommandRunner | None = None) -> None
Run QSIPrep preprocessing for a subject's DWI data.
This function spawns a QSIPrep Docker container as a sibling to the current SimNIBS container using Docker-out-of-Docker (DooD).
Parameters¶
project_dir : str
Path to the BIDS project root directory.
subject_id : str
Subject identifier (without 'sub-' prefix).
logger : logging.Logger
Logger for status messages.
output_resolution : float, optional
Target output resolution in mm. Default: 2.0.
cpus : int, optional
Number of CPUs to allocate. Default: 8.
memory_gb : int, optional
Memory limit in GB. Default: 32.
omp_threads : int, optional
Number of OpenMP threads. Default: 1.
image_tag : str, optional
QSIPrep Docker image tag. Default from constants.QSI_QSIPREP_IMAGE_TAG.
skip_bids_validation : bool, optional
Skip BIDS validation. Default: True.
denoise_method : str, optional
Denoising method. Default: 'dwidenoise'.
unringing_method : str, optional
Unringing method. Default: 'mrdegibbs'.
runner : CommandRunner | None, optional
Command runner for subprocess execution.
Raises¶
PreprocessError If QSIPrep fails or prerequisites are not met.
Source code in tit/pre/qsi/qsiprep.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
run_qsirecon ¶
run_qsirecon(project_dir: str, subject_id: str, *, logger: Logger, recon_specs: list[str] | None = None, atlases: list[str] | None = None, use_gpu: bool = False, cpus: int | None = None, memory_gb: int | None = None, omp_threads: int = QSI_DEFAULT_OMP_THREADS, image_tag: str = QSI_QSIRECON_IMAGE_TAG, skip_odf_reports: bool = True, runner: CommandRunner | None = None) -> None
Run QSIRecon reconstruction for a subject's preprocessed DWI data.
This function spawns QSIRecon Docker containers as siblings to the current SimNIBS container using Docker-out-of-Docker (DooD).
QSIRecon requires QSIPrep output as input. Multiple reconstruction specs can be run sequentially.
Parameters¶
project_dir : str
Path to the BIDS project root directory.
subject_id : str
Subject identifier (without 'sub-' prefix).
logger : logging.Logger
Logger for status messages.
recon_specs : list[str] | None, optional
List of reconstruction specifications to run. Default: ['dsi_studio_gqi'].
This default produces DTI tensors for SimNIBS anisotropic modeling.
Other specs (mrtrix_, dipy_, amico_noddi, pyafq_*, etc.) remain available.
atlases : list[str] | None, optional
List of atlases for connectivity analysis. Default: None (no connectivity).
Not needed for DTI extraction. Set to e.g. ['4S156Parcels', 'AAL116']
if connectivity matrices are desired.
use_gpu : bool, optional
Enable GPU acceleration. Default: False.
cpus : int | None, optional
Number of CPUs to allocate. None = inherit from current container.
memory_gb : int | None, optional
Memory limit in GB. None = inherit from current container.
omp_threads : int, optional
Number of OpenMP threads. Default: 1.
image_tag : str, optional
QSIRecon Docker image tag. Default from constants.QSI_QSIRECON_IMAGE_TAG.
skip_odf_reports : bool, optional
Skip ODF report generation. Default: True.
runner : CommandRunner | None, optional
Command runner for subprocess execution.
Raises¶
PreprocessError If QSIRecon fails or prerequisites are not met.
Source code in tit/pre/qsi/qsirecon.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
extract_dti_tensor ¶
extract_dti_tensor(project_dir: str, subject_id: str, *, logger: Logger, skip_registration: bool = False) -> Path
Extract and register a DTI tensor from QSIRecon DSI Studio output.
Loads the six tensor components produced by DSI Studio GQI,
validates them, registers the tensor to the SimNIBS T1 grid
(with FSL-convention pre-compensation), saves
DTI_coregT1_tensor.nii.gz into the m2m directory, and
generates a QC report.
Parameters¶
project_dir : str
BIDS project root directory.
subject_id : str
Subject identifier (e.g. '070').
logger : logging.Logger
Logger instance for progress and diagnostic messages.
skip_registration : bool, optional
When True, copy the tensor as-is without resampling or
reorientation. Default is False.
Returns¶
pathlib.Path
Path to the saved DTI_coregT1_tensor.nii.gz.
Raises¶
tit.pre.utils.PreprocessError If required inputs are missing, the tensor already exists, or the tensor data is invalid.
Source code in tit/pre/qsi/dti_extractor.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
check_dti_tensor_exists ¶
Check whether a registered DTI tensor already exists for subject_id.
Parameters¶
project_dir : str BIDS project root directory. subject_id : str Subject identifier.
Returns¶
bool
True if DTI_coregT1_tensor.nii.gz is present in the m2m
directory.