Utility Functions#

coordinates#

get_static_2d_centered_coordinates(map_size, object_dimensions=None, return_2d=True)[source]#

Calculates relative coordinates for a dense map with coordinate origin in the center of the map. If the dimension in map_size is even, the origin is shifted 1/2 with respect to grid indices, if they are uneven, the origin coincides with a grid point. Reshapes the output to a shape, used in cmrsim simulations. The singleton-axis is reserved for repetitions contrasts.

Parameters:
  • map_size (Tuple[int, int]) – Tuple[int, int], 2D grid dimensions used to calculate coordinates relative to mid-point

  • object_dimensions (Optional[Tuple[float, float]]) – Optional Tuple[float, float] used to scale relative coordinates. Defaults to (1., 1.)

  • return_2d (bool) –

Return type:

Tensor

Returns:

(X, Y, 1, 1, 3)

compute_orientation_matrix(slice_normal, slice_position, readout_direction=None)[source]#

Computes the 4x4 transformation matrix \(A\) that transform a positional vector \(r_{s}\) defined in slice-coordinates into the gobal coordinate system \(r_{g}\). To apply the transformation, compute the matrix-vector product:

\[(x_{g}, y_{g}, x_{g}, 1) = A \cdot (x_{s}, y_{s}, x_{s}, 1)\]

To apply the inverse transformation, transpose the rotation-part of the matrix:

A_inv =  A.copy()
A_inv[:3, :3] = A[:3, :3].T
Parameters:
  • slice_normal (array) –

  • slice_position (Quantity) –

  • readout_direction (array) –

Returns:

transformation matrix - A (4, 4)

snr#

calculate_snr(single_coil_images, dynamic_noise_scan, coil_sensitivities=None)[source]#
Calculates the SNR for a multicoil-acquisition according to doi:10.1002/mrm.21868.

To guarantee correct scaling this assumes, non-zero-filled reconstruction.

Previously implemented by Robbert van Gorkum in the MRXCAT project.

Parameters:
  • single_coil_images (Union[ndarray, Tensor]) – (#coils, X, Y, [Z]) of type complex64

  • dynamic_noise_scan (Union[ndarray, Tensor]) – (#coils, X, Y, [Z]) of type complex64

  • coil_sensitivities (Union[ndarray, Tensor, None]) – Optional: (#coils, X, Y, [Z]) of type complex64 defaults to ones(1, X, Y, [Z])

Returns:

snr_map (X, Y, Z) of type float32

compute_noise_std(noiseless_single_coil_images, target_snr, coil_sensitivities=None, mask=None, **kwargs)[source]#
Computes the standard deviation of the complex gaussian noise for a set of target snr given

multiple single coil images, which are combined on reconstruction.

Parameters:
  • noiseless_single_coil_images (Union[ndarray, Tensor]) – (n_coils, X, Y, [Z]) of type complex64

  • target_snr (Iterable[float]) –

  • coil_sensitivities (Union[ndarray, Tensor, None]) – (n_coils, X, Y, [Z]) of type complex64, Optional: defaults to ones(1, X, Y, [Z]) Is used for iterative refinement.

  • mask (Union[ndarray, Tensor, None]) – (X, Y, [Z]) Optional: binary mask to specify ROI for SNR computation. Defaults to entire image.

  • kwargs

    • iteratively_refine: (bool) default=True. If True and coil_sensitivities are given, uses iterative method to refine std estimation.

Return type:

ndarray

Returns:

estimated_stds (np.array) of type np.float32 with shape like np.array(target_snr)

particle_properties#

uniform(default_value, additional_shape=(), dtype=<class 'numpy.float32'>)[source]#

Factory function to create an array containing the property of n_new particles

Parameters:
norm_magnetization(dtype=<class 'numpy.complex64'>)[source]#
Parameters:

dtype (dtype) –

t2star_lorentzian(T2p, prctile_cutoff=0.01, dtype=<class 'numpy.float32'>)[source]#
Parameters:

display#

SimulationProgressBarI(total, prefix='', suffix='', bar_width=40, print_step=20)[source]#

Graph-execution compatible command line progress-bar for running simulations

Parameters:
  • total (int) –

  • prefix (str) –

  • suffix (str) –

SimulationProgressBarII(total_voxels=0, total_segments=None, prefix='', suffix='')[source]#

Graph-execution compatible command line progress-bar for running simulations

Parameters:
  • total_voxels (Variable) –

  • total_segments (Variable) –

  • prefix (str) –

  • suffix (str) –