nifreeze.data.pet module

PET data representation.

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

Bases: BaseDataset

Data representation structure for PET data.

Method generated by attrs for class PET.

frame_time: np.ndarray | None

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

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

Read an HDF5 file from disk and create a PET object.

Parameters:

filename (os.pathlike) – The HDF5 file path to read.

Returns:

A PET dataset with data loaded from the specified file.

Return type:

PET

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

Write the PET dataset to an HDF5 file on disk.

Parameters:
  • filename (os.pathlike) – The HDF5 file path to write to.

  • compression (str, optional) – Compression strategy. See create_dataset documentation.

  • compression_opts (typing.Any, optional) – Parameters for compression filters.

total_duration: float | None

A float representing the total duration of the dataset.

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

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

Parameters:
  • filename (os.pathlike) – The NIfTI or HDF5 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).