From edf1ea985c3d62c4a5c985de541d1d1cb7a76280 Mon Sep 17 00:00:00 2001 From: Tom Vaucourt Date: Mon, 17 Jun 2024 11:32:25 +0200 Subject: [PATCH] fix poct header decoding error handling and acquisition date conversion --- oct_converter/dicom/dicom.py | 6 +----- oct_converter/readers/boct.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/oct_converter/dicom/dicom.py b/oct_converter/dicom/dicom.py index 1beac3e..0e9e017 100644 --- a/oct_converter/dicom/dicom.py +++ b/oct_converter/dicom/dicom.py @@ -201,11 +201,7 @@ def write_opt_dicom( ds.ImageType = ["DERIVED", "SECONDARY"] ds.SamplesPerPixel = 1 if meta.series_info.acquisition_date: - # Convert string to datetime object - input_datetime = datetime.strptime( - meta.series_info.acquisition_date, "%Y-%m-%d %H:%M:%S" - ) - ds.AcquisitionDateTime = input_datetime.strftime("%Y%m%d%H%M%S.%f") + ds.AcquisitionDateTime = meta.series_info.acquisition_date.strftime("%Y%m%d%H%M%S.%f") else: ds.AcquisitionDateTime = "" diff --git a/oct_converter/readers/boct.py b/oct_converter/readers/boct.py index 6a13f2d..1b45ded 100644 --- a/oct_converter/readers/boct.py +++ b/oct_converter/readers/boct.py @@ -8,7 +8,7 @@ import h5py import numpy as np -from construct import Struct +from construct import Struct, StringError from numpy.typing import NDArray from oct_converter.exceptions import InvalidOCTReaderError @@ -39,7 +39,7 @@ def __init__(self, filepath: Path | str) -> None: def _validate(self, path: Path) -> bool: try: self.header_structure.parse_file(path) - except UnicodeDecodeError: + except StringError: raise InvalidOCTReaderError( "OCT header does not match Bioptigen .OCT format. Did you mean to use Optovue .oct (POCT)?" )