From 8dc6c41d1b9652b73ce791a4489d362f4dab83d0 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Fri, 17 May 2024 15:23:38 -0400 Subject: [PATCH] Add support for eiger-stream-v1 This is a special HDF5 file, which requires a special imageseries to load it, since the dataset is just raw bytes that needs to be decompressed. It would be nice in the future if we could get HDF5 to decompress this data automatically, which is definitely possible, but we will need to do this for now... Signed-off-by: Patrick Avery --- hexrdgui/image_file_manager.py | 35 +++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/hexrdgui/image_file_manager.py b/hexrdgui/image_file_manager.py index 28085aa69..50828a74a 100644 --- a/hexrdgui/image_file_manager.py +++ b/hexrdgui/image_file_manager.py @@ -75,14 +75,30 @@ def open_file(self, f, options=None): dset = hdf.select(self.path[1]) ims = imageseries.open(None, 'array', data=dset) elif ext in self.HDF5_FILE_EXTS: + regular_hdf5 = True with h5py.File(f, 'r') as data: - dset = data['/'.join(self.path)] - ndim = dset.ndim - if ndim < 3: - # Handle raw two dimesional data - ims = imageseries.open(None, 'array', data=dset[()]) - - if ndim >= 3: + if data.attrs.get('version') == 'CHESS_EIGER_STREAM_V1': + ims_type = 'eiger-stream-v1' + registry = ( + imageseries.load.registry.Registry.adapter_registry + ) + if ims_type not in registry: + msg = ( + '"dectris-compression" must be installed to load ' + 'eiger stream files' + ) + raise Exception(msg) + + ims = imageseries.open(f, 'eiger-stream-v1') + regular_hdf5 = False + else: + dset = data['/'.join(self.path)] + ndim = dset.ndim + if ndim < 3: + # Handle raw two dimesional data + ims = imageseries.open(None, 'array', data=dset[()]) + + if regular_hdf5 and ndim >= 3: ims = imageseries.open( f, 'hdf5', path=self.path[0], dataname=self.path[1]) elif ext == '.npz': @@ -160,6 +176,11 @@ def hdf_path_exists(self, f): return False def hdf5_path_exists(self, f): + # If it is a special HDF5 file, just return True + with h5py.File(f, 'r') as rf: + if rf.attrs.get('version') == 'CHESS_EIGER_STREAM_V1': + return True + all_paths = [] if HexrdConfig().hdf5_path: all_paths.append(HexrdConfig().hdf5_path)