nifreeze.data.pet module

PET data representation.

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

Bases: BaseDataset[ndarray | None]

Data representation structure for PET data.

Method generated by attrs for class PET.

classmethod from_filename(filename)[source]

Read an HDF5 file from disk.

classmethod load(filename, json_file, brainmask_file=None)[source]

Load PET data.

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 | None

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

set_transform(index, affine, order=3)[source]

Set an affine, and update data object and gradients.

to_filename(filename, compression=None, compression_opts=None)[source]

Write an HDF5 file to disk.

to_nifti(filename, *_)[source]

Write a NIfTI 1.0 file to disk.

total_duration: float | None

A float representing the total duration of the dataset.

nifreeze.data.pet.from_nii(filename: Path | str, brainmask_file: Path | str | None = None, motion_file: Path | str | None = None, frame_time: ndarray | list[float] | None = None, frame_duration: ndarray | list[float] | None = None) PET[source]

Load PET data from NIfTI, creating a PET object with appropriate metadata.

Parameters:
  • filename (os.pathlike) – The NIfTI file.

  • brainmask_file (os.pathlike, optional) – A brainmask NIfTI file. If provided, will be loaded and stored in the returned dataset.

  • motion_file (os.pathlike) – A file containing head motion affine matrices (linear).

  • frame_time (numpy.ndarray or list of float, optional) – The start times of each frame relative to the beginning of the acquisition. If None, an error is raised (since BIDS requires FrameTimesStart).

  • frame_duration (numpy.ndarray or list of float, optional) – The duration of each frame. If None, it is derived by the difference of consecutive frame times, defaulting the last frame to match the second-last.

Returns:

A PET object storing the data, metadata, and any optional mask.

Return type:

PET

Raises:

RuntimeError – If frame_time is not provided (BIDS requires it).