nifreeze.data.pet.base module

PET data representation.

nifreeze.data.pet.base.ARRAY_ATTRIBUTE_NDIM_ERROR_MSG = "PET '{attribute}' must be a 1D numpy array."

PET initialization array attribute ndim error message.

nifreeze.data.pet.base.ARRAY_ATTRIBUTE_OBJECT_ERROR_MSG = "PET '{attribute}' must be a numeric homogeneous array-like object."

PET initialization array attribute object error message.

nifreeze.data.pet.base.ATTRIBUTE_ABSENCE_ERROR_MSG = "PET '{attribute}' may not be None"

PET initialization array attribute absence error message.

nifreeze.data.pet.base.ATTRIBUTE_VOLUME_DIMENSIONALITY_MISMATCH_ERROR_MSG = "PET '{attribute}' length does not match number of frames: expected {n_frames} values, found {attr_len}."

PET attribute shape mismatch error message.

class nifreeze.data.pet.base.PET(self, dataobj: 'np.ndarray' = None, affine: 'np.ndarray' = None, brainmask: 'np.ndarray | None' = None, motion_affines: 'np.ndarray | None' = None, datahdr: 'nb.Nifti1Header | None' = None, filepath: 'Path' = NOTHING, midframe: 'Any' = None, total_duration: 'Any' = None) None[source]

Bases: BaseDataset[ndarray]

Data representation structure for PET data.

Method generated by attrs for class PET.

classmethod from_filename(filename: Path | str) Self[source]

Read an HDF5 file from disk.

lofo_split(index)[source]

Leave-one-frame-out (LOFO) for PET data.

Parameters:

index (int) – Index of the PET frame to be left out in this fold.

Returns:

  • (train_data, train_timings) (tuple) – Training data and corresponding timings, excluding the left-out frame.

  • (test_data, test_timing) (tuple) – Test data (one PET frame) and corresponding timing.

midframe: np.ndarray

A (N,) numpy array specifying the midpoint timing of each sample or frame.

set_transform(index: int, affine: ndarray, order: int = 3) None[source]

Set an affine, and update data object and gradients.

to_filename(filename: Path | str, compression: str | None = None, compression_opts: Any = None) None[source]

Write an HDF5 file to disk.

total_duration: float

A float representing the total duration of the dataset.

nifreeze.data.pet.base.SCALAR_ATTRIBUTE_ERROR_MSG = "PET '{attribute}' must be a numeric or single-element sequence object."

PET initialization scalar attribute object error message.

nifreeze.data.pet.base.TEMPORAL_ATTRIBUTE_INCONSISTENCY_ERROR_MSG = "PET 'total_duration' cannot be smaller than last 'midframe' value: found {total_duration} and {last_midframe}."

PET attribute inconsistency error message.

nifreeze.data.pet.base.format_array_like(value: Any, attr: Attribute) ndarray[source]

Convert value to a ndarray.

This function is intended for use as an attrs-style formatter.

Parameters:
  • value (Any) – The value to format.

  • attr (Attribute) – The attribute being initialized; attr.name is used in the error message.

Returns:

formatted – The formatted value.

Return type:

ndarray

:raises exc:TypeError: If the input cannot be converted to a float ndarray. :raises exc:ValueError: If the value is None.

nifreeze.data.pet.base.format_scalar_like(value: Any, attr: Attribute) float[source]

Convert value to a scalar.

Accepts:

This function is intended for use as an attrs-style formatter.

Parameters:
  • value (Any) – The value to format.

  • attr (Attribute) – The attribute being initialized; attr.name is used in the error message.

Returns:

formatted – The formatted value.

Return type:

float

:raises exc:TypeError: If the input cannot be converted to a scalar. :raises exc:ValueError: If the value is None, is of type bool or has not size/length 1.

nifreeze.data.pet.base.validate_1d_array(inst: PET, attr: Attribute, value: Any) None[source]

Strict validator to ensure an attribute is a 1D NumPy array.

Enforces that value has exactly one dimension (value.ndim == 1).

This function is intended for use as an attrs-style validator.

Parameters:
  • inst (PET) – The instance being validated (unused; present for validator signature).

  • attr (Attribute) – The attribute being validated; attr.name is used in the error message.

  • value (Any) – The value to validate.

:raises exc:ValueError: If the value is not 1D.