# Uses DECTRIS Stream2 example import zmq import numpy as np import sys import signal import cbor2 import time from dectris.compression import decompress from tifffile import imwrite TERMINATE = False def decode_multi_dim_array(tag, column_major): dimensions, contents = tag.value if isinstance(contents, list): array = np.empty((len(contents),), dtype=object) array[:] = contents elif isinstance(contents, (np.ndarray, np.generic)): array = contents else: raise cbor2.CBORDecodeValueError("expected array or typed array") return array.reshape(dimensions, order="F" if column_major else "C") def decode_typed_array(tag, dtype): if not isinstance(tag.value, bytes): raise cbor2.CBORDecodeValueError("expected byte string in typed array") return np.frombuffer(tag.value, dtype=dtype) def decode_dectris_compression(tag): algorithm, elem_size, encoded = tag.value return decompress(encoded, algorithm, elem_size=elem_size) tag_decoders = { 40: lambda tag: decode_multi_dim_array(tag, column_major=False), 64: lambda tag: decode_typed_array(tag, dtype="u1"), 65: lambda tag: decode_typed_array(tag, dtype=">u2"), 66: lambda tag: decode_typed_array(tag, dtype=">u4"), 67: lambda tag: decode_typed_array(tag, dtype=">u8"), 68: lambda tag: decode_typed_array(tag, dtype="u1"), 69: lambda tag: decode_typed_array(tag, dtype="