From 082145657733c0cde4b3e125297e6a1762e19ade Mon Sep 17 00:00:00 2001 From: Maxime RIO Date: Tue, 5 Mar 2024 03:18:10 +0000 Subject: [PATCH 1/4] 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 c29047ac998681938d928d91898ea2a9bfc96fdf Mon Sep 17 00:00:00 2001 From: Maxime Rio Date: Thu, 2 May 2024 09:55:20 +1200 Subject: [PATCH 2/4] Update heudiconv/dicoms.py Co-authored-by: Yaroslav Halchenko --- heudiconv/dicoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heudiconv/dicoms.py b/heudiconv/dicoms.py index 96358e65..a2d82d2b 100644 --- a/heudiconv/dicoms.py +++ b/heudiconv/dicoms.py @@ -528,7 +528,7 @@ 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() From f3a6d5f2732af14071b531dee748f8d62ac57ae7 Mon Sep 17 00:00:00 2001 From: Maxime Rio Date: Thu, 2 May 2024 09:55:27 +1200 Subject: [PATCH 3/4] Update heudiconv/dicoms.py Co-authored-by: Yaroslav Halchenko --- heudiconv/dicoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heudiconv/dicoms.py b/heudiconv/dicoms.py index a2d82d2b..4666a722 100644 --- a/heudiconv/dicoms.py +++ b/heudiconv/dicoms.py @@ -532,7 +532,7 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti 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() From 7342206f9f08d872aa96f3d12f3749fb175bbc32 Mon Sep 17 00:00:00 2001 From: Maxime Rio Date: Thu, 2 May 2024 09:55:33 +1200 Subject: [PATCH 4/4] Update heudiconv/dicoms.py Co-authored-by: Yaroslav Halchenko --- heudiconv/dicoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heudiconv/dicoms.py b/heudiconv/dicoms.py index 4666a722..2c3d8029 100644 --- a/heudiconv/dicoms.py +++ b/heudiconv/dicoms.py @@ -537,7 +537,7 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti 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