From 082145657733c0cde4b3e125297e6a1762e19ade Mon Sep 17 00:00:00 2001 From: Maxime RIO Date: Tue, 5 Mar 2024 03:18:10 +0000 Subject: [PATCH 1/2] try to fix code failure when dicom time fields are empty This scenario happens when anonymization empties the field (not removed). --- heudiconv/dicoms.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/heudiconv/dicoms.py b/heudiconv/dicoms.py index f504af18..96358e65 100644 --- a/heudiconv/dicoms.py +++ b/heudiconv/dicoms.py @@ -526,18 +526,18 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti 3. SeriesDate & SeriesTime (0008,0021); (0008,0031) """ - acq_date = dcm_data.get("AcquisitionDate") - acq_time = dcm_data.get("AcquisitionTime") - if not (acq_date is None or acq_time is None): + acq_date = dcm_data.get("AcquisitionDate", "").strip() + acq_time = dcm_data.get("AcquisitionTime", "").strip() + if len(acq_date) > 0 and len(acq_time) > 0: return strptime_micr(acq_date + acq_time, "%Y%m%d%H%M%S[.%f]") - acq_dt = dcm_data.get("AcquisitionDateTime") - if acq_dt is not None: + acq_dt = dcm_data.get("AcquisitionDateTime", "").strip() + if len(acq_dt) > 0: return strptime_micr(acq_dt, "%Y%m%d%H%M%S[.%f]") - series_date = dcm_data.get("SeriesDate") - series_time = dcm_data.get("SeriesTime") - if not (series_date is None or series_time is None): + series_date = dcm_data.get("SeriesDate", "").strip() + series_time = dcm_data.get("SeriesTime", "").strip() + if len(series_date) > 0 and len(series_time) > 0: return strptime_micr(series_date + series_time, "%Y%m%d%H%M%S[.%f]") return None From b3cfd73ce043a56372481cf318008bcff81a7316 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 1 May 2024 16:30:01 -0400 Subject: [PATCH 2/2] RF: replace string size comparison with a more generic "bool" of a string check --- heudiconv/dicoms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/heudiconv/dicoms.py b/heudiconv/dicoms.py index 96358e65..2c3d8029 100644 --- a/heudiconv/dicoms.py +++ b/heudiconv/dicoms.py @@ -528,16 +528,16 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti """ acq_date = dcm_data.get("AcquisitionDate", "").strip() acq_time = dcm_data.get("AcquisitionTime", "").strip() - if len(acq_date) > 0 and len(acq_time) > 0: + if acq_date and acq_time: return strptime_micr(acq_date + acq_time, "%Y%m%d%H%M%S[.%f]") acq_dt = dcm_data.get("AcquisitionDateTime", "").strip() - if len(acq_dt) > 0: + if acq_dt: return strptime_micr(acq_dt, "%Y%m%d%H%M%S[.%f]") series_date = dcm_data.get("SeriesDate", "").strip() series_time = dcm_data.get("SeriesTime", "").strip() - if len(series_date) > 0 and len(series_time) > 0: + if series_date and series_time: return strptime_micr(series_date + series_time, "%Y%m%d%H%M%S[.%f]") return None