gigablochs.bloch.relax#
- gigablochs.bloch.relax(magnetization, T1, T2, dt, *, M0=(0, 0, 1), extend_shapes=True, match_shapes=True, axis=-1)[source]#
Apply relaxation to the magnetization vector.
- Parameters:
magnetization (ndarray) – Magnetization vector, can be multidimensional.
T1 (ndarray) – Longitudinal relaxation time in seconds.
T2 (ndarray) – Transverse relaxation time in seconds.
dt (float) – Time step in seconds.
M0 (tuple, optional) – Initial magnetization vector. Default is (0, 0, 1), i.e. up along the z-axis.
extend_shapes (bool, optional) – If True, the shapes of T1 and T2 are prefixed to the shape of the magnetization array. See
match_shapes. Note when False, T1 and T2 should have the same shape as magnetization except along axis, which should be 1. Default is True.match_shapes (bool, optional) – If True, the shapes of T1 and T2 are not prefixed to the shape of the magnetization array when they match the start of its shape. Default is True.
axis (int, optional) – Axis along the magnetization array which represents the 2D or 3D spatial magnetization vector. Default is the last axis.
- Returns:
updated_magnetization – Updated magnetization vector. The shapes of T1 and T2 are prefixed to the shape of the magnetization array if not already present.
- Return type:
ndarray
- Raises:
ValueError – If the length of M0 is not equal to the length of the spatial axis: of the magnetization array.
Notes
The relaxation is computed as:
\[\vec{M}_{\text{relaxed}} = \vec{M}_{\text{stressed}} \cdot \left[1 - \frac{\Delta t}{T_2}, 1 - \frac{\Delta t}{T_2}, 1 - \frac{\Delta t}{T_1} \right]^T + \vec{M_0} \left(\frac{\Delta t}{T_1} \right)\]where \(\vec{M}_{\text{relaxed}}\) is the relaxed magnetization vector, \(\vec{M}_{\text{stressed}}\) is the input magnetization vector, \(\vec{M_0}\) is the initial magnetization vector, \(T_1\) is the longitudinal relaxation time in seconds, \(T_2\) is the transverse relaxation time in seconds, and \(\Delta t\) is the time step in seconds.
Examples
# One line to simulate a relaxation process for 5000 time steps with 3000 parameter combos! import numpy as np from gigablochs import bloch dt = 0.001 # seconds duration = 5 # seconds T1 = np.linspace(0.3, 2.3, 20) # seconds T2 = np.linspace(0.05, 1.1, 30) # seconds mag = np.random.random((5, 3)) # last axis is the spatial axis mags = np.array([mag := bloch.relax(mag, T1, T2, dt) for _ in range(round(duration / dt))]) mags.shape # (5000, 20, 30, 5, 3)