No project description provided
Project description
LiberTEM-dectris-rs
This is a Python package for efficiently receiving data from DECTRIS detectors with the zeromq interface. The low-level, high-frequency operations are performed in a background thread implemented in rust, and multiple frames are batched together for further processing in Python.
Usage
import numpy as np
import libertem_dectris
from libertem_live.detectors.dectris.DEigerClient import DEigerClient
# trigger acquisition via the REST API, needs `libertem-live`
nimages = 256 * 256
ec = DEigerClient('localhost', 8910) # hostname and port of the DCU REST API
ec.setDetectorConfig('ntrigger', 1)
ec.setDetectorConfig('nimages', 1)
ec.setDetectorConfig('trigger_mode', 'exte')
ec.setDetectorConfig('ntrigger', nimages)
result = ec.sendDetectorCommand('arm')
sequence_id = result['sequence id']
conn = libertem_dectris.DectrisConnection(
uri="tcp://localhost:9999",
handle_path="/tmp/dectris_shm",
frame_stack_size=32,
num_slots=2000,
bytes_per_frame=512*512,
huge=False,
)
# as we have armed the detector above, we know the sequence number
# that we should expect:
# (in other cases, can also call
# `conn.start_passive` and `conn.wait_for_arm` to passively wait for
# the detector to be armed)
conn.start(sequence_id)
# any other process can use a `CamClient` to use data
# stored in the SHM:
cam_client = libertem_dectris.CamClient(conn.get_socket_path())
try:
while True:
# get at most `max_size` frames as a stack
# (might get less at the end of the acquisition)
stack_handle = conn.get_next_stack(max_size=32)
# if the receiver is idle, stack_handle will be None here:
if stack_handle is None:
break
# the expected shape and data type:
frame_shape = tuple(reversed(stack_handle.get_shape()))
dtype = np.dtype(stack_handle.get_pixel_type()).newbyteorder(
stack_handle.get_endianess()
)
# pre-allocate some memory for the pixel data:
# (would be pulled out of the loop in real code)
buf = np.zeros((len(stack_handle),) + frame_shape, dtype=dtype)
# decompress into the pre-allocated buffer
cam_client.decompress_frame_stack(stack_handle, out=buf)
# free up the shared memory slot for this frame stack:
cam_client.done(stack_handle)
# we can still use the decompressed data:
buf.sum()
finally:
conn.close() # clean up background thread etc.
cam_client.close()
Changelog
v0.2.10
- Add functionality to generate mock data for sending via the simulator
- Add missing numpy dependency
- Make debug output a bit more reliable
v0.2.9
- Add more debug and trace output
v0.2.7
- Log more details in
DectrisConnection.log_shm_stats
and change log level toINFO
- Increase timeout for sending headers and frames
v0.2.4 - v0.2.6
- Updated examples and CI configuration
v0.2.3
- Add
env_logger
: set environment variableLIBERTEM_DECTRIS_LOG_LEVEL
to e.g.'INFO'
to enable logging - Improved error handling: raise an exception instead of panicing on serialization errors
- Ignore messages with mismatching series ID
- Add explicit checks for the correct
header_detail
levels - Move code into monorepo
v0.2.2
- Vendor
bitshuffle
and addFrame.decompress_into
method, PR #10
v0.2.1
- Catch frame ID mismatch, PR #9
v0.2.0
- Added
libertem_dectris.headers
submodule that exports header classes - Added ways to create
libertem_dectris.Frame
andlibertem_dectris.FrameStack
objects from Python, mostly useful for testing - Added binding to random port for the simulator
- Properly parametrize with zmq endpoint URI
- Fix many clippy complaints
v0.1.0
Initial release!
Development
This package is using pyo3 with
maturin to create the Python bindings. First, make sure
maturin
is installed in your Python environment:
(venv) $ pip install maturin
Then, after each change to the rust code, run maturin develop -r
to build and
install a new version of the wheel.
As we vendor bitshuffle
, make sure to clone with git clone --recursive ...
, or manually
take care of initializing and updating submodules.
Release
- update changelog above
- bump version in Cargo.toml if not already bumped, and push
- create a release from the GitHub UI, creating a new tag vX.Y.Z
- done!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for libertem_dectris-0.2.11-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72cbaf1cf6157745bcc27f18fc24d2bd279f8e062f1a2ed953bb11d82ed7691c |
|
MD5 | aea3624d910f6d17c7629d9d46e9a484 |
|
BLAKE2b-256 | c1fd5fef85a72c014c51d89f51153fcc18c302e63ed5661fa87bcaa9ac0b4f3f |
Hashes for libertem_dectris-0.2.11-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a13d2bf056451cd73fb77159c2bb7a8aae05994ba553256824b5a792e4202c1 |
|
MD5 | fdaa56ecde4c2b6f2bfe5cc501609625 |
|
BLAKE2b-256 | 820eee16d0aacc84f3c847001cc9431d4432195cd4a4bc6d952be9f464044820 |
Hashes for libertem_dectris-0.2.11-cp37-abi3-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc1fab044258ec90e77549852de840fa63e010dcbe84ffbf37e42eb6f657d278 |
|
MD5 | 4ca689e8c7f0fcb53456fafb0deb4444 |
|
BLAKE2b-256 | 68e6ad2c6d41a35dded57098f0a9aa01ad59c4d877b7c48479fe8b05618a8ce4 |
Hashes for libertem_dectris-0.2.11-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 633746dec4fbbe98a0c28843c6159d17e760c3845b253dbcd4c054fcd7d058ad |
|
MD5 | 80188a922a839fa87cb035c4d96c12dd |
|
BLAKE2b-256 | d46e50ae5bd7a2810fec308cbdd2efa23b732376e1de4edca7cd830335c2989b |