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', use_syn_sdc: bool = False, mni_normalization: bool = False)
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' (already resolved; the
pipeline setting 'auto' is resolved by run_qsiprep).
use_syn_sdc : bool
Pass --use-syn-sdc warn (fieldmap-less SyN distortion correction).
Set by run_qsiprep when the subject has no usable fieldmap.
mni_normalization : bool
Run QSIPrep's anatomical normalization to MNI. Off by default: only
QSIRecon atlases/template-space specs need it. Always on with SyN SDC,
which uses the MNI transform to place its fieldmap prior.
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'] (scalar maps only; the SimNIBS DTI tensor does not need QSIRecon). 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 = (lambda: 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 | None = None, 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 = 'auto', mni_normalization: bool = False, 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). QSIPrep needs an x86-64 Docker host (its SynthSeg step needs AVX); an arm64 host is refused before anything runs.
Susceptibility distortion correction is always on: TOPUP with the subject's
reverse phase-encoding fieldmap (IntendedFor written into its sidecar when
missing) or reverse-PE DWI series, else fieldmap-less SyN
(--use-syn-sdc warn). DWI fieldmaps that exist but cannot be used stop the
run instead of silently falling back.
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 or None, optional
Isotropic output voxel size in mm. None (default) uses the native DWI
voxel size (smallest axis, rounded to 0.1 mm).
cpus : int, optional
Number of CPUs to allocate. Default: 8.
memory_gb : int, optional
Memory limit in GB. Default: 32.
omp_threads : int, optional
Threads per process. Default: constants.QSI_DEFAULT_OMP_THREADS
(min(cpu_count - 1, 8), matching QSIPrep's own default).
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
'mrdegibbs', 'rpg', 'none' or 'auto' (default): rpg when the DWI sidecar
has PartialFourier < 1, else mrdegibbs.
mni_normalization : bool, optional
Run the anatomical normalization to MNI (needed only for QSIRecon atlases
and template-space specs). Default: False; forced on by SyN SDC.
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
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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
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 is optional: it adds tractography, scalar maps and connectivity on top of QSIPrep output. The SimNIBS DTI tensor does not need it. 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']
(GQI scalar maps, no tractography). 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). Needs a QSIPrep run with MNI normalization enabled.
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
Threads per process. Default: constants.QSI_DEFAULT_OMP_THREADS
(min(cpu_count - 1, 8), matching QSIPrep's own default).
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
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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
extract_dti_tensor ¶
Fit, register and write DTI_coregT1_tensor.nii.gz for subject_id.
Reads QSIPrep output and the charm m2m folder; writes the tensor and
DTI_coregT1_qc.json into the m2m folder, then a DTI QC report.
Raises¶
tit.pre.utils.PreprocessError Missing inputs, an existing tensor, an m2m T1 that is not the T1w QSIPrep used, or a failed QC gate (the QC JSON and the report are still written; the tensor is not).
Source code in tit/pre/qsi/dti_extractor.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
check_dti_tensor_exists ¶
Whether DTI_coregT1_tensor.nii.gz exists in subject_id's m2m folder.