Utils¶
_general ¶
Utility module contains helpers functions.
find_gradient_blocks ¶
find_gradient_blocks(
time_points: ndarray, grad_wf: ndarray
) -> List[Tuple[str, np.ndarray, np.ndarray]]
Given an array of single-channel gradient amplitudes (waveform) and corresponding time points, subdivides the waveform into possible trapezoidal and arbitrary gradient definitions.
Assumes that for consecutive trapezoids, the zero-crossing is explicitly included, otherwise the two lobes are combined into one arbitrary waveform. Trapezoids, include triangular gradient pulses. Zero-crossings of arbitrary gradients (such as spirals) are not used to subdivide the shape.
.. note::
Comparison by value of inflection points and slew-rates are done up to the
precision on 1e-8, therefore it is advisable to adhere to the stated units
or scale correspondingly!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_points
|
ndarray
|
(t, ) array of time-points in ms |
required |
grad_wf
|
ndarray
|
(t, ) array of gradient-waveforms in mT/m |
required |
Returns:
| Type | Description |
|---|---|
Temporally ordered gradient definitions containing: the type (trapezoid/arbitrary) the time-points (t_i,) the gradient samples (g_i, )
|
|
Source code in cmrseq/utils/_general.py
14 15 16 17 18 19 20 21 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 | |
grid_sequence_list ¶
grid_sequence_list(
sequence_list: List[Sequence],
force_uniform_grid: bool = False,
) -> Tuple[List[np.ndarray], ...]
Grids RF, Gradients and adc_events of all sequences in the provided List.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence_list
|
List[Sequence]
|
|
required |
force_uniform_grid
|
bool
|
bool if False the ADC-events are inserted into the time grid resulting in a non-uniform raster per TR |
False
|
Returns:
| Type | Description |
|---|---|
(time, rf_list, wf_list, adc_list)
|
|
Source code in cmrseq/utils/_general.py
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 | |
calculate_gradient_spectra ¶
calculate_gradient_spectra(
sequence: Sequence,
directions: List[ndarray],
start_time: Quantity = None,
end_time: Quantity = None,
interpolation_subfactor: int = 1,
pad_factor: int = 10,
)
Calculates gradient sampling spectra along a given direction according to:
.. math::
S(\omega,t) = |\tilde{q}(\omega,t)|^2
\tilde{q}(\omega,t) = \int_{0}^{t}q(t')e^{i\omega t'}dt'
q(t) = \gamma \int_{0}^{t}G(t')dt'
where G(t) is the gradient. Spectra returns in units of :math:mT^2/m^2/ms^4
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
Sequence
|
Sequence to calculate spectra on |
required |
directions
|
List[ndarray]
|
List[np.ndarray of shape (3, )] denoting the directions to calculate spectra along |
required |
start_time
|
Quantity
|
Quantity[Time] Start time of spectra calculation window |
None
|
end_time
|
Quantity
|
Quantity[Time] End time of spectra calculation window |
None
|
interpolation_subfactor
|
int
|
int, factor to divide sequence raster time by for spectra calculation |
1
|
pad_factor
|
int
|
int, multiplicative pad factor prior to fourier transform. Used to better resolve low frequencies |
10
|
Returns:
| Type | Description |
|---|---|
(List[Spectra],Frequency) Tuple of arrays giving spectra and frequency axis
|
|
Source code in cmrseq/utils/_general.py
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 | |
concomitant_fields ¶
concomitant_fields(
sequence: Sequence, coordinates: ndarray
)
Computes concomitant fields for all and accumulated phase for static positions at the end of the given sequence.
.. math::
B_c(t) = (g_z^2/(8B_0))(x^2 + y^2) + (g_x^2 + g_y^2)/(2 B_0)z^2 -
(g_x g_z)/(2B_0) xz - (g_y g_z)/(2B_0)yz
\phi_c(t) = \int_0^t \gamma / B_c(t\prime) dt\prime
.. Dropdown:: References https://onlinelibrary.wiley.com/doi/abs/10.1002/%28SICI%291522-25 94%28199901%2941%3A1%3C103%3A%3AAID-MRM15%3E3.0.CO%3B2-M?sid=nlm%3Apubmed
https://pubmed.ncbi.nlm.nih.gov/22851517/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
Sequence
|
|
required |
coordinates
|
ndarray
|
(..., [x, y, z]) |
required |
Returns:
| Type | Description |
|---|---|
object
|
|
Source code in cmrseq/utils/_general.py
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 | |
_diffusion ¶
Utility module contains helpers for diffusion sequence design.
calculate_diffusion_weighting ¶
calculate_diffusion_weighting(
seq: Sequence,
return_bmatrix: bool = False,
return_cumulative: bool = False,
)
Evaluates the b-value or b-matrix of arbitrary gradient waveforms by numerical integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
Sequence object, which is gridded to obtain hte waveform |
required |
return_bmatrix
|
bool
|
If True returns the b-matrix instead of the scalar b-value |
False
|
return_cumulative
|
bool
|
if True returns the bvalue on raster-time resolution |
False
|
Returns:
| Type | Description |
|---|---|
Quantity of shape (1, ) or (t, ) depending on `return_cumulative` argument
|
|
Source code in cmrseq/utils/_diffusion.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 | |
_transformations ¶
Utility module contains helpers for coordinate transformations
mps_to_xyz ¶
mps_to_xyz(
gradients: ndarray,
slice_normal: ndarray = np.array([1.0, 0.0, 0.0]),
readout_direction: ndarray = np.array([0.0, 0.0, 1.0]),
) -> np.ndarray
Converts from MPS formalism to scanner coordinates XYZ. Default scheme is Coronal slice with measurement in Z If M and S are not orthogonal, M is adjusted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gradients
|
ndarray
|
(..., 3) np.array containing gradient waveforms defined in MPS coordinates |
required |
slice_normal
|
ndarray
|
np.array (3, ) containing the slice orientation in XYZ coordinates |
array([1.0, 0.0, 0.0])
|
readout_direction
|
ndarray
|
np.array (3, ) containing the readout direction in XYZ coordinates |
array([0.0, 0.0, 1.0])
|
Returns:
| Type | Description |
|---|---|
(..., 3) rotated gradient waveform in XYZ coordinates
|
|
Source code in cmrseq/utils/_transformations.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
xyz_to_mps ¶
xyz_to_mps(
gradients: ndarray,
slice_normal: ndarray = np.array([1.0, 0.0, 0.0]),
readout_direction: ndarray = np.array([0.0, 0.0, 1.0]),
) -> np.ndarray
Converts from XYZ formalism to scanner coordinates MPS. Default scheme is Coronal slice with measurement in Z If M and S are not orthogonal, M is adjusted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gradients
|
ndarray
|
(..., 3) np.array containing gradient waveforms defined in XYZ coordinates |
required |
slice_normal
|
ndarray
|
np.array (3, ) containing the slice orientation in XYZ coordinates |
array([1.0, 0.0, 0.0])
|
readout_direction
|
ndarray
|
np.array (3, ) containing the readout direction in XYZ coordinates |
array([0.0, 0.0, 1.0])
|
Returns:
| Type | Description |
|---|---|
(..., 3) rotated gradient waveform in MPS coordinates
|
|
Source code in cmrseq/utils/_transformations.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
get_rotation_matrix ¶
get_rotation_matrix(
slice_normal: ndarray,
readout_direction: ndarray,
target_orientation: str = "xyz",
) -> np.ndarray
Evaluates a rotation matrix according which can be used to transform between MPS and XYZ coordinates. If M and S are not orthogonal, M is adjusted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_normal
|
ndarray
|
Slice normal vector in XYZ coordinates |
required |
readout_direction
|
ndarray
|
Readout vector in XYZ coordinates |
required |
target_orientation
|
str
|
str, either ('mps', 'xyz') |
'xyz'
|
Returns:
| Type | Description |
|---|---|
(3, 3) array the 0th axis indexes the M/P/S vector in cartesian coordinates
|
|
Source code in cmrseq/utils/_transformations.py
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 | |
_report ¶
report ¶
report(
seq: Sequence, format: str = "str"
) -> Union[str, dict]
Creates Sequence report in specified format. Contained values: - Counter per block type - Non-unique block names - Flip angles of RF-events - RF-peak power of RF-waveforms - Center-timing of acquisition events - Max gradient per channel - Max gradient magnitude (norm of all axes) - Max gradient slew per channel - Max gradient slew norm
Returns:
| Type | Description |
|---|---|
string in specified format or dictionary containing the values
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if format not in [str, json, html, dict] |
Source code in cmrseq/utils/_report.py
9 10 11 12 13 14 15 16 17 18 19 20 21 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 | |