mridc.collections.reconstruction.data package

Submodules

mridc.collections.reconstruction.data.mri_data module

class mridc.collections.reconstruction.data.mri_data.FastMRICombinedSliceDataset(roots: Sequence[Path], challenges: Sequence[str], sense_roots: Optional[Sequence[Path]] = None, transforms: Optional[Sequence[Optional[Callable]]] = None, sample_rates: Optional[Sequence[Optional[float]]] = None, volume_sample_rates: Optional[Sequence[Optional[float]]] = None, use_dataset_cache: bool = False, dataset_cache_file: Union[str, Path, PathLike] = 'dataset_cache.yaml', num_cols: Optional[Tuple[int]] = None)[source]

Bases: Dataset

A dataset that combines multiple datasets.

class mridc.collections.reconstruction.data.mri_data.FastMRISliceDataset(root: Union[str, Path, PathLike], challenge: str = 'segmentation', transform: Optional[Callable] = None, sense_root: Optional[Union[str, Path, PathLike]] = None, use_dataset_cache: bool = False, sample_rate: Optional[float] = None, volume_sample_rate: Optional[float] = None, dataset_cache_file: Union[str, Path, PathLike] = 'dataset_cache.yaml', num_cols: Optional[Tuple[int]] = None, mask_root: Optional[Union[str, Path, PathLike]] = None, consecutive_slices: int = 1)[source]

Bases: Dataset

A dataset that loads slices from a single dataset.

get_consecutive_slices(data, key, dataslice)[source]

Get consecutive slices from a given data. :param data: Data to extract slices from. :param key: Key to extract slices from. :param dataslice: Slice to extract slices from.

Returns

A list of consecutive slices.

mridc.collections.reconstruction.data.mri_data.et_query(root: str, qlist: Sequence[str], namespace: str = 'https://www.ismrm.org/ISMRMRD') str[source]

Query an XML element for a list of attributes.

Parameters
  • root (The root element of the XML tree.) –

  • qlist (A list of strings, each of which is an attribute name.) –

  • namespace (The namespace of the XML tree.) –

Return type

A string containing the value of the last attribute in the list.

mridc.collections.reconstruction.data.subsample module

class mridc.collections.reconstruction.data.subsample.Equispaced1DMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

Equispaced1DMaskFunc creates a sub-sampling mask of a 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_low_freqs = (N * 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 (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 Equispaced1DMaskFunc object is called.

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

__call__(shape: Sequence[int], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (Optional; Defines the scale of the center of the mask.) –

Return type

A tuple of the mask and the number of columns selected.

class mridc.collections.reconstruction.data.subsample.Equispaced2DMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

Same as Equispaced1DMaskFunc, but for 2D k-space data.

__call__(shape: Sequence[int], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (Optional; Defines the scale of the center of the mask.) –

Return type

A tuple of the mask and the number of columns selected.

class mridc.collections.reconstruction.data.subsample.Gaussian1DMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

Creates a 1D sub-sampling mask of a given shape.

For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region. The remaining points will be sampled according to a Gaussian distribution.

The center fractions here act as Full-Width at Half-Maximum (FWHM) values.

__call__(shape: Union[Sequence[int], ndarray], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region) –

Return type

A tuple of the mask and the number of columns selected.

gaussian_coordinates()[source]

Creates a Gaussian sampled k-space coordinates.

gaussian_kernel()[source]

Creates a Gaussian sampled k-space kernel.

gaussian_kspace()[source]

Creates a Gaussian sampled k-space center.

class mridc.collections.reconstruction.data.subsample.Gaussian2DMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

Creates a 2D sub-sampling mask of a given shape.

For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region. The remaining points will be sampled according to a Gaussian distribution.

The center fractions here act as Full-Width at Half-Maximum (FWHM) values.

__call__(shape: Union[Sequence[int], ndarray], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region) –

Return type

A tuple of the mask and the number of columns selected.

gaussian_coordinates()[source]

Creates a Gaussian sampled k-space coordinates.

gaussian_kernel()[source]

Creates a Gaussian kernel.

gaussian_kspace()[source]

Creates a Gaussian sampled k-space center.

class mridc.collections.reconstruction.data.subsample.MaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: object

A class that defines a mask function.

__call__(shape: Sequence[int], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (Shape of the input tensor.) –

  • seed (Seed for the random number generator.) –

  • half_scan_percentage (Percentage of the low-frequency columns to be retained.) –

  • scale (Scale of the mask.) –

Return type

A tuple of the mask and the number of low-frequency columns retained.

choose_acceleration()[source]

Choose acceleration.

class mridc.collections.reconstruction.data.subsample.Poisson2DMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

Creates a 2D sub-sampling mask of a given shape.

For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region. The remaining points will be sampled according to a (variable density) Poisson distribution.

For a given acceleration factor to be accurate, the scale for the fully sampled center should remain at the default 0.02. A predefined list is used to convert the acceleration factor to the appropriate r parameter needed for the variable density calculation. This list has been made to accommodate acceleration factors of 4 up to 21, rounding off to the nearest one available. As such, acceleration factors outside this range cannot be used.

__call__(shape: Union[Sequence[int], ndarray], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (For autocalibration purposes, data points near the k-space center will be fully sampled within an ellipse of which the half-axes will set to the set scale % of the fully sampled region) –

Return type

A tuple of the mask and the number of columns selected.

centered_circle()[source]

Creates a boolean centered circle image using the scale as a radius.

poisson_disc2d()[source]

Creates a 2D Poisson disc pattern.

class mridc.collections.reconstruction.data.subsample.RandomMaskFunc(center_fractions: Sequence[float], accelerations: Sequence[int])[source]

Bases: MaskFunc

RandomMaskFunc creates a sub-sampling mask of a 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_low_freqs = (N * center_fraction) columns in the center corresponding to low-frequencies.

  2. The other columns are selected uniformly at random with a probability equal to: prob = (N / acceleration - N_low_freqs) / (N - N_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 RandomMaskFunc 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.

__call__(shape: Sequence[int], seed: Optional[Union[int, Tuple[int, ...]]] = None, half_scan_percentage: Optional[float] = 0.0, scale: Optional[float] = 0.02) Tuple[Tensor, int][source]
Parameters
  • shape (The shape of the mask to be created. The shape should have at least 3 dimensions. Samples are drawn along the second last dimension.) –

  • seed (Seed for the random number generator. Setting the seed ensures the same mask is generated each time for the same shape. The random state is reset afterwards.) –

  • half_scan_percentage (Optional; Defines a fraction of the k-space data that is not sampled.) –

  • scale (Optional; Defines the scale of the center of the mask.) –

Return type

A tuple of the mask and the number of columns selected.

mridc.collections.reconstruction.data.subsample.create_mask_for_mask_type(mask_type_str: str, center_fractions: Sequence[float], accelerations: Sequence[int]) MaskFunc[source]

Creates a MaskFunc object for the given mask type.

Parameters
  • mask_type_str (The string representation of the mask type.) –

  • center_fractions (The center fractions for the mask.) –

  • accelerations (The accelerations for the mask.) –

Return type

A MaskFunc object.

mridc.collections.reconstruction.data.subsample.temp_seed(rng: <module 'numpy.random' from '/home/docs/checkouts/readthedocs.org/user_builds/mridc/envs/latest/lib/python3.9/site-packages/numpy/random/__init__.py'>, seed: ~typing.Optional[~typing.Union[int, ~typing.Tuple[int, ...]]])[source]

Temporarily sets the seed of the given random number generator.

Parameters
  • rng (The random number generator.) –

  • seed (The seed to set.) –

Return type

A context manager.

Module contents