Skip to content

Commit b08e40e

Browse files
committed
DSEGOG-255 Support both timestamp formats for HDF file ingestion
- This is so the old Gemini test data still works
1 parent 9d31baa commit b08e40e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

operationsgateway_api/src/records/hdf_handler.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import h5py
77
from pydantic import ValidationError
88

9-
from operationsgateway_api.src.constants import ID_DATETIME_FORMAT
9+
from operationsgateway_api.src.constants import DATA_DATETIME_FORMAT, ID_DATETIME_FORMAT
1010
from operationsgateway_api.src.exceptions import HDFDataExtractionError, ModelError
1111
from operationsgateway_api.src.models import (
1212
ImageChannelMetadataModel,
@@ -52,13 +52,24 @@ def extract_data(self) -> Tuple[RecordModel, List[WaveformModel], List[ImageMode
5252
metadata_hdf["timestamp"],
5353
timestamp_format,
5454
)
55-
self.record_id = metadata_hdf["timestamp"].strftime(ID_DATETIME_FORMAT)
56-
except ValueError as exc:
57-
raise HDFDataExtractionError(
58-
"Incorrect timestamp format for metadata timestamp. Use"
59-
f" {timestamp_format} instead",
60-
) from exc
61-
55+
except ValueError:
56+
# Try using alternative timestamp format that might be used for older HDF
57+
# files such as old Gemini test data
58+
# TODO - when Gemini test data is needed, remove this try/except block to
59+
# have a second attempt to convert the timestamp - go straight
60+
# to raising an exception
61+
try:
62+
metadata_hdf["timestamp"] = datetime.strptime(
63+
metadata_hdf["timestamp"],
64+
DATA_DATETIME_FORMAT,
65+
)
66+
except ValueError as exc:
67+
raise HDFDataExtractionError(
68+
"Incorrect timestamp format for metadata timestamp. Use"
69+
f" {timestamp_format} instead",
70+
) from exc
71+
72+
self.record_id = metadata_hdf["timestamp"].strftime(ID_DATETIME_FORMAT)
6273
self.extract_channels()
6374

6475
try:

0 commit comments

Comments
 (0)