Skip to main content

No project description provided

Project description

LiberTEM-dectris-rs

LiberTEM-dectris-rs on GitHub

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 libertem_dectris
from libertem_live.detectors.dectris.DEigerClient import DEigerClient

# trigger acquisition via the REST API, needs `libertem-live`
nimages = 512 * 512
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'] 

frames = libertem_dectris.FrameChunkedIterator(uri="tcp://localhost:9999")
# start to receive data for the given series
# (can be called multiple times on the same `FrameChunkedIterator` instance)
frames.start(series=sequence_id)

try:
    while True:
        # get at most `max_size` frames as a stack
        # (might get less at the end of the acquisition)
        stack = frames.get_next_stack(max_size=32)
        for i in range(len(stack)):
            frame = stack[i]
            image_data_bytes = frame.get_image_data()  # this is the raw data
            shape = frame.get_shape()
            pixel_type = frame.get_pixel_type()  # uint8 etc.
            endianess = frame.get_endianess()  # in numpy notation; ">" or "<"
            dtype = endianess + pixel_type
            encoding = frame.get_encoding()
            frame_id = frame.get_frame_id()
            decompressed = np.zeros(shape, dtype=dtype)
            frame.decompress_into(decompressed)
            # `decompressed` now contains the array data for this frame:
            decompressed.sum()
        if len(stack) == 0:
            break
finally:
    frames.close()  # clean up background thread etc.

Changelog

v0.2.2

  • Vendor bitshuffle and add Frame.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 and libertem_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libertem_dectris-0.2.2.tar.gz (2.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libertem_dectris-0.2.2-cp37-abi3-win_amd64.whl (507.1 kB view details)

Uploaded CPython 3.7+Windows x86-64

libertem_dectris-0.2.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

libertem_dectris-0.2.2-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.4 MB view details)

Uploaded CPython 3.7+macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

File details

Details for the file libertem_dectris-0.2.2.tar.gz.

File metadata

  • Download URL: libertem_dectris-0.2.2.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.7

File hashes

Hashes for libertem_dectris-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cc1d8bd7ca1cb13864ec86acc3639bb948e3ebbf4fc40040fb2174ee4a186269
MD5 69e876994f3a24761adffba47883d559
BLAKE2b-256 2a9c533db94fe54731417cf618c9c3d69a620b4b9c9416355462dbc2b07d3451

See more details on using hashes here.

File details

Details for the file libertem_dectris-0.2.2-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for libertem_dectris-0.2.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2517b4307c054ba0eadbb6c7071cc73c273a7eb9f313e7f90162e08426f00d5d
MD5 bc76169b57ae9cd9f4097b32eac4c0bd
BLAKE2b-256 7ddf81482158796631b06c3919ebc8da5190338632a777893717cf085677662e

See more details on using hashes here.

File details

Details for the file libertem_dectris-0.2.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for libertem_dectris-0.2.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e5625456d19d441a57364c2bb4f010b4bc8c6a9be34a44915f45b5f986d79e1
MD5 0279e9a614f8442e06dfbce23923a66c
BLAKE2b-256 c6f7617a45024054846bf72477f44f5c1f8ab98f071817b3c664a18a4c7b5d81

See more details on using hashes here.

File details

Details for the file libertem_dectris-0.2.2-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for libertem_dectris-0.2.2-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 172092afdde35c6acde8a97bfa8ae066823cd66f4cfd921570647669094553ac
MD5 283be926952d525d0f506e8e3fcc007d
BLAKE2b-256 239a255da29d4959f7d05f04bfb91ee0a2e52011ca1b7fdd3b72b5a6f40e37c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page