BidsMetadataMender#

class petpal.utils.metadata.BidsMetadataMender(json_filepath: str, decay_correction: bool = False)#

Class for repairing and filling in the gaps of BIDS metadata based on existing fields.

For most use cases, just initialize a mender object, passing a string path to the .json file, and a boolean for whether the image was decay_corrected. Then, simply calling the object (i.e. ‘mender()’) will result in keys being added/updated where possible.

The following checks are made:

  • If ‘FrameDuration’ is present, fill ‘FrameTimesStart’, assuming the first entry to be 0.

  • If ‘TracerRadionuclide’ is present, add ‘RadionuclideHalfLife’.
    • Note that ‘RadionuclideHalfLife’ is not listed in BIDS, but we find it useful to store.

  • If all the previous keys were added, use them to calculate ‘FrameReferenceTime’.
    • ‘FrameReferenceTime’ is not BIDS-required but it is useful.

  • If all the previous keys were added, add ‘DecayCorrectionFactor’ and ‘ImageDecayCorrected’.
    • If decay_correction was set to False, ‘DecayCorrectionFactor’ is a list of ones of len(FrameDuration) and ‘ImageDecayCorrected will be ‘false’, per BIDS.

Variables:
  • metadata (dict) – dictionary containing all the existing BIDS metadata

  • filepath (str) – path to .json file containing original BIDS metadata

  • decay_correction (bool) – whether or not the image is decay-corrected

Initializes a new BidsMetadataMender object.

Parameters:
  • json_filepath (str) – path to .json file with original BIDS metadata.

  • decay_correction (bool) – Whether or not the image is decay-corrected. Defaults to False.

__call__(output_filepath: str | None = None)#
_add_missing_keys()#

Repair/Fill missing keys where possible.

_add_half_life()#

Add “RadionuclideHalfLife” key to metadata.

_add_empty_decay_factors()#

Adds a list of ones for decay factors and sets ‘ImageDecayCorrected’ to False.

_add_decay_factors()#

Computes decay factors and adds ‘DecayCorrectionFactor’ to metadata.

_add_frame_times_start()#

Fill in frame starts from frame durations, assuming first frame starts at 0.

_add_frame_reference_times()#

Fill in frame reference times from frame starts and durations.

_to_file(filepath: str | None = None)#

Write metadata dictionary to a .json file; defaults to making a backup.