|
6 | 6 | import h5py
|
7 | 7 | from pydantic import ValidationError
|
8 | 8 |
|
9 |
| -from operationsgateway_api.src.constants import ID_DATETIME_FORMAT |
| 9 | +from operationsgateway_api.src.constants import DATA_DATETIME_FORMAT, ID_DATETIME_FORMAT |
10 | 10 | from operationsgateway_api.src.exceptions import HDFDataExtractionError, ModelError
|
11 | 11 | from operationsgateway_api.src.models import (
|
12 | 12 | ImageChannelMetadataModel,
|
@@ -52,13 +52,24 @@ def extract_data(self) -> Tuple[RecordModel, List[WaveformModel], List[ImageMode
|
52 | 52 | metadata_hdf["timestamp"],
|
53 | 53 | timestamp_format,
|
54 | 54 | )
|
55 |
| - self.record_id = metadata_hdf["timestamp"].strftime(ID_DATETIME_FORMAT) |
56 | 55 | except ValueError as exc:
|
57 |
| - raise HDFDataExtractionError( |
58 |
| - "Incorrect timestamp format for metadata timestamp. Use" |
59 |
| - f" {timestamp_format} instead", |
60 |
| - ) from exc |
61 |
| - |
| 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) |
62 | 73 | self.extract_channels()
|
63 | 74 |
|
64 | 75 | try:
|
|
0 commit comments