From a05cd314b5ee7b13e32a8e034b1be1ae3adca331 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:55:44 -0500 Subject: [PATCH] added entrypoint for updating a json from a pet dicom file (#258) --- pypet2bids/pypet2bids/dcm2niix4pet.py | 22 +++++++++++++++++++++- pypet2bids/pyproject.toml | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pypet2bids/pypet2bids/dcm2niix4pet.py b/pypet2bids/pypet2bids/dcm2niix4pet.py index 1b6320c5..0f6d0c3f 100644 --- a/pypet2bids/pypet2bids/dcm2niix4pet.py +++ b/pypet2bids/pypet2bids/dcm2niix4pet.py @@ -156,7 +156,7 @@ def update_json_with_dicom_value( **additional_arguments ): """ - We go through all of the missing values or keys that we find in the sidecar json and attempt to extract those + We go through all the missing values or keys that we find in the sidecar json and attempt to extract those missing entities from the dicom source. This function relies on many heuristics a.k.a. many unique conditionals and simply is what it is, hate the game not the player. @@ -282,6 +282,26 @@ def update_json_with_dicom_value( pass +def update_json_with_dicom_value_cli(): + dicom_update_parser = argparse.ArgumentParser() + dicom_update_parser.add_argument('-j', '--json', help='path to json to update', required=True) + dicom_update_parser.add_argument('-d', '--dicom', help='path to dicom to extract values from', required=True) + dicom_update_parser.add_argument('-k', '--additional_arguments', + help='additional key value pairs to update json with', nargs='*', + action=helper_functions.ParseKwargs, default={}) + + args = dicom_update_parser.parse_args() + + # get missing values + missing_values = check_json(args.json, silent=True) + + # load dicom header + dicom_header = pydicom.dcmread(args.dicom, stop_before_pixels=True) + + # update json + update_json_with_dicom_value(args.json, missing_values, dicom_header, **args.additional_arguments) + + def dicom_datetime_to_dcm2niix_time(dicom=None, date='', time=''): """ Dcm2niix provides the option of outputing the scan data and time into the .nii and .json filename at the time of diff --git a/pypet2bids/pyproject.toml b/pypet2bids/pyproject.toml index 5f4a4188..c5694979 100644 --- a/pypet2bids/pyproject.toml +++ b/pypet2bids/pyproject.toml @@ -42,6 +42,7 @@ dcm2niix4pet = 'pypet2bids.dcm2niix4pet:main' pet2bids-spreadsheet-template = 'pypet2bids.helper_functions:write_out_module' convert-pmod-to-blood = 'pypet2bids.convert_pmod_to_blood:main' ispet = 'pypet2bids.is_pet:main' +updatepetjsonfromdicom = 'pypet2bids.dcm2niix4pet:update_json_with_dicom_value_cli' [tool.poetry.group.dev.dependencies] pyinstaller = "^5.4.1"