From d9ba404d163210448db6d50076203e8f6ef0f9ca Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Sat, 17 Aug 2024 20:11:58 -0500 Subject: [PATCH] Save eiger metadata as a yaml string Because the numpy frame-cache format does not yet support nested metadata structures, we cannot save nested metadata as a frame-cache without causing errors. We have some potential solutions to support nested metadata on the horizon. Until that time, let's store the eiger stream metadata as a yaml string, so that sparse arrays can actually be created from it. The metadata is still present, it is just in the form of a yaml string. Signed-off-by: Patrick Avery --- hexrd/imageseries/load/eiger_stream_v1.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hexrd/imageseries/load/eiger_stream_v1.py b/hexrd/imageseries/load/eiger_stream_v1.py index 188309a7..661cc236 100644 --- a/hexrd/imageseries/load/eiger_stream_v1.py +++ b/hexrd/imageseries/load/eiger_stream_v1.py @@ -5,9 +5,11 @@ from dectris.compression import decompress import h5py import numpy as np +import yaml from hexrd.utils.compatibility import h5py_read_string from hexrd.utils.hdf5 import unwrap_h5_to_dict +from hexrd.utils.yaml import NumpyToNativeDumper from . import ImageSeriesAdapter from ..imageseriesiter import ImageSeriesIterator @@ -96,8 +98,22 @@ def _load_metadata(self): def _get_metadata(self): d = {} + # First, unwrap the metadata from the HDF5 file into a dict unwrap_h5_to_dict(self.__h5file['/metadata'], d) - return d + + # Because frame cache imageseries do not yet support nested + # metadata structures, we should not use them. The frame cache + # imageseries should, at some point, start allowing for nested + # metadata structures. At that point, we can return to the + # previous way. + # For now instead, we will serialize this nested structure to + # yaml and keep it as a string. This means the metadata is still + # saved and accessible. + metadata = { + 'eiger_metadata_as_yaml': yaml.dump(d, Dumper=NumpyToNativeDumper) + } + + return metadata @property def metadata(self):