mrpro.data.KHeader

class mrpro.data.KHeader(trajectory: KTrajectoryCalculator, b0: float, encoding_limits: EncodingLimits, recon_matrix: SpatialDimension[int], recon_fov: SpatialDimension[float], encoding_matrix: SpatialDimension[int], encoding_fov: SpatialDimension[float], acq_info: AcqInfo, h1_freq: float, n_coils: int | None = None, datetime: datetime.datetime | None = None, te: torch.Tensor | None = None, ti: torch.Tensor | None = None, fa: torch.Tensor | None = None, tr: torch.Tensor | None = None, echo_spacing: torch.Tensor | None = None, echo_train_length: int = 1, seq_type: str = 'unknown', model: str = 'unknown', vendor: str = 'unknown', protocol_name: str = 'unknown', misc: dict = <factory>, calibration_mode: enums.CalibrationMode = CalibrationMode.OTHER, interleave_dim: enums.InterleavingDimension = InterleavingDimension.OTHER, traj_type: enums.TrajectoryType = TrajectoryType.OTHER, measurement_id: str = 'unknown', patient_name: str = 'unknown', trajectory_description: TrajectoryDescription = <factory>)[source]

Bases: MoveDataMixin

MR raw data header.

All information that is not covered by the dataclass is stored in the misc dict. Our code shall not rely on this information, and it is not guaranteed to be present. Also, the information in the misc dict is not guaranteed to be correct or tested.

__init__(trajectory: KTrajectoryCalculator, b0: float, encoding_limits: EncodingLimits, recon_matrix: SpatialDimension[int], recon_fov: SpatialDimension[float], encoding_matrix: SpatialDimension[int], encoding_fov: SpatialDimension[float], acq_info: AcqInfo, h1_freq: float, n_coils: int | None = None, datetime: datetime.datetime | None = None, te: torch.Tensor | None = None, ti: torch.Tensor | None = None, fa: torch.Tensor | None = None, tr: torch.Tensor | None = None, echo_spacing: torch.Tensor | None = None, echo_train_length: int = 1, seq_type: str = 'unknown', model: str = 'unknown', vendor: str = 'unknown', protocol_name: str = 'unknown', misc: dict = <factory>, calibration_mode: enums.CalibrationMode = CalibrationMode.OTHER, interleave_dim: enums.InterleavingDimension = InterleavingDimension.OTHER, traj_type: enums.TrajectoryType = TrajectoryType.OTHER, measurement_id: str = 'unknown', patient_name: str = 'unknown', trajectory_description: TrajectoryDescription = <factory>) None

Methods

__init__(trajectory, b0, encoding_limits, ...)

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_ismrmrd(header, acq_info[, defaults, ...])

Create an Header from ISMRMRD Data.

half(*[, memory_format, copy])

Convert all float tensors to half precision.

single(*[, memory_format, copy])

Convert all float tensors to single precision.

to(*args, **kwargs)

Perform dtype and/or device conversion of data.

Attributes

trajectory

Function to calculate the k-space trajectory.

b0

Magnetic field strength [T].

encoding_limits

K-space encoding limits.

recon_matrix

Dimensions of the reconstruction matrix.

recon_fov

Field-of-view of the reconstructed image [m].

encoding_matrix

Dimensions of the encoded k-space matrix.

encoding_fov

Field of view of the image encoded by the k-space trajectory [m].

acq_info

Information of the acquisitions (i.e. readout lines).

h1_freq

Lamor frequency of hydrogen nuclei [Hz].

n_coils

Number of receiver coils.

datetime

Date and time of acquisition.

te

Echo time [s].

ti

Inversion time [s].

fa

Flip angle [rad].

tr

Repetition time [s].

echo_spacing

Echo spacing [s].

echo_train_length

Number of echoes in a multi-echo acquisition.

seq_type

Type of sequence.

model

Scanner model.

vendor

Scanner vendor.

protocol_name

Name of the acquisition protocol.

misc

Dictionary with miscellaneous parameters.

calibration_mode

Mode of how calibration data is acquired.

interleave_dim

Interleaving dimension.

traj_type

Type of trajectory.

measurement_id

Measurement ID.

patient_name

Name of the patient.

trajectory_description

Description of the trajectory.

device

Return the device of the tensors.

fa_degree

Flip angle in degree.

is_cpu

Return True if all tensors are on the CPU.

is_cuda

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

acq_info: AcqInfo

Information of the acquisitions (i.e. readout lines).

b0: float

Magnetic field strength [T].

calibration_mode: enums.CalibrationMode

Mode of how calibration data is acquired.

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

datetime: datetime.datetime | None

Date and time of acquisition.

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

echo_spacing: torch.Tensor | None

Echo spacing [s].

echo_train_length: int

Number of echoes in a multi-echo acquisition.

encoding_fov: SpatialDimension[float]

Field of view of the image encoded by the k-space trajectory [m].

encoding_limits: EncodingLimits

K-space encoding limits.

encoding_matrix: SpatialDimension[int]

Dimensions of the encoded k-space matrix.

fa: torch.Tensor | None

Flip angle [rad].

property fa_degree: Tensor | None

Flip angle in degree.

classmethod from_ismrmrd(header: ismrmrdHeader, acq_info: AcqInfo, defaults: dict | None = None, overwrite: dict | None = None, encoding_number: int = 0) Self[source]

Create an Header from ISMRMRD Data.

Parameters:
  • header – ISMRMRD header

  • acq_info – acquisition information

  • defaults – dictionary of values to be used if information is missing in header

  • overwrite – dictionary of values to be used independent of header

  • encoding_number – as ismrmrdHeader can contain multiple encodings, selects which to consider

h1_freq: float

Lamor frequency of hydrogen nuclei [Hz].

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

interleave_dim: enums.InterleavingDimension

Interleaving dimension.

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.

measurement_id: str

Measurement ID.

misc: dict

Dictionary with miscellaneous parameters.

model: str

Scanner model.

n_coils: int | None

Number of receiver coils.

patient_name: str

Name of the patient.

protocol_name: str

Name of the acquisition protocol.

recon_fov: SpatialDimension[float]

Field-of-view of the reconstructed image [m].

recon_matrix: SpatialDimension[int]

Dimensions of the reconstruction matrix.

seq_type: str

Type of sequence.

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

te: torch.Tensor | None

Echo time [s].

ti: torch.Tensor | None

Inversion time [s].

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.

tr: torch.Tensor | None

Repetition time [s].

traj_type: enums.TrajectoryType

Type of trajectory.

trajectory: KTrajectoryCalculator

Function to calculate the k-space trajectory.

trajectory_description: TrajectoryDescription

Description of the trajectory.

vendor: str

Scanner vendor.