direct.common package

Contents

direct.common package#

Submodules#

direct.common.subsample module#

DIRECT samplers module.

This module contains classes for creating sub-sampling masks. The masks are used to sample k-space data in MRI reconstruction. The masks are created by selecting a subset of samples from the input k-space data.

class direct.common.subsample.BaseMaskFunc(accelerations, center_fractions=None, uniform_range=True, mode=MaskFuncMode.STATIC)[source]#

Bases: object

BaseMaskFunc is the base class to create a sub-sampling mask of a given shape.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained. If multiple values are provided, then one of these numbers is chosen uniformly each time. If uniform_range is True, then two values should be given. Default: None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions=None, uniform_range=True, mode=MaskFuncMode.STATIC)[source]#

Inits BaseMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained. If multiple values are provided, then one of these numbers is chosen uniformly each time. If uniform_range is True, then two values should be given. Default: None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

choose_acceleration()[source]#

Chooses an acceleration and center fraction.

Return type:

Union[float, int, tuple[Union[float, int], Union[float, int]]]

Returns:

Acceleration and center fraction.

Raises:

NotImplementedError – If uniform range is not yet implemented.

abstract mask_func(*args, **kwargs)[source]#

Abstract methot to create a sub-sampling mask.

Return type:

Tensor

Returns:

Sampling mask.

Raises:

NotImplementedError

__call__(shape, *args, **kwargs)[source]#

Calls the mask function.

Parameters:
  • shape (tuple[int, ...]) – Shape of the mask to be created. Needs to be at least 3 dimensions. If mode is MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE, then the shape should have at least 4 dimensions.

  • args – Additional arguments to be passed to the mask function.

  • kwargs – Additional keyword arguments to be passed to the mask function.

Return type:

Tensor

Returns:

Sampling mask.

class direct.common.subsample.CIRCUSMaskFunc(subsampling_scheme, accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: BaseMaskFunc

Implementation of Cartesian undersampling (radial or spiral) using CIRCUS as shown in [1]_.

It creates radial or spiral masks for Cartesian acquired data on a grid.

Parameters:
  • subsampling_scheme (CIRCUSSamplingMode) – CIRCUSSamplingMode

  • or (The subsampling scheme to use. Can be either CIRCUSSamplingMode.CIRCUS_RADIAL)

  • CIRCUSSamplingMode.CIRCUS_SPIRAL.

  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask based on the

  • mask (maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC. :param References: :param .. [1] Liu J: a variable density :type .. [1] Liu J: CIRCUS :param Saloner D. Accelerated MRI with CIRcular Cartesian UnderSampling: a variable density :type Saloner D. Accelerated MRI with CIRcular Cartesian UnderSampling: CIRCUS :param Cartesian sampling strategy for compressed sensing and parallel imaging. Quant Imaging Med Surg.: :param 2014 Feb;4: 57-67. doi: 10.3978/j.issn.2223-4292.2014.02.01. PMID: 24649436; PMCID: PMC3947985. :type 2014 Feb;4: 1

__init__(subsampling_scheme, accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits CIRCUSMaskFunc.

Parameters:
  • subsampling_scheme (CIRCUSSamplingMode) – CIRCUSSamplingMode

  • or (The subsampling scheme to use. Can be either CIRCUSSamplingMode.CIRCUS_RADIAL)

  • CIRCUSSamplingMode.CIRCUS_SPIRAL.

  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask

  • mask (based on the maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

Raises: NotImplementedError

If the subsampling_scheme is not CIRCUSSamplingMode.CIRCUS_RADIAL or CIRCUSSamplingMode.CIRCUS_SPIRAL.

static get_square_ordered_idxs(square_side_size, square_id)[source]#

Returns ordered (clockwise) indices of a sub-square of a square matrix.

Parameters:
  • square_side_size (int) – Square side size. Dim of array.

  • square_id (int) – Number of sub-square. Can be 0, …, square_side_size // 2.

Return type:

tuple[tuple, ...]

Returns:

Indices of each point that belongs to the square_id-th sub-square starting from top-left point clockwise.

circus_radial_mask(shape, acceleration)[source]#

Implements CIRCUS radial undersampling.

Parameters:
  • shape (tuple[int, int]) – Shape of the mask.

  • acceleration (Union[float, int]) – The acceleration factor.

Return type:

Tensor

Returns:

The radial mask.

circus_spiral_mask(shape, acceleration)[source]#

Implements CIRCUS spiral undersampling.

Parameters:
  • shape (tuple[int, int]) – Shape of the mask.

  • acceleration (Union[float, int]) – The acceleration factor.

Return type:

Tensor

Returns:

The spiral mask.

static circular_centered_mask(mask, eps=0.1)[source]#

Finds the maximum (masked) disk in mask given a tolerance.

Parameters:
  • mask (Tensor) – The mask.

  • eps (float) – Tolerance for the disk radius. The disk radius is increased until the ratio of the disk area to the

  • Default (intersection area is greater than 1 + eps.) – 0.1

Return type:

Tensor

Returns:

_description_

mask_func(shape, return_acs=False, seed=None)[source]#

Produces CIRCUSMaskFunc sampling masks.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.CIRCUSSamplingMode(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: DirectEnum

Enumeration of CIRCUS sampling modes.

CIRCUS sampling modes are radial and spiral.

CIRCUS_RADIAL = 'circus-radial'#
CIRCUS_SPIRAL = 'circus-spiral'#
class direct.common.subsample.CalgaryCampinasMaskFunc(accelerations, **kwargs)[source]#

Bases: BaseMaskFunc

Implementation of Calgary-Campinas sampling mask function.

Samples are drawn from pre-computed masks provided by the challenge. The masks are available for accelerations of 5 and 10. The masks are available for shapes of \(218 \times 170/174/180\). The masks are downloaded from the challenge website and cached locally. The masks are loaded based on the shape of the input k-space data. The masks are randomly selected from the available masks for the given shape. The masks are broadcasted to the shape of the input k-space data. The autocalibration signal region is generated as a circular mask centered in the k-space with a radius of 18.

For more information, please refer to the challenge website [1]_.

Parameters:
  • accelerations (Union[list[int], tuple[int, ...]]) – Union[list[int], tuple[int, …]]

  • k-space (Amount of under-sampling_mask. An acceleration of 4 retains 25% of the)

  • by (the method is given)

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

Raises:

ValueError – If the acceleration is not 5 or 10.

References

BASE_URL = 'https://huggingface.co/datasets/NKI-AI/direct-mri-masks/resolve/main/calgary_campinas_masks/'#
MASK_MD5S = {'R10_218x170.npy': '6e1511c33dcfc4a960f526252676f7c3', 'R10_218x174.npy': '78fe23ae5eed2d3a8ff3ec128388dcc9', 'R10_218x180.npy': '5039a6c19ac2aa3472a94e4b015e5228', 'R5_218x170.npy': '6599715103cf3d71d6e87d09f865e7da', 'R5_218x174.npy': '5bd27d2da3bf1e78ad1b65c9b5e4b621', 'R5_218x180.npy': '717b51f3155c3a64cfaaddadbe90791d'}#
__init__(accelerations, **kwargs)[source]#

Inits CalgaryCampinasMaskFunc.

Parameters:
  • accelerations (Union[list[int], tuple[int, ...]]) – Union[list[int], tuple[int, …]]

  • supported. (Amount of under-sampling. Only 5 and 10 are)

Raises: ValueError

If the acceleration is not 5 or 10.

static circular_centered_mask(shape, radius)[source]#

Creates a circular centered mask.

Parameters:
  • shape (tuple[int, int]) – Shape of the mask as a two-dim tuple.

  • radius (int) – Radius of the circular mask.

Return type:

ndarray

Returns:

The circular mask.

mask_func(shape, return_acs=False, seed=None)[source]#

Downloads and loads pre-computed Poisson masks.

Currently supports shapes of \(218 \times 170/174/180\) and acceleration factors of 5 or 10.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.CartesianEquispacedMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: EquispacedMaskFunc

Cartesian equispaced vertical line mask function.

Similar to FastMRIEquispacedMaskFunc, but instead of center fraction (center_fractions) representing the fraction of center lines to the original size, here, it represents the actual number of center lines.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits CartesianEquispacedMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.CartesianMagicMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: MagicMaskFunc

Cartesian equispaced mask function as implemented in [1]_.

Similar to FastMRIMagicMaskFunc, but instead of center fraction (center_fractions) representing the fraction of center lines to the original size, here, it represents the actual number of center lines.

References

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits CartesianMagicMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.CartesianRandomMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: RandomMaskFunc

Cartesian random vertical line mask function.

Similar to FastMRIRandomMaskFunc, but instead of center fraction (center_fractions) representing the fraction of center lines to the original size, here, it represents the actual number of center lines.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits CartesianRandomMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[int], tuple[int, ...]]) – Number of low-frequence (center) columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.CartesianVerticalMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: BaseMaskFunc

CartesianVerticalMaskFunc is the base class to create vertical Cartesian sub-sampling masks.

This is the base class of Cartesian and FastMRI mask functions. The difference between Cartesian and FastMRI mask functions is that the former uses the number of center lines to be retained, while the latter uses the fraction of center lines to be retained.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits CartesianVerticalMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

static center_mask_func(num_cols, num_low_freqs)[source]#

Creates the ACS (center) mask.

Parameters:
  • num_cols (int) – Number of center columns/lines.

  • num_low_freqs (int) – Number of low-frequency columns/lines.

Return type:

ndarray

Returns:

ACS (center) mask.

class direct.common.subsample.EquispacedMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CartesianVerticalMaskFunc

Equispaced vertical line mask function.

EquispacedMaskFunc creates a sub-sampling mask of given shape. The mask selects a subset of columns from the input k-space data. If the k-space data has N columns, the mask picks out:

  1. \(N_{\text{low freqs}} = (N \times \text{center_fraction})\) columns in the center corresponding to low-frequencies if center_fraction < 1.0, or \(N_{\text{low freqs}} = \text{center_fraction}\) if center_fraction >= 1 and is integer.

  2. The other columns are selected with equal spacing at a proportion that reaches the desired acceleration rate taking into consideration the number of low frequencies. This ensures that the expected number of columns selected is equal to \(\frac{N}{\text{acceleration}}\).

It is possible to use multiple center_fractions and accelerations, in which case one possible (center_fraction, acceleration) is chosen uniformly at random each time the EquispacedMaskFunc object is called.

Note that this function may not give equispaced samples (documented in facebookresearch/fastMRI#54), which will require modifications to standard GRAPPA approaches. Nonetheless, this aspect of the function has been preserved to match the public multicoil data.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained. If multiple values are provided, then one of these numbers is chosen uniformly each time. If uniform_range is True, then two values should be given. Default: None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits EquispacedMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – If multiple values are provided, then one of these numbers is chosen uniformly each time. If uniform_range is True, then two values should be given. Default: None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates an vertical equispaced vertical line mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.FastMRIEquispacedMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: EquispacedMaskFunc

Equispaced vertical line mask function.

FastMRIEquispacedMaskFunc creates a sub-sampling mask of given shape. The mask selects a subset of columns from the input k-space data. If the k-space data has N columns, the mask picks out:

  1. \(N_{\text{low freqs}} = (N \times \text{center_fraction})\) columns in the center corresponding to low-frequencies.

  2. The other columns are selected with equal spacing at a proportion that reaches the desired acceleration rate taking into consideration the number of low frequencies. This ensures that the expected number of columns selected is equal to \(\frac{N}{\text{acceleration}}\).

It is possible to use multiple center_fractions and accelerations, in which case one possible (center_fraction, acceleration) is chosen uniformly at random each time the EquispacedMaskFunc object is called.

Note that this function may not give equispaced samples (documented in facebookresearch/fastMRI#54), which will require modifications to standard GRAPPA approaches. Nonetheless, this aspect of the function has been preserved to match the public multicoil data.

Args:

accelerations: Amount of under-sampling. center_fractions: Fraction (< 1.0) of low-frequency columns to be retained. uniform_range: If True then an acceleration will be uniformly sampled between the two values, by default False. mode: Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits FastMRIEquispacedMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction (< 1.0) of low-frequency columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.FastMRIMagicMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: MagicMaskFunc

Vertical line mask function as implemented in [1]_.

FastMRIMagicMaskFunc exploits the conjugate symmetry via offset-sampling. It is essentially an equispaced mask with an offset for the opposite site of the k-space. Since MRI images often exhibit approximate conjugate k-space symmetry, this mask is generally more efficient than FastMRIEquispacedMaskFunc.

References

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction (< 1.0) of low-frequency columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits FastMRIMagicMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction (< 1.0) of low-frequency columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.FastMRIRandomMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: RandomMaskFunc

Random vertical line mask function.

The mask selects a subset of columns from the input k-space data. If the k-space data has \(N\) columns, the mask picks out:

  1. \(N_{\text{low freqs}} = (N \times \text{center_fraction})\) columns in the center corresponding to low-frequencies.

  2. The other columns are selected uniformly at random with a probability equal to: \(\text{prob} = (N / \text{acceleration} - N_{\text{low freqs}}) / (N - N_{\text{low freqs}})\). This ensures that the expected number of columns selected is equal to (N / acceleration).

It is possible to use multiple center_fractions and accelerations, in which case one possible (center_fraction, acceleration) is chosen uniformly at random each time the MaskFunc object is called.

For example, if accelerations = [4, 8] and center_fractions = [0.08, 0.04], then there is a 50% probability that 4-fold acceleration with 8% center fraction is selected and a 50% probability that 8-fold acceleration with 4% center fraction is selected.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits FastMRIRandomMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.Gaussian1DMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CartesianVerticalMaskFunc

Gaussian 1D vertical line mask function.

This method uses Cython under the hood to generate a 1D Gaussian mask, employing rejection sampling.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits Gaussian1DMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a vertical gaussian mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.Gaussian2DMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: BaseMaskFunc

Gaussian 2D mask function.

This method uses Cython under the hood to generate a 2D Gaussian mask, employing rejection sampling.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency samples (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits Gaussian2DMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency samples (float < 1.0) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a 2D gaussian mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.KtBaseMaskFunc(accelerations, center_fractions, uniform_range=False)[source]#

Bases: BaseMaskFunc

Base class for kt mask functions.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

__init__(accelerations, center_fractions, uniform_range=False)[source]#

Inits KtBaseMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

static zero_pad_to_center(array, target_shape)[source]#

Zero pads an array to the target shape around its center.

Parameters:
  • array (ndarray) – The input array.

  • target_shape (tuple[int, ...]) – The target shape for each dimension.

Return type:

ndarray

Returns:

The zero-padded array.

static linear_indices_to_2d_coordinates(indices, row_length)[source]#

Converts linear indices to 2D coordinates.

Parameters:
  • indices (ndarray) – The linear indices to convert.

  • row_length (int) – The length of the rows in the 2D array.

Return type:

tuple[ndarray, ndarray]

Returns:

The x and y coordinates.

static find_nearest_empty_location(target_index, empty_indices, row_length)[source]#

Finds the nearest empty index to the target index in 2D space.

Parameters:
  • target_index (int) – The index of the target point.

  • empty_indices (ndarray) – The indices of empty locations.

  • row_length (int) – The length of the rows in the 2D array.

Return type:

int

Returns:

The nearest empty index.

static resolve_duplicates_on_kt_grid(phase, time, ny, nt)[source]#

Corrects overlapping trajectories in k-space by shifting points to the nearest vacant locations.

Parameters:
  • phase (ndarray) – The phase coordinates of the trajectories.

  • time (ndarray) – The time coordinates of the trajectories.

  • ny (int) – The number of phase encoding steps.

  • nt (int) – The number of time encoding steps.

Return type:

tuple[ndarray, ndarray]

Returns:

Corrected phase and time coordinates.

static crop_center(array, target_height, target_width)[source]#

Crops the center of an array to the target height and width.

Parameters:
  • array – The input array.

  • target_height – The target height.

  • target_width – The target width.

Returns:

The cropped array.

class direct.common.subsample.KtGaussian1DMaskFunc(accelerations, center_fractions, uniform_range=False, alpha=0.28, std_scale=5.0)[source]#

Bases: KtBaseMaskFunc

Kt Gaussian 1D mask function.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • alpha (float) – 0 < alpha < 1 controls sampling density; 0: uniform density, 1: maximally non-uniform density.

  • std_scale (float) – The standard deviation scaling of the Gaussian envelope for sampling density. Default: 5.0.

  • Default (The standard deviation scaling of the Gaussian envelope for sampling density.) – 5.0.

__init__(accelerations, center_fractions, uniform_range=False, alpha=0.28, std_scale=5.0)[source]#

Inits KtGaussian1DMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Union[list[Number], tuple[Number, …]]

  • under-sampling. (Amount of)

  • center_fractions (Union[list[float], tuple[float, ...]]) – Union[list[float], tuple[float, …]]

  • columns (Fraction of low-frequency)

uniform_range: If True then an acceleration will be uniformly sampled between the two values, by default False. alpha: 0 < alpha < 1 controls sampling density; 0: uniform density, 1: maximally non-uniform density. Default: 0.28. std_scale: The standard deviation scaling of the Gaussian envelope for sampling density. Default: 5.0.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a kt Gaussian 1D mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.KtRadialMaskFunc(accelerations, center_fractions, uniform_range=False, crop_corner=False)[source]#

Bases: KtBaseMaskFunc

Kt radial mask function.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

  • crop_corner (bool) – If True, the mask is cropped to the corners. Default: False.

__init__(accelerations, center_fractions, uniform_range=False, crop_corner=False)[source]#

Inits KtRadialMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Union[list[Number], tuple[Number, …]]

  • under-sampling. (Amount of)

  • center_fractions (Union[list[float], tuple[float, ...]]) – Union[list[float], tuple[float, …]]

  • columns (Fraction of low-frequency)

uniform_range: If True then an acceleration will be uniformly sampled between the two values, by default False. crop_corner: If True, the mask is cropped to the corners. Default: False.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a kt radial mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.KtUniformMaskFunc(accelerations, center_fractions, uniform_range=False)[source]#

Bases: KtBaseMaskFunc

Kt uniform mask function.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

__init__(accelerations, center_fractions, uniform_range=False)[source]#

Inits KtUniformMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • columns (Fraction of low-frequency)

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values, by default False.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a kt uniform mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.MagicMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CartesianVerticalMaskFunc

Vertical line mask function as implemented in [1]_.

MagicMaskFunc exploits the conjugate symmetry via offset-sampling. It is essentially an equispaced mask with an offset for the opposite site of the k-space. Since MRI images often exhibit approximate conjugate k-space symmetry, this mask is generally more efficient than EquispacedMaskFunc.

References

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – If < 1.0 this corresponds to the fraction of low-frequency columns to be retained. If >= 1 (integer) this corresponds to the exact number of low-frequency columns to be retained.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits MagicMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by

  • True. (mask_type. Has to be the same length as center_fractions if uniform_range is not)

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – If < 1.0 this corresponds to the fraction of low-frequency columns to be retained.

  • retained. (If >= 1.0 this corresponds to the exact number of low-frequency columns to be)

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates a vertical equispaced mask that exploits conjugate symmetry.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.MaskFuncMode(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: DirectEnum

STATIC = 'static'#
DYNAMIC = 'dynamic'#
MULTISLICE = 'multislice'#
class direct.common.subsample.RadialMaskFunc(accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CIRCUSMaskFunc

Computes CIRCUS radial masks for Cartesian data.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask

  • mask (based on the maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits RadialMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask

  • mask (based on the maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.RandomMaskFunc(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CartesianVerticalMaskFunc

Random vertical line mask function.

The mask selects a subset of columns from the input k-space data. If the k-space data has \(N\) columns, the mask picks out:

  1. \(N_{\text{low freqs}} = (N \times \text{center_fraction})\) columns in the center corresponding to low-frequencies if center_fraction < 1.0, or \(N_{\text{low freqs}} = \text{center_fraction}\) if center_fraction >= 1 and is integer.

  2. The other columns are selected uniformly at random with a probability equal to: \(\text{prob} = (N / \text{acceleration} - N_{\text{low freqs}}) / (N - N_{\text{low freqs}})\). This ensures that the expected number of columns selected is equal to (N / acceleration).

It is possible to use multiple center_fractions and accelerations, in which case one possible (center_fraction, acceleration) is chosen uniformly at random each time the MaskFunc object is called.

For example, if accelerations = [4, 8] and center_fractions = [0.08, 0.04], then there is a 50% probability that 4-fold acceleration with 8% center fraction is selected and a 50% probability that 8-fold acceleration with 4% center fraction is selected.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • provided (If multiple values are)

  • uniform_range (bool)

  • True (is) – None.

  • Default (then two values should be given.) – None.

  • uniform_range – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits RandomMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling_mask. An acceleration of 4 retains 25% of the k-space, the method is given by mask_type. Has to be the same length as center_fractions if uniform_range is not True.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained. If multiple values are provided, then one of these numbers is chosen uniformly each time. If uniform_range is True, then two values should be given. Default: None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. If MaskFuncMode.STATIC, then a single mask is created independent of the requested shape, and will be broadcasted to the shape by expanding other dimensions with 1, if applicable. If MaskFuncMode.DYNAMIC, this expects the shape to have more then 3 dimensions, and the mask will be created for each time frame along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE, the mask will be created for each slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

mask_func(shape, return_acs=False, seed=None)[source]#

Creates vertical line mask.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – Shape of the mask to be created. The shape should at least 3 dimensions.

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. Default: None.

Return type:

Tensor

Returns:

The sampling mask.

class direct.common.subsample.SpiralMaskFunc(accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Bases: CIRCUSMaskFunc

Computes CIRCUS spiral masks for Cartesian data.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask

  • mask (based on the maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

__init__(accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC)[source]#

Inits SpiralMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...], None]) – Fraction (< 1.0) of low-frequency samples to be retained. If None, it will calculate the acs mask

  • mask (based on the maximum masked disk in the generated) – None.

  • uniform_range (bool) – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode)

  • MaskFuncMode.STATIC (If)

  • MaskFuncMode.DYNAMIC (if applicable. If)

  • MaskFuncMode.MULTISLICE. (or)

  • MaskFuncMode.STATIC

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC.

class direct.common.subsample.VariableDensityPoissonMaskFunc(accelerations, center_fractions, mode=MaskFuncMode.STATIC, crop_corner=False, max_attempts=10, tol=0.2, slopes=None)[source]#

Bases: BaseMaskFunc

Variable Density Poisson sampling mask function. Based on [1]_.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Must have the same length as accelerations. Amount of center fully-sampling.

  • center_scale='r' (For)

  • to (then a centered disk area with radius equal)

:param : math:R = sqrt{{n_r}^2 + {n_c}^2} \times r will be fully sampled, where \(n_r\) and \(n_c\) :param denote the input shape.: :type mode: MaskFuncMode :param mode: Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. :param If MaskFuncMode.STATIC: :param then a single mask is created independent of the requested shape: :param and will be: :param broadcasted to the shape by expanding other dimensions with 1: :param if applicable. If MaskFuncMode.DYNAMIC: :param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC. :type crop_corner: Optional[bool] :param crop_corner: If True mask will be disk. Default: False. :type max_attempts: Optional[int] :param max_attempts: Maximum rejection samples. Default: 10. :type tol: Optional[float] :param tol: Maximum deviation between the generated mask acceleration and the desired acceleration. Default: 0.2. :type slopes: Union[list[float], tuple[float, ...], None] :param slopes: An increasing sequence of non-negative floats (of length 2) to be used :param for the generation of the sampling radius. Default: None.

Note:

  • Code inspired and modified from [2] with BSD-3 licence, Copyright (c) 2016, Frank Ong, Copyright (c) 2016,

    The Regents of the University of California [3].

References:

__init__(accelerations, center_fractions, mode=MaskFuncMode.STATIC, crop_corner=False, max_attempts=10, tol=0.2, slopes=None)[source]#

Inits VariableDensityPoissonMaskFunc.

Parameters:
  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[float], tuple[float, ...]]) – Must have the same length as accelerations. Amount of center fully-sampling.

  • center_scale='r' (For)

  • to (then a centered disk area with radius equal)

:param : math:R = sqrt{{n_r}^2 + {n_c}^2} times r will be fully sampled, where \(n_r\) and \(n_c\) :param denote the input shape.: :type mode: MaskFuncMode :param mode: Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE. :param If MaskFuncMode.STATIC: :param then a single mask is created independent of the requested shape: :param and will be: :param broadcasted to the shape by expanding other dimensions with 1: :param if applicable. If MaskFuncMode.DYNAMIC: :param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC. :type crop_corner: Optional[bool] :param crop_corner: If True mask will be disk. Default: False. :type max_attempts: Optional[int] :param max_attempts: Maximum rejection samples. Default: 10. :type tol: Optional[float] :param tol: Maximum deviation between the generated mask acceleration and the desired acceleration. Default: 0.2. :type slopes: Union[list[float], tuple[float, ...], None] :param slopes: An increasing sequence of non-negative floats (of length 2) to be used :param for the generation of the sampling radius. Default: None.

mask_func(shape, return_acs=False, seed=None)[source]#

Produces variable Density Poisson sampling masks.

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the mask to be created. The shape should at least 3 dimensions.

  • dimension. (Samples are drawn along the second last)

  • return_acs (bool) – Return the autocalibration signal region as a mask.

  • seed (Union[int, Iterable[int], None]) – Seed for the random number generator. Setting the seed ensures the same mask is generated

  • Default (each time for the same shape.) – None.

Return type:

Tensor

Returns:

The sampling mask of shape (1, shape[0], shape[1], 1).

poisson(num_rows, num_cols, center_fraction, acceleration, seed=0)[source]#

Calculates mask by calling the cython _poisson method.

Parameters:
  • num_rows (int) – Number of rows - x-axis size.

  • num_cols (int) – Number of columns - y-axis size.

  • center_fraction (float) – Amount of center fully-sampling.

  • acceleration (float) – Acceleration factor.

  • seed (int) – Seed to be used by cython function. Default: 0.

Return type:

Tensor

Returns:

Sampling mask of shape (num_rows, num_cols).

direct.common.subsample.build_masking_function(name, accelerations, center_fractions=None, uniform_range=False, mode=MaskFuncMode.STATIC, **kwargs)[source]#

Builds a mask function.

Parameters:
  • name (str) – Name of the mask function.

  • accelerations (Union[list[Union[float, int]], tuple[Union[float, int], ...]]) – Amount of under-sampling.

  • center_fractions (Union[list[Union[float, int]], tuple[Union[float, int], ...], None]) – Fraction of low-frequency columns (float < 1.0) or number of low-frequence columns (integer) to be retained.

  • provided (If multiple values are)

  • uniform_range (bool)

  • True (is) – None.

  • Default (then two values should be given.) – None.

  • uniform_range – If True then an acceleration will be uniformly sampled between the two values. Default: False.

  • mode (MaskFuncMode) – Mode of the mask function. Can be MaskFuncMode.STATIC, MaskFuncMode.DYNAMIC, or MaskFuncMode.MULTISLICE.

  • MaskFuncMode.STATIC (If)

  • shape (then a single mask is created independent of the requested)

  • be (and will)

  • 1 (broadcasted to the shape by expanding other dimensions with)

  • MaskFuncMode.DYNAMIC (if applicable. If)

:param : :param this expects the shape to have more then 3 dimensions: :param and the mask will be created for each time frame: :param along the fourth last dimension. Similarly for MaskFuncMode.MULTISLICE: :param the mask will be created for each: :param slice along the fourth last dimension. Default: MaskFuncMode.STATIC. :type **kwargs: dict[str, Any] :param **kwargs: Additional keyword arguments to be passed to the mask function. These will be passed as keyword arguments :param to the mask function constructor. If the mask function constructor does not accept these arguments: :param they will: :param be ignored.:

Return type:

BaseMaskFunc

Returns:

The mask function.

direct.common.subsample.centered_disk_mask(shape, center_scale)[source]#

Creates a mask with a centered disk of radius \(R=\sqrt{c_x \cdot c_y \cdot r / \pi}\).

Parameters:
  • shape (Union[list[int], tuple[int, ...]]) – The shape of the (2D) mask to be created.

  • center_scale (float) – Center scale.

Return type:

ndarray

Returns:

The mask.

direct.common.subsample.integerize_seed(seed)[source]#

Returns an integer seed.

If input is integer, will return the input. If input is None, will return a random integer seed. If input is a tuple or list, will return a random integer seed based on the input.

Can be useful for functions that take as input only integer seeds (e.g. cython functions).

Parameters:

seed (Union[None, tuple[int, ...], list[int]]) – Input seed to integerize.

Return type:

int

Returns:

Integer seed.

direct.common.subsample_config module#

class direct.common.subsample_config.MaskingConfig(name='???', accelerations=(5.0,), center_fractions=(0.1,), uniform_range=False, mode=MaskFuncMode.STATIC, val_accelerations=(5.0, 10.0), val_center_fractions=(0.1, 0.05))[source]#

Bases: BaseConfig

name = '???'#
accelerations = (5.0,)#
center_fractions = (0.1,)#
uniform_range = False#
mode = 'static'#
val_accelerations = (5.0, 10.0)#
val_center_fractions = (0.1, 0.05)#
__init__(name='???', accelerations=(5.0,), center_fractions=(0.1,), uniform_range=False, mode=MaskFuncMode.STATIC, val_accelerations=(5.0, 10.0), val_center_fractions=(0.1, 0.05))#

Module contents#

Common utilities for DIRECT.