mrpro.data.KData

class mrpro.data.KData(header: ~mrpro.data.KHeader.KHeader = <property object>, data: ~torch.Tensor = <property object>, traj: ~mrpro.data.KTrajectory.KTrajectory = <property object>)[source]

Bases: KDataSplitMixin, KDataRearrangeMixin, KDataSelectMixin, KDataRemoveOsMixin, MoveDataMixin

MR raw data / k-space data class.

__init__(header: ~mrpro.data.KHeader.KHeader = <property object>, data: ~torch.Tensor = <property object>, traj: ~mrpro.data.KTrajectory.KTrajectory = <property object>) None

Methods

__init__([header, data, traj])

clone()

Return a deep copy of the object.

cpu(*[, memory_format, copy])

Put in CPU memory.

cuda([device, non_blocking, memory_format, copy])

Put object in CUDA memory.

double(*[, memory_format, copy])

Convert all float tensors to double precision.

from_file(filename, ktrajectory[, ...])

Load k-space data from an ISMRMRD file.

half(*[, memory_format, copy])

Convert all float tensors to half precision.

rearrange_k2_k1_into_k1()

Rearrange kdata from (.

remove_readout_os()

Remove any oversampling along the readout (k0) direction [GAD].

select_other_subset(subset_idx, subset_label)

Select a subset from the other dimension of KData.

single(*[, memory_format, copy])

Convert all float tensors to single precision.

split_k1_into_other(split_idx, other_label)

Based on an index tensor, split the data in e.g. phases.

split_k2_into_other(split_idx, other_label)

Based on an index tensor, split the data in e.g. phases.

to(*args, **kwargs)

Perform dtype and/or device conversion of data.

Attributes

header

Header information for k-space data

data

K-space data.

traj

K-space trajectory along kz, ky and kx.

device

Return the device of the tensors.

is_cpu

Return True if all tensors are on the CPU.

is_cuda

Return True if all tensors are on a single CUDA device.

clone() Self

Return a deep copy of the object.

cpu(*, memory_format: memory_format = torch.preserve_format, copy: bool = False) Self

Put in CPU memory.

Parameters:
  • memory_format – The desired memory format of returned tensor.

  • copy – If True, the returned tensor will always be a copy, even if the input was already on the correct device. This will also create new tensors for views

cuda(device: device | str | int | None = None, *, non_blocking: bool = False, memory_format: memory_format = torch.preserve_format, copy: bool = False) Self

Put object in CUDA memory.

Parameters:
  • device – The destination GPU device. Defaults to the current CUDA device.

  • non_blocking – If True and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect.

  • memory_format – The desired memory format of returned tensor.

  • copy – If True, the returned tensor will always be a copy, even if the input was already on the correct device. This will also create new tensors for views

data: Tensor

K-space data. Shape (…other coils k2 k1 k0)

property device: device | None

Return the device of the tensors.

Looks at each field of a dataclass implementing a device attribute, such as torch.Tensors or MoveDataMixin instances. If the devices of the fields differ, an InconsistentDeviceError is raised, otherwise the device is returned. If no field implements a device attribute, None is returned.

Raises:

InconsistentDeviceError: – If the devices of different fields differ.

Return type:

The device of the fields or None if no field implements a device attribute.

double(*, memory_format: memory_format = torch.preserve_format, copy: bool = False) Self

Convert all float tensors to double precision.

converts float to float64 and complex to complex128

Parameters:
  • memory_format – The desired memory format of returned tensor.

  • copy – If True, the returned tensor will always be a copy, even if the input was already on the correct device. This will also create new tensors for views

classmethod from_file(filename: str | ~pathlib.Path, ktrajectory: ~mrpro.data.traj_calculators.KTrajectoryCalculator.KTrajectoryCalculator | ~mrpro.data.KTrajectory.KTrajectory | ~mrpro.data.traj_calculators.KTrajectoryIsmrmrd.KTrajectoryIsmrmrd, header_overwrites: dict[str, object] | None = None, dataset_idx: int = -1, acquisition_filter_criterion: ~collections.abc.Callable = <function is_image_acquisition>) Self[source]

Load k-space data from an ISMRMRD file.

Parameters:
  • filename – path to the ISMRMRD file

  • ktrajectory – KTrajectoryCalculator to calculate the k-space trajectory or an already calculated KTrajectory

  • header_overwrites – dictionary of key-value pairs to overwrite the header

  • dataset_idx – index of the ISMRMRD dataset to load (converter creates dataset, dataset_1, …)

  • acquisition_filter_criterion – function which returns True if an acquisition should be included in KData

half(*, memory_format: memory_format = torch.preserve_format, copy: bool = False) Self

Convert all float tensors to half precision.

converts float to float16 and complex to complex32

Parameters:
  • memory_format – The desired memory format of returned tensor.

  • copy – If True, the returned tensor will always be a copy, even if the input was already on the correct device. This will also create new tensors for views

header: KHeader

Header information for k-space data

property is_cpu: bool

Return True if all tensors are on the CPU.

Checks all tensor attributes of the dataclass for their device, (recursively if an attribute is a MoveDataMixin)

Returns False if not all tensors are on cpu or if the device is inconsistent, returns True if the data class has no tensors as attributes.

property is_cuda: bool

Return True if all tensors are on a single CUDA device.

Checks all tensor attributes of the dataclass for their device, (recursively if an attribute is a MoveDataMixin)

Returns False if not all tensors are on the same CUDA devices, or if the device is inconsistent, returns True if the data class has no tensors as attributes.

rearrange_k2_k1_into_k1() Self

Rearrange kdata from (… k2 k1 …) to (… 1 (k2 k1) …).

Parameters:

kdata – K-space data (other coils k2 k1 k0)

Return type:

K-space data (other coils 1 (k2 k1) k0)

remove_readout_os() Self

Remove any oversampling along the readout (k0) direction [GAD].

Returns a copy of the data.

Parameters:

kdata – K-space data

Return type:

Copy of K-space data with oversampling removed.

Raises:

ValueError – If the recon matrix along x is larger than the encoding matrix along x.

References

select_other_subset(subset_idx: Tensor, subset_label: Literal['average', 'slice', 'contrast', 'phase', 'repetition', 'set']) Self

Select a subset from the other dimension of KData.

Parameters:
  • kdata – K-space data (other coils k2 k1 k0)

  • subset_idx – Index which elements of the other subset to use, e.g. phase 0,1,2 and 5

  • subset_label – Name of the other label, e.g. phase

Return type:

K-space data (other_subset coils k2 k1 k0)

Raises:

ValueError – If the subset indices are not available in the data

single(*, memory_format: memory_format = torch.preserve_format, copy: bool = False) Self

Convert all float tensors to single precision.

converts float to float32 and complex to complex64

Parameters:
  • memory_format – The desired memory format of returned tensor.

  • copy – If True, the returned tensor will always be a copy, even if the input was already on the correct device. This will also create new tensors for views

split_k1_into_other(split_idx: Tensor, other_label: Literal['average', 'slice', 'contrast', 'phase', 'repetition', 'set']) Self

Based on an index tensor, split the data in e.g. phases.

Parameters:
  • kdata – K-space data (other coils k2 k1 k0)

  • split_idx – 2D index describing the k1 points in each block to be moved to other dimension (other_split, k1_per_split)

  • other_label – Label of other dimension, e.g. repetition, phase

Return type:

K-space data with new shape ((other other_split) coils k2 k1_per_split k0)

split_k2_into_other(split_idx: Tensor, other_label: Literal['average', 'slice', 'contrast', 'phase', 'repetition', 'set']) Self

Based on an index tensor, split the data in e.g. phases.

Parameters:
  • kdata – K-space data (other coils k2 k1 k0)

  • split_idx – 2D index describing the k2 points in each block to be moved to other dimension (other_split, k2_per_split)

  • other_label – Label of other dimension, e.g. repetition, phase

Return type:

K-space data with new shape ((other other_split) coils k2_per_split k1 k0)

to(*args, **kwargs) Self

Perform dtype and/or device conversion of data.

A torch.dtype and torch.device are inferred from the arguments args and kwargs. Please have a look at the documentation of torch.Tensor.to() for more details.

A new instance of the dataclass will be returned.

The conversion will be applied to all Tensor- or Module fields of the dataclass, and to all fields that implement the MoveDataMixin.

The dtype-type, i.e. float or complex will always be preserved, but the precision of floating point dtypes might be changed.

Example: If called with dtype=torch.float32 OR dtype=torch.complex64:

  • A complex128 tensor will be converted to complex64

  • A float64 tensor will be converted to float32

  • A bool tensor will remain bool

  • An int64 tensor will remain int64

If other conversions are desired, please use the torch.Tensor.to() method of the fields directly.

If the copy argument is set to True (default), a deep copy will be returned even if no conversion is necessary. If two fields are views of the same data before, in the result they will be independent copies if copy is set to True or a conversion is necessary. If set to False, some Tensors might be shared between the original and the new object.

traj: KTrajectory

K-space trajectory along kz, ky and kx. Shape (…other k2 k1 k0)