Skip to content

Commit

Permalink
added entrypoint for updating a json from a pet dicom file (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendhouseart authored Jan 12, 2024
1 parent dd91243 commit a05cd31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pypet2bids/pypet2bids/dcm2niix4pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pypet2bids/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a05cd31

Please sign in to comment.