qmri.dro¶
Digital Reference Objects for quantitative MRI validation.
Module Overview¶
The qmri.dro module provides tools for generating synthetic MRI data with known ground truth parameters.
Types¶
GroundTruth
dataclass
¶
DWIPhantom
dataclass
¶
DWIPhantom(
signal: NDArray[floating],
b_values: NDArray[floating],
ground_truth: dict[
str, GroundTruth[float | NDArray[floating]]
],
snr: float | None,
seed: int | None,
)
Digital Reference Object for diffusion-weighted imaging.
Contains synthetic DWI signal with known ground truth ADC values, along with acquisition parameters and optional noise characteristics.
Attributes:
| Name | Type | Description |
|---|---|---|
signal |
NDArray[floating]
|
Signal intensities at each b-value. Shape is either (n_bvalues,) for single voxel or (..., n_bvalues) for multi-voxel. |
b_values |
NDArray[floating]
|
Diffusion weighting values in s/mm². |
ground_truth |
dict[str, GroundTruth[float | NDArray[floating]]]
|
Dictionary of ground truth parameters. |
snr |
float | None
|
Signal-to-noise ratio used for noise generation, or None if noiseless. |
seed |
int | None
|
Random seed used for reproducibility, or None if not seeded. |
Example
T1Phantom
dataclass
¶
T1Phantom(
signal: NDArray[floating],
time_points: NDArray[floating],
method: str,
model: str | None,
repetition_time: float | None,
ground_truth: dict[
str, GroundTruth[float | NDArray[floating]]
],
snr: float | None,
seed: int | None,
)
Digital Reference Object for T1 relaxometry.
Contains synthetic T1 signal with known ground truth values, supporting both inversion recovery (IR) and variable TR (VTR) methods.
Attributes:
| Name | Type | Description |
|---|---|---|
signal |
NDArray[floating]
|
Signal intensities at each time point. Shape is either (n_timepoints,) for single voxel or (..., n_timepoints) for multi-voxel. |
time_points |
NDArray[floating]
|
Time points in seconds (TI for IR, TR for VTR). |
method |
str
|
Acquisition method used ("ir" or "vtr"). |
model |
str | None
|
For IR method, the model used ("general" or "classical"). |
repetition_time |
float | None
|
TR value(s) for IR method, or None for VTR. |
ground_truth |
dict[str, GroundTruth[float | NDArray[floating]]]
|
Dictionary of ground truth parameters. |
snr |
float | None
|
Signal-to-noise ratio used for noise generation, or None if noiseless. |
seed |
int | None
|
Random seed used for reproducibility, or None if not seeded. |
Example
ASLPhantom
dataclass
¶
ASLPhantom(
control: NDArray[floating],
label: NDArray[floating],
m0: NDArray[floating],
ground_truth: dict[
str, GroundTruth[float | NDArray[floating]]
],
acquisition_params: dict[str, float],
snr: float | None,
seed: int | None,
)
Digital Reference Object for arterial spin labelling.
Contains synthetic ASL control and label images with known ground truth perfusion values, along with acquisition parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
NDArray[floating]
|
Control image signal intensity. |
label |
NDArray[floating]
|
Label image signal intensity. |
m0 |
NDArray[floating]
|
Equilibrium magnetisation (M0) image. |
ground_truth |
dict[str, GroundTruth[float | NDArray[floating]]]
|
Dictionary of ground truth parameters. |
acquisition_params |
dict[str, float]
|
Dictionary of acquisition parameters used. |
snr |
float | None
|
Signal-to-noise ratio used for noise generation, or None if noiseless. |
seed |
int | None
|
Random seed used for reproducibility, or None if not seeded. |
Example
DWI Phantom Generation¶
dwi ¶
DWI phantom generation for ADC validation.
This module provides functions for generating synthetic diffusion-weighted imaging (DWI) data with known ground truth ADC values.
Example
from qmri.dro import dwi
from qmri.diffusion import adc
# Generate a single-voxel phantom
phantom = dwi.generate(adc=1e-3, s0=1000, snr=50, seed=42)
# Fit and compare to ground truth
result = adc.fit(phantom.signal, phantom.b_values)
print(f"True ADC: {phantom.ground_truth['adc'].value:.2e}")
print(f"Fitted ADC: {result.adc:.2e}")
generate ¶
generate(
adc: NDArray[floating] | float,
s0: NDArray[floating] | float = 1000.0,
b_values: Sequence[float] = (0, 500, 1000, 2000),
*,
snr: float | None = None,
noise_model: Literal["rician", "gaussian"] = "rician",
seed: int | None = None,
) -> DWIPhantom
Generate a DWI phantom with known ADC.
Creates synthetic DWI signal using the mono-exponential diffusion model with optional noise for validation and testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adc
|
NDArray[floating] | float
|
Apparent Diffusion Coefficient in mm²/s. Can be a scalar for single-voxel phantom or an array for multi-voxel phantom. |
required |
s0
|
NDArray[floating] | float
|
Baseline signal intensity (at b=0). Can be scalar or array
matching the shape of |
1000.0
|
b_values
|
Sequence[float]
|
Diffusion weighting values in s/mm². Default is (0, 500, 1000, 2000). |
(0, 500, 1000, 2000)
|
snr
|
float | None
|
Signal-to-noise ratio. If None, no noise is added. |
None
|
noise_model
|
Literal['rician', 'gaussian']
|
Type of noise to add ("rician" or "gaussian"). Default is "rician", which is more realistic for magnitude MRI. |
'rician'
|
seed
|
int | None
|
Random seed for reproducibility. If None, uses random state. |
None
|
Returns:
| Type | Description |
|---|---|
DWIPhantom
|
DWIPhantom containing the synthetic signal, b-values, and ground truth. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If noise_model is not "rician" or "gaussian". |
Example
Single-voxel phantom:
from qmri.dro import dwi
phantom = dwi.generate(adc=1e-3, snr=50, seed=42)
print(phantom.signal)
# array([1000. , 606.5..., 367.8..., 135.3...])
Multi-voxel phantom:
Notes
The signal is generated using the Stejskal-Tanner equation:
For magnitude MRI, Rician noise is the appropriate model and causes a positive bias at low SNR. Gaussian noise is suitable for complex data or high SNR scenarios.
Source code in packages/qmri-dro/src/qmri/dro/dwi.py
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 | |
generate_calibration_phantom ¶
generate_calibration_phantom(
adc_values: Sequence[float] = (
0.0003,
0.0007,
0.001,
0.0015,
0.002,
0.003,
),
b_values: Sequence[float] = (
0,
50,
100,
200,
400,
600,
800,
1000,
),
*,
s0: float = 1000.0,
snr: float | None = 50.0,
noise_model: Literal["rician", "gaussian"] = "rician",
seed: int | None = None,
) -> DWIPhantom
Generate a calibration phantom with multiple ADC values.
Creates a phantom with multiple voxels at different ADC values, suitable for method validation and benchmarking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adc_values
|
Sequence[float]
|
Sequence of ADC values in mm²/s. Default covers the range from restricted diffusion to free water. |
(0.0003, 0.0007, 0.001, 0.0015, 0.002, 0.003)
|
b_values
|
Sequence[float]
|
Diffusion weighting values in s/mm². Default provides good sampling for ADC range. |
(0, 50, 100, 200, 400, 600, 800, 1000)
|
s0
|
float
|
Baseline signal intensity for all voxels. Default is 1000.0. |
1000.0
|
snr
|
float | None
|
Signal-to-noise ratio. Default is 50.0. |
50.0
|
noise_model
|
Literal['rician', 'gaussian']
|
Type of noise to add. Default is "rician". |
'rician'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
DWIPhantom
|
DWIPhantom with shape (n_adc_values, n_bvalues). |
Example
from qmri.dro import dwi
from qmri.diffusion import adc
# Generate calibration phantom
phantom = dwi.generate_calibration_phantom(seed=42)
print(f"Shape: {phantom.signal.shape}")
# Shape: (6, 8)
# Fit each "voxel"
for i, true_adc in enumerate(phantom.ground_truth['adc'].value):
result = adc.fit(phantom.signal[i], phantom.b_values)
print(f"True: {true_adc:.2e}, Fitted: {result.adc:.2e}")
Notes
Default ADC values represent:
- 0.3e-3: Highly restricted (e.g., tumour)
- 0.7e-3: White matter
- 1.0e-3: Grey matter
- 1.5e-3: Less restricted tissue
- 2.0e-3: CSF-like
- 3.0e-3: Free water
Source code in packages/qmri-dro/src/qmri/dro/dwi.py
Relaxometry Phantom Generation¶
relaxometry ¶
Relaxometry phantom generation for T1/T2 validation.
This module provides functions for generating synthetic T1 relaxometry data with known ground truth values using inversion recovery (IR) and variable TR (VTR) methods.
Example
from qmri.dro import relaxometry
from qmri.relaxometry import t1
# Generate IR data with known T1
phantom = relaxometry.generate_t1_ir(
t1=1.2,
inversion_times=[0.1, 0.5, 1.0, 2.0, 3.0],
repetition_time=5.0,
snr=100,
seed=42,
)
# Fit and validate
result = t1.fit_ir(phantom.signal, phantom.time_points, repetition_times=5.0)
print(f"True T1: {phantom.ground_truth['t1'].value:.2f} s")
print(f"Fitted T1: {float(result.t1):.2f} s")
generate_t1_ir ¶
generate_t1_ir(
t1: float,
inversion_times: Sequence[float],
*,
s0: float = ...,
repetition_time: float = ...,
inversion_efficiency: float = ...,
model: Literal["general", "classical"] = ...,
snr: float | None = ...,
noise_model: Literal["rician", "gaussian"] = ...,
seed: int | None = ...,
) -> T1Phantom
generate_t1_ir(
t1: NDArray[floating],
inversion_times: Sequence[float],
*,
s0: NDArray[floating] | float = ...,
repetition_time: float = ...,
inversion_efficiency: NDArray[floating] | float = ...,
model: Literal["general", "classical"] = ...,
snr: float | None = ...,
noise_model: Literal["rician", "gaussian"] = ...,
seed: int | None = ...,
) -> T1Phantom
generate_t1_ir(
t1: NDArray[floating] | float,
inversion_times: Sequence[float],
*,
s0: NDArray[floating] | float = 1000.0,
repetition_time: float = 5.0,
inversion_efficiency: NDArray[floating] | float = 1.0,
model: Literal["general", "classical"] = "general",
snr: float | None = None,
noise_model: Literal["rician", "gaussian"] = "rician",
seed: int | None = None,
) -> T1Phantom
Generate a T1 phantom using inversion recovery.
Creates synthetic IR signal using either the general or classical model with optional noise for validation and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t1
|
NDArray[floating] | float
|
T1 relaxation time in seconds. Can be scalar or array. |
required |
inversion_times
|
Sequence[float]
|
Inversion times (TI) in seconds. |
required |
s0
|
NDArray[floating] | float
|
Signal amplitude at equilibrium. Default is 1000.0. |
1000.0
|
repetition_time
|
float
|
Repetition time (TR) in seconds. Default is 5.0. |
5.0
|
inversion_efficiency
|
NDArray[floating] | float
|
Inversion efficiency (0-1). Default is 1.0. |
1.0
|
model
|
Literal['general', 'classical']
|
IR model to use. Default is "general". - "general": Full model including TR recovery term - "classical": Assumes TR >> T1 |
'general'
|
snr
|
float | None
|
Signal-to-noise ratio. If None, no noise is added. |
None
|
noise_model
|
Literal['rician', 'gaussian']
|
Type of noise to add. Default is "rician". |
'rician'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
T1Phantom
|
T1Phantom containing the synthetic signal, time points, and ground truth. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model is not "general" or "classical". |
ValueError
|
If noise_model is not "rician" or "gaussian". |
Example
Single-voxel phantom:
from qmri.dro import relaxometry
phantom = relaxometry.generate_t1_ir(
t1=1.2,
inversion_times=[0.1, 0.5, 1.0, 2.0, 3.0],
snr=100,
seed=42,
)
print(phantom.signal)
Multi-voxel phantom:
Notes
General model:
Classical model (assumes TR >> T1):
Source code in packages/qmri-dro/src/qmri/dro/relaxometry.py
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 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 | |
generate_t1_vtr ¶
generate_t1_vtr(
t1: NDArray[floating] | float,
repetition_times: Sequence[float],
*,
m: NDArray[floating] | float = 1000.0,
snr: float | None = None,
noise_model: Literal["rician", "gaussian"] = "rician",
seed: int | None = None,
) -> T1Phantom
Generate a T1 phantom using variable TR method.
Creates synthetic VTR signal for saturation recovery T1 mapping with optional noise for validation and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t1
|
NDArray[floating] | float
|
T1 relaxation time in seconds. Can be scalar or array. |
required |
repetition_times
|
Sequence[float]
|
Repetition times (TR) in seconds. |
required |
m
|
NDArray[floating] | float
|
Equilibrium magnetisation. Default is 1000.0. |
1000.0
|
snr
|
float | None
|
Signal-to-noise ratio. If None, no noise is added. |
None
|
noise_model
|
Literal['rician', 'gaussian']
|
Type of noise to add. Default is "rician". |
'rician'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
T1Phantom
|
T1Phantom containing the synthetic signal, time points, and ground truth. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If noise_model is not "rician" or "gaussian". |
Example
from qmri.dro import relaxometry
from qmri.relaxometry import t1
phantom = relaxometry.generate_t1_vtr(
t1=1.2,
repetition_times=[0.5, 1.0, 2.0, 4.0, 8.0],
snr=100,
seed=42,
)
result = t1.fit_vtr(phantom.signal, phantom.time_points)
print(f"True T1: {phantom.ground_truth['t1'].value:.2f} s")
print(f"Fitted T1: {float(result.t1):.2f} s")
Notes
The VTR signal model is:
where M is the equilibrium magnetisation.
Source code in packages/qmri-dro/src/qmri/dro/relaxometry.py
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 | |
Perfusion Phantom Generation¶
perfusion ¶
Perfusion phantom generation for ASL validation.
This module provides functions for generating synthetic arterial spin labelling (ASL) data with known ground truth perfusion values.
Example
from qmri.dro import perfusion
# Generate pCASL data with known perfusion
phantom = perfusion.generate_pcasl(
perfusion_rate=60.0, # ml/100g/min
m0=1000.0,
transit_time=1.0,
snr=50,
seed=42,
)
# Access the difference signal
delta_m = phantom.control - phantom.label
print(f"True CBF: {phantom.ground_truth['perfusion_rate'].value} ml/100g/min")
generate_pcasl ¶
generate_pcasl(
perfusion_rate: float,
m0: float,
*,
transit_time: float = ...,
label_duration: float = ...,
post_label_delay: float = ...,
label_efficiency: float = ...,
partition_coefficient: float = ...,
t1_blood: float = ...,
t1_tissue: float = ...,
snr: float | None = ...,
noise_model: Literal["rician", "gaussian"] = ...,
seed: int | None = ...,
) -> ASLPhantom
generate_pcasl(
perfusion_rate: NDArray[floating],
m0: NDArray[floating] | float,
*,
transit_time: NDArray[floating] | float = ...,
label_duration: float = ...,
post_label_delay: float = ...,
label_efficiency: float = ...,
partition_coefficient: NDArray[floating] | float = ...,
t1_blood: float = ...,
t1_tissue: NDArray[floating] | float = ...,
snr: float | None = ...,
noise_model: Literal["rician", "gaussian"] = ...,
seed: int | None = ...,
) -> ASLPhantom
generate_pcasl(
perfusion_rate: NDArray[floating] | float,
m0: NDArray[floating] | float,
*,
transit_time: NDArray[floating] | float = 1.0,
label_duration: float = 1.8,
post_label_delay: float = 1.8,
label_efficiency: float = 0.85,
partition_coefficient: NDArray[floating] | float = 0.9,
t1_blood: float = 1.65,
t1_tissue: NDArray[floating] | float = 1.3,
snr: float | None = None,
noise_model: Literal["rician", "gaussian"] = "rician",
seed: int | None = None,
) -> ASLPhantom
Generate a pCASL phantom with known perfusion.
Creates synthetic pseudo-continuous ASL (pCASL) control and label images using the General Kinetic Model with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
perfusion_rate
|
NDArray[floating] | float
|
Cerebral blood flow (CBF) in ml/100g/min. Can be scalar or array for multi-voxel phantom. |
required |
m0
|
NDArray[floating] | float
|
Equilibrium magnetisation (M0) of tissue. |
required |
transit_time
|
NDArray[floating] | float
|
Arterial transit time (ATT) in seconds. Default is 1.0. |
1.0
|
label_duration
|
float
|
Duration of labelling pulse (tau) in seconds. Default is 1.8. |
1.8
|
post_label_delay
|
float
|
Post-label delay (PLD) in seconds. Default is 1.8. |
1.8
|
label_efficiency
|
float
|
Labelling efficiency (0-1). Default is 0.85. |
0.85
|
partition_coefficient
|
NDArray[floating] | float
|
Blood-brain partition coefficient (lambda) in ml/g. Default is 0.9. |
0.9
|
t1_blood
|
float
|
T1 of arterial blood in seconds. Default is 1.65. |
1.65
|
t1_tissue
|
NDArray[floating] | float
|
T1 of tissue in seconds. Default is 1.3. |
1.3
|
snr
|
float | None
|
Signal-to-noise ratio. If None, no noise is added. |
None
|
noise_model
|
Literal['rician', 'gaussian']
|
Type of noise to add. Default is "rician". |
'rician'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
ASLPhantom
|
ASLPhantom containing control, label, and M0 images with ground truth. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If noise_model is not "rician" or "gaussian". |
Example
Single-voxel phantom:
from qmri.dro import perfusion
phantom = perfusion.generate_pcasl(
perfusion_rate=60.0,
m0=1000.0,
snr=50,
seed=42,
)
print(f"Control: {phantom.control}")
print(f"Label: {phantom.label}")
print(f"Delta M: {phantom.control - phantom.label}")
Multi-voxel phantom:
Notes
The signal is calculated using the General Kinetic Model (GKM):
Default parameters are based on ASL White Paper recommendations for adult brain imaging at 3T.
Typical perfusion values:
- Grey matter: 50-80 ml/100g/min
- White matter: 20-30 ml/100g/min
- Tumour: Variable, often elevated
Source code in packages/qmri-dro/src/qmri/dro/perfusion.py
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 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 | |