qmri.pipelines¶
End-to-end quantitative MRI workflows that combine the pure signal models in
qmri with the file handling in qmri.io. Pipelines are file-in / file-out:
they load images, run the fit, and write maps and reports.
Provided by the qmri-pipelines package.
Multi-Echo Thermometry¶
multiecho ¶
Multi-echo MR thermometry pipeline.
This pipeline estimates temperature from multi-echo magnitude images and a
segmentation/label map using the dual-resonance model
(:func:qmri.thermometry.fit_multiecho_thermometry_image).
At a high level it:
- Loads one or more 4D multi-echo magnitude NIfTI images (the echo dimension is the last axis).
- Loads a 3D segmentation/label map co-located with the images.
- Loads echo times (in seconds) for each image, concatenates them, and sorts all echoes by echo time.
- Determines the magnetic field strength \(B_0\) (Tesla) from an explicit argument
or from a JSON sidecar (
ImagingFrequencyin MHz orMagneticFieldStrengthin Tesla). - Runs region-wise, voxel-wise or bootstrap region-wise fitting and (optionally) writes a temperature map NIfTI and a JSON report.
MultiEchoThermometryReport
dataclass
¶
MultiEchoThermometryReport(
input_files: list[Path],
segmentation_file: Path,
output_file: Path | None,
magnetic_field_tesla: float,
analysis_method: str,
n_bootstrap: int | None,
echo_times: list[float],
regions: list[RegionThermometryResult],
acquisition_date_time: list[str],
processing_date: str,
processing_time_seconds: float,
)
Structured report from :func:run_multiecho_thermometry.
Attributes:
| Name | Type | Description |
|---|---|---|
input_files |
list[Path]
|
The multi-echo input image paths, in the order supplied. |
segmentation_file |
Path
|
The segmentation/label-map path. |
output_file |
Path | None
|
Path of the saved temperature map, or |
magnetic_field_tesla |
float
|
Magnetic field strength used for the calibration. |
analysis_method |
str
|
The analysis method that was run. |
n_bootstrap |
int | None
|
Number of bootstrap samples ( |
echo_times |
list[float]
|
All echo times in seconds, concatenated and sorted ascending. |
regions |
list[RegionThermometryResult]
|
Per-region results, one per non-empty segmentation label. |
acquisition_date_time |
list[str]
|
Acquisition date/time string per input image
( |
processing_date |
str
|
Local date/time the pipeline finished. |
processing_time_seconds |
float
|
Wall-clock processing time in seconds. |
to_dict ¶
Return a JSON-serialisable dictionary of the report.
Source code in packages/qmri-pipelines/src/qmri/pipelines/thermometry/multiecho.py
run_multiecho_thermometry ¶
run_multiecho_thermometry(
multiecho_files: Sequence[str | Path],
segmentation_file: str | Path,
echo_times_files: Sequence[str | Path],
*,
method: RegionAnalysisMethod = "regionwise",
n_bootstrap: int = 100,
df_init: DfInitMethod = "multistart",
magnetic_field_tesla: float | None = None,
output_dir: str | Path | None = None,
output_prefix: str | None = None,
save_outputs: bool = True,
) -> tuple[NiftiImage, MultiEchoThermometryReport]
Run multi-echo thermometry over a set of images and a segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
multiecho_files
|
Sequence[str | Path]
|
One or more 4D multi-echo magnitude NIfTI files. The echo dimension must be the last axis. All images must share the same spatial shape and affine. |
required |
segmentation_file
|
str | Path
|
A 3D segmentation/label-map NIfTI co-located with the
multi-echo data. Label |
required |
echo_times_files
|
Sequence[str | Path]
|
Echo-time text files (seconds), one per multi-echo image, in the same order. Each file's length must match the number of echoes in its image. |
required |
method
|
RegionAnalysisMethod
|
Analysis method — |
'regionwise'
|
n_bootstrap
|
int
|
Number of bootstrap samples ( |
100
|
df_init
|
DfInitMethod
|
Frequency starting-value strategy — |
'multistart'
|
magnetic_field_tesla
|
float | None
|
Magnetic field strength in Tesla. If |
None
|
output_dir
|
str | Path | None
|
Directory for output files. Defaults to the directory of the
first input image. Only used when |
None
|
output_prefix
|
str | None
|
Prefix for output filenames. Defaults to the first input image's stem. |
None
|
save_outputs
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
NiftiImage
|
A tuple |
MultiEchoThermometryReport
|
class: |
tuple[NiftiImage, MultiEchoThermometryReport]
|
the segmentation, and |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no images are supplied, the number of images and echo-time files differ, image dimensions/affines are inconsistent, an image's echo count does not match its echo times, or the magnetic field strength cannot be determined. |
Source code in packages/qmri-pipelines/src/qmri/pipelines/thermometry/multiecho.py
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
ASL Perfusion Quantification¶
asl ¶
Arterial Spin Labelling (ASL) quantification pipeline.
This pipeline produces a cerebral blood flow (CBF) map from an ASL NIfTI using
the White Paper consensus equations in :mod:qmri.perfusion.asl.
At a high level it:
- Loads a 4D ASL NIfTI and the per-volume
asl_contextdescribing each volume as"control","label"or"m0scan"(read from an explicit argument, a sibling*_aslcontext.tsvfile, or the JSON sidecar). - Averages the control, label and M0 volumes (or takes M0 from a separate file).
- Resolves the labelling parameters with the precedence explicit argument > JSON sidecar > sensible defaults.
- Quantifies CBF (ml/100g/min) using the pCASL/CASL or PASL equation, depending
on
ArterialSpinLabelingType. - Optionally writes a CBF map NIfTI and a JSON report.
ASLQuantificationReport
dataclass
¶
ASLQuantificationReport(
asl_file: Path,
m0_file: Path | None,
output_file: Path | None,
label_type: str,
asl_context: list[str],
quantification_parameters: dict[str, float],
n_valid_voxels: int,
perfusion_mean: float,
perfusion_std: float,
processing_date: str,
processing_time_seconds: float,
)
Structured report from :func:run_asl_quantification.
Attributes:
| Name | Type | Description |
|---|---|---|
asl_file |
Path
|
The input ASL image path. |
m0_file |
Path | None
|
A separate M0 image path, or |
output_file |
Path | None
|
Path of the saved CBF map, or |
label_type |
str
|
The resolved ASL labelling type used for quantification. |
asl_context |
list[str]
|
The per-volume context labels used to split the ASL image. |
quantification_parameters |
dict[str, float]
|
The resolved labelling parameters actually used for quantification. |
n_valid_voxels |
int
|
Number of voxels with non-zero M0 (i.e. voxels where CBF is defined) included in the statistics below. |
perfusion_mean |
float
|
Mean CBF (ml/100g/min) over the valid voxels. |
perfusion_std |
float
|
Standard deviation of CBF (ml/100g/min) over the valid voxels. |
processing_date |
str
|
Local date/time the pipeline finished. |
processing_time_seconds |
float
|
Wall-clock processing time in seconds. |
to_dict ¶
Return a JSON-serialisable dictionary of the report.
Source code in packages/qmri-pipelines/src/qmri/pipelines/perfusion/asl.py
run_asl_quantification ¶
run_asl_quantification(
asl_file: str | Path,
*,
asl_context: Sequence[str] | None = None,
m0_file: str | Path | None = None,
label_type: LabelType | None = None,
post_label_delay: float | None = None,
label_duration: float | None = None,
bolus_duration: float | None = None,
label_efficiency: float | None = None,
t1_blood: float | None = None,
partition_coefficient: float | None = None,
magnetic_field_tesla: float | None = None,
output_dir: str | Path | None = None,
output_prefix: str | None = None,
save_outputs: bool = True,
) -> tuple[NiftiImage, ASLQuantificationReport]
Quantify cerebral blood flow (CBF) from an ASL image.
The control, label and M0 volumes are identified from asl_context and
averaged. CBF is then computed with the White Paper pCASL/CASL or PASL
equation, depending on the resolved labelling type.
Labelling parameters are resolved with the precedence
explicit argument > JSON sidecar > default. Sidecar keys follow BIDS
(ArterialSpinLabelingType, PostLabelingDelay, LabelingDuration,
BolusCutOffDelayTime, LabelingEfficiency,
BloodBrainPartitionCoefficient, T1ArterialBlood,
MagneticFieldStrength).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asl_file
|
str | Path
|
A 4D ASL NIfTI containing control/label (and optionally M0) volumes. |
required |
asl_context
|
Sequence[str] | None
|
Per-volume labels ( |
None
|
m0_file
|
str | Path | None
|
Optional separate M0 NIfTI. If omitted, M0 is taken from the
|
None
|
label_type
|
LabelType | None
|
|
None
|
post_label_delay
|
float | None
|
Post-label delay (s) for pCASL/CASL, or the inversion time (TI, s) for PASL. |
None
|
label_duration
|
float | None
|
Label duration (s); pCASL/CASL only. |
None
|
bolus_duration
|
float | None
|
Bolus duration (TI1, s); PASL only. |
None
|
label_efficiency
|
float | None
|
Labelling efficiency. Defaults to 0.85 (pCASL/CASL) or 0.98 (PASL). |
None
|
t1_blood
|
float | None
|
T1 of arterial blood (s). Defaults from field strength (1.35 s at 1.5 T, 1.65 s at 3 T) or 1.65 s. |
None
|
partition_coefficient
|
float | None
|
Blood-brain partition coefficient (ml/g). Defaults to 0.9. |
None
|
magnetic_field_tesla
|
float | None
|
Field strength (T), used only to pick a default
|
None
|
output_dir
|
str | Path | None
|
Directory for output files. Defaults to the directory of
|
None
|
output_prefix
|
str | None
|
Prefix for output filenames. Defaults to the stem of
|
None
|
save_outputs
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
NiftiImage
|
A tuple |
ASLQuantificationReport
|
class: |
tuple[NiftiImage, ASLQuantificationReport]
|
the input, and |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the ASL context cannot be determined or mismatches the number of volumes; if control, label or M0 volumes are missing; if the labelling type is unknown; or if a required labelling parameter (post-label delay, label duration, or bolus duration) is missing. |
Source code in packages/qmri-pipelines/src/qmri/pipelines/perfusion/asl.py
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
Magnetisation Transfer Ratio¶
mtr ¶
Magnetisation Transfer Ratio (MTR) pipeline.
This pipeline calculates an MTR map from images acquired with and without
bound-pool saturation, using :func:qmri.transfer.calculate_mtr.
At a high level it:
- Loads the saturated and unsaturated images, either as two separate 3D NIfTI
files or as a single 4D file whose last axis holds the two volumes (ordered
[unsaturated, saturated]). - Checks the two images are co-located (matching spatial shape and affine).
- Computes the MTR (percentage units) voxel-wise.
- Optionally writes an MTR map NIfTI and a JSON report.
The MTR is defined as
where \(S_0\) is the unsaturated signal and \(S_s\) the saturated signal.
MTRReport
dataclass
¶
MTRReport(
input_files: list[Path],
mode: str,
output_file: Path | None,
n_valid_voxels: int,
mtr_mean: float,
mtr_std: float,
mtr_min: float,
mtr_max: float,
processing_date: str,
processing_time_seconds: float,
)
Structured report from :func:run_mtr.
Attributes:
| Name | Type | Description |
|---|---|---|
input_files |
list[Path]
|
The input image paths. Two entries (unsaturated, saturated) in separate-file mode, or one entry in combined-file mode. |
mode |
str
|
|
output_file |
Path | None
|
Path of the saved MTR map, or |
n_valid_voxels |
int
|
Number of voxels with a non-zero unsaturated signal (i.e. voxels where MTR is defined) included in the statistics below. |
mtr_mean |
float
|
Mean MTR (pu) over the valid voxels. |
mtr_std |
float
|
Standard deviation of MTR (pu) over the valid voxels. |
mtr_min |
float
|
Minimum MTR (pu) over the valid voxels. |
mtr_max |
float
|
Maximum MTR (pu) over the valid voxels. |
processing_date |
str
|
Local date/time the pipeline finished. |
processing_time_seconds |
float
|
Wall-clock processing time in seconds. |
to_dict ¶
Return a JSON-serialisable dictionary of the report.
Source code in packages/qmri-pipelines/src/qmri/pipelines/transfer/mtr.py
run_mtr ¶
run_mtr(
saturated_file: str | Path,
unsaturated_file: str | Path | None = None,
*,
output_dir: str | Path | None = None,
output_prefix: str | None = None,
save_outputs: bool = True,
) -> tuple[NiftiImage, MTRReport]
Calculate a Magnetisation Transfer Ratio (MTR) map.
Two input modes are supported:
- Separate (
unsaturated_filegiven):saturated_fileandunsaturated_fileare individual NIfTI images of the same shape and affine. - Combined (
unsaturated_fileisNone):saturated_fileis a single 4D NIfTI whose last axis holds two volumes ordered[unsaturated, saturated].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saturated_file
|
str | Path
|
The image with bound-pool saturation, or — in combined mode — a 4D file containing both the unsaturated and saturated volumes (in that order). |
required |
unsaturated_file
|
str | Path | None
|
The image without bound-pool saturation. Omit to use combined mode. |
None
|
output_dir
|
str | Path | None
|
Directory for output files. Defaults to the directory of
|
None
|
output_prefix
|
str | None
|
Prefix for output filenames. Defaults to the stem of
|
None
|
save_outputs
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
NiftiImage
|
A tuple |
MTRReport
|
class: |
tuple[NiftiImage, MTRReport]
|
co-located with the input, and |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a combined file is not 4D with two volumes, or the two separate images differ in shape or affine. |
Source code in packages/qmri-pipelines/src/qmri/pipelines/transfer/mtr.py
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 | |