Skip to content

Commit 977199b

Browse files
committed
Added flag for ezbids conversion
This will ensure that AcqusitionDate and AcqusitionTime are included in the sidecar jsons.
1 parent a42196f commit 977199b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pypet2bids/pypet2bids/dcm2niix4pet.py

+11
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __init__(
175175
file_format="%p_%i_%t_%s",
176176
silent=False,
177177
tempdir_location=None,
178+
ezbids=False
178179
):
179180
"""
180181
This class is a simple wrapper for dcm2niix and contains methods to do the following in order:
@@ -215,6 +216,7 @@ def __init__(
215216
self.blood_json = None
216217
self.blood_tsv = None
217218
self.telemetry_data = {}
219+
self.ezbids=ezbids
218220
self.dcm2niix_path = self.check_for_dcm2niix()
219221
if not self.dcm2niix_path:
220222
logger.error(
@@ -589,6 +591,7 @@ def run_dcm2niix(self):
589591
check_for_missing,
590592
dicom_header,
591593
dicom2bids_json=metadata_dictionaries["dicom2bids"],
594+
ezbids=self.ezbids,
592595
**self.additional_arguments,
593596
)
594597

@@ -1162,6 +1165,13 @@ def cli():
11621165
"This information helps to improve PET2BIDS and provides an indicator of real world "
11631166
"usage crucial for obtaining funding.",
11641167
)
1168+
parser.add_argument(
1169+
"--ezbids",
1170+
action="store_true",
1171+
default=False,
1172+
help="Add fields to json output that are useful for ezBIDS or other conversion software. This will de-anonymize"
1173+
" pet2bids output and add AcquisitionDate an AcquisitionTime into the output json."
1174+
)
11651175
return parser
11661176

11671177

@@ -1328,6 +1338,7 @@ def main():
13281338
additional_arguments=cli_args.kwargs,
13291339
tempdir_location=cli_args.tempdir,
13301340
silent=cli_args.silent,
1341+
ezbids=cli_args.ezbids,
13311342
)
13321343

13331344
if cli_args.trc:

pypet2bids/pypet2bids/update_json_pet_file.py

+11
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def update_json_with_dicom_value(
149149
dicom_header,
150150
dicom2bids_json=None,
151151
silent=True,
152+
ezbids=False,
152153
**additional_arguments,
153154
):
154155
"""
@@ -160,6 +161,9 @@ def update_json_with_dicom_value(
160161
:param missing_values: dictionary output from check_json indicating missing fields and/or values
161162
:param dicom_header: the dicom or dicoms that may contain information not picked up by dcm2niix
162163
:param dicom2bids_json: a json file that maps dicom header entities to their corresponding BIDS entities
164+
:param silent: run silently without error, status, or warning messages
165+
:param ezbids: boolean to supply additional data that ezbids or other software requires, defaults to false. When
166+
true the sidecar json will be updated with AcquisitionDate, AcquisitionTime, and AcquisitionDateTime
163167
:return: a dictionary of successfully updated (written to the json file) fields and values
164168
"""
165169

@@ -297,6 +301,13 @@ def update_json_with_dicom_value(
297301
# remove scandate if it exists
298302
json_updater.remove("ScanDate")
299303

304+
# lastly if ezbids is true update the sidecar with acquisition data
305+
if ezbids:
306+
json_updater.update(
307+
{"AcquisitionDate": dicom_header.get("AcquisitionDate", ""),
308+
"AcquisitionTime": dicom_header.get("AcquisitionTime", ""),
309+
})
310+
300311
# after updating raise warnings to user if values in json don't match values in dicom headers, only warn!
301312
updated_values = json.load(open(path_to_json, "r"))
302313
for key, value in paired_fields.items():

0 commit comments

Comments
 (0)