Commit fc5619a4 authored by Tim Schoof's avatar Tim Schoof
Browse files

Add limited support for nexus files

parent 24d22b6d
......@@ -16,7 +16,8 @@ VERSION = '0.0.3'
# What packages are required for this module to be executed?
REQUIRED = [
'attrs', 'numpy', 'asapo_consumer', 'asapo_producer', 'scikit-image'
'attrs', 'numpy', 'asapo_consumer', 'asapo_producer', 'scikit-image',
'h5py'
]
# What packages are optional?
......
import io
import numpy as np
import h5py
from skimage.io import imread
......@@ -12,11 +13,29 @@ def get_image(data, metadata):
shape = metadata["meta"]["shape"]
dtype = metadata["meta"]["dtype"]
image = np.frombuffer(data, dtype=dtype).reshape(shape)
elif typ == "nxs":
buf = io.BytesIO(data)
h5file = h5py.File(buf)
image = get_default_data(h5file)
else:
raise ValueError("Unknown extension: " + typ)
return image
def get_default_data(group):
default_name = group.attrs.get("default", None)
if default_name:
return get_default_data(group[default_name])
signal_name = group.attrs.get("signal", "data")
signal = group[signal_name]
if signal.ndim == 1:
axis_name = group.attrs.get("axes", "axis")[0]
axis = group[axis_name]
return np.vstack((axis, signal)).T
else:
return np.asarray(signal)
def get_filename_parts(metadata):
name = metadata["name"]
base, sep, index_and_ext = name.rpartition("-")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment