snake.mrd_utils.loader#

Loader of MRD data.

Module Contents#

Classes#

MRDLoader

Base class for MRD data loader.

CartesianFrameDataLoader

Load cartesian MRD files k-space frames iteratively.

NonCartesianFrameDataLoader

Non Cartesian Dataloader.

Functions#

read_mrd_header

Read the header of the MRD file.

parse_sim_conf

Parse the header to populate SimConfig from an MRD Header.

parse_waveform_information

Parse the waveform information from the MRD file.

Data#

log

API#

snake.mrd_utils.loader.log = 'getLogger(...)'[source]#
snake.mrd_utils.loader.read_mrd_header(filename: _typeshed.AnyPath | ismrmrd.Dataset) ismrmrd.xsd.ismrmrdHeader[source]#

Read the header of the MRD file.

class snake.mrd_utils.loader.MRDLoader(filename: _typeshed.AnyPath, dataset_name: str = 'dataset', writeable: bool = False, swmr: bool = False)[source]#

Bases: snake._meta.LogMixin

Base class for MRD data loader.

This is to be used as a context manager.

It reimplements most of the methods of the mrd.Dataset class, and adds some useful wrappers. With this dataloader, you can open the dataset in readonly mode, which is not possible with mrd.

Initialization

__enter__()[source]#
__exit__(exc_type: Any, exc_value: Any, traceback: Any)[source]#
iter_frames(start: int | None = None, stop: int | None = None, step: int | None = None, shot_dim: bool = False) collections.abc.Generator[tuple[int, numpy.typing.NDArray[numpy.float32], numpy.typing.NDArray[numpy.complex64]], None, None][source]#

Iterate over kspace frames of the dataset.

Parameters:
  • start (int, optional) – Start index of the iteration.

  • stop (int, optional) – Stop index of the iteration.

  • step (int, optional) – Step of the iteration.

  • shot_dim (bool, optional) – Return the data reshaped with the shot dimension first.

Yields:

tuple[int, np.ndarray, np.ndarray] – The index of the frame, the trajectory and the kspace data.

abstract get_kspace_frame(idx: int) tuple[numpy.typing.NDArray[numpy.float32], numpy.typing.NDArray[numpy.complex64]][source]#

Get k-space frame trajectory/mask and data.

_read_xml_header() ismrmrd.xsd.ismrmrdHeader[source]#

Read the header of the MRD file.

_read_waveform(wavnum: int) ismrmrd.Waveform[source]#
_read_image(impath: str, imnum: int = 0) ismrmrd.Image[source]#
header() ismrmrd.xsd.ismrmrdHeader#

Get the header from the mrd file.

property _dataset: h5py.Dataset#

Get MRD dataset.

property n_frames: int#

Number of frames.

property shape: tuple[int, ...]#

Shape of the volume.

property n_coils: int#

Number of coils.

property n_acquisition: int#

Number of acquisition in the dataset.

__len__()[source]#
property n_sample: int#

Number of samples in a single acquisition.

property n_shots: int#

Number of samples in a single acquisition.

Notes

for EPI this is the number of phase encoding lines in the EPI zigzag.

property engine_model: str#

Get the engine model.

property slice_2d: bool#

Is the acquisition run on 2D slices.

get_phantom(imnum: int = 0) snake.core.Phantom[source]#

Load the phantom from the dataset.

_all_waveform_infos() dict[int, dict]#
get_dynamic(waveform_num: int) snake.core.DynamicData[source]#

Get dynamic data.

get_all_dynamic() list[snake.core.DynamicData][source]#

Get all dynamic data.

get_sim_conf() snake.core.SimConfig[source]#

Parse the sim config.

_get_image_data(name: str, idx: int = 0) numpy.typing.NDArray[numpy.complex64] | None[source]#
get_smaps() numpy.typing.NDArray[numpy.complex64] | None[source]#

Load the sensitivity maps from the dataset.

get_coil_cov(default: numpy.typing.NDArray | None = None) numpy.typing.NDArray | None[source]#

Load the coil covariance from the dataset.

class snake.mrd_utils.loader.CartesianFrameDataLoader(filename: _typeshed.AnyPath, dataset_name: str = 'dataset', writeable: bool = False, swmr: bool = False)[source]#

Bases: snake.mrd_utils.loader.MRDLoader

Load cartesian MRD files k-space frames iteratively.

Parameters:

filename (source for the MRD file.)

Examples

>>> for mask, kspace in CartesianFrameDataLoader("test.mrd"):
        image = ifft(kspace)

Initialization

get_kspace_frame(idx: int) tuple[numpy.ndarray, numpy.ndarray][source]#

Get the k-space frame.

class snake.mrd_utils.loader.NonCartesianFrameDataLoader(filename: _typeshed.AnyPath, dataset_name: str = 'dataset', writeable: bool = False, swmr: bool = False)[source]#

Bases: snake.mrd_utils.loader.MRDLoader

Non Cartesian Dataloader.

Iterate over the acquisition of the MRD file.

Examples

>>> from mrinufft import get_operator
>>> dataloader =  NonCartesianFrameDataLoader("test.mrd")
>>> for mask, kspace in data_loader:
...     nufft = get_operator("finufft")(traj,
...     shape=dataloader.shape, n_coils=dataloader.n_coils)
...     image = nufft.adj_op(kspace)

Initialization

get_kspace_frame(idx: int, shot_dim: bool = False) tuple[numpy.typing.NDArray[numpy.float32], numpy.typing.NDArray[numpy.complex64]][source]#

Get the k-space frame and the associated trajectory.

Parameters:
  • idx (int) – Index of the frame to get.

  • shot_dim (bool, optional) – Return the data reshaped with the shot dimension first.

Returns:

  • np.ndarray – The trajectory.

  • np.ndarray – The kspace data.

snake.mrd_utils.loader.parse_sim_conf(header: ismrmrd.xsd.ismrmrdHeader) snake.core.SimConfig[source]#

Parse the header to populate SimConfig from an MRD Header.

snake.mrd_utils.loader.parse_waveform_information(hdr: ismrmrd.xsd.ismrmrdHeader) dict[int, dict][source]#

Parse the waveform information from the MRD file.

Returns a dictionary with id as key and waveform information (name, parameters, etc.. ) as value.

Base64 encoded parameters are decoded.