Skip to content

Commit

Permalink
Add support for eiger-stream-v1
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
psavery committed May 17, 2024
1 parent d3550c7 commit 1b05ebc
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions hexrdgui/image_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b05ebc

Please sign in to comment.