BidsMetadataMender ======================================== .. py: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. :ivar metadata: dictionary containing all the existing BIDS metadata :vartype metadata: dict :ivar filepath: path to .json file containing original BIDS metadata :vartype filepath: str :ivar decay_correction: whether or not the image is decay-corrected :vartype decay_correction: bool Initializes a new BidsMetadataMender object. :param json_filepath: path to .json file with original BIDS metadata. :type json_filepath: str :param decay_correction: Whether or not the image is decay-corrected. Defaults to False. :type decay_correction: bool .. py:method:: __call__(output_filepath: str | None = None) .. py:method:: _add_missing_keys() Repair/Fill missing keys where possible. .. py:method:: _add_half_life() Add "RadionuclideHalfLife" key to metadata. .. py:method:: _add_empty_decay_factors() Adds a list of ones for decay factors and sets 'ImageDecayCorrected' to False. .. py:method:: _add_decay_factors() Computes decay factors and adds 'DecayCorrectionFactor' to metadata. .. py:method:: _add_frame_times_start() Fill in frame starts from frame durations, assuming first frame starts at 0. .. py:method:: _add_frame_reference_times() Fill in frame reference times from frame starts and durations. .. py:method:: _to_file(filepath: str | None = None) Write metadata dictionary to a .json file; defaults to making a backup.