Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DECTRIS support; use PipelinedExecutor for live processing #51

Merged
merged 83 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
50a6dec
WIP: dectris support
sk1p May 9, 2022
ddd5500
Real Dectris interface code
uellue May 9, 2022
c24ea05
Record and replay ZMQ messages
uellue May 10, 2022
61c56d3
Derive `nimages` from `aq.shape.nav`
sk1p May 10, 2022
3136e0d
Misc. dectris improvements
sk1p May 11, 2022
0f529cf
Drive-by: remove code duplication
uellue May 11, 2022
29a7c0a
Remove unused import
uellue May 11, 2022
d69f59b
Add bitshuffle dependency
uellue May 11, 2022
b9aa50d
Support uncompressed data and specify byte order
uellue May 11, 2022
8cbd7a9
Simulator for Dectris detector
uellue May 11, 2022
023b0f1
Allow co-existence of Dectris acquisition objects
uellue May 12, 2022
4e18717
Apply corrections
uellue May 12, 2022
9036f95
Allow reading excluded pixels from the detector
sk1p May 12, 2022
aad63b0
Fix reversed shape
sk1p May 12, 2022
f1d11ba
reset ntrigger and nframes to allow mode switch
uellue May 12, 2022
1728a3b
dectris sim: accept nimages/ntrigger==1, even if different from the file
sk1p May 12, 2022
fefe6d2
Allow enabling file writing
sk1p May 12, 2022
8126ad4
wip
sk1p May 16, 2022
d19a079
WIP: Working prototyp for multiprocessing-based executor
sk1p May 17, 2022
40c4b15
WIP
sk1p May 23, 2022
78ca481
Updates for pipelined executor
sk1p Jun 8, 2022
257b250
dectris: update for pipelined executor
sk1p Jun 9, 2022
ec960f9
WIP: update merlin to new API
sk1p Jun 23, 2022
348340d
Fixup for 359c5bd
sk1p Jun 23, 2022
da40ee0
Add example notebook for pipelined executor usage w/ merlin acq
sk1p Jun 29, 2022
d85ece0
Require current LiberTEM (0.10)
sk1p Jun 29, 2022
8891142
Try to fix version constraint
sk1p Jul 13, 2022
8982808
Rename: MainController -> TaskCommHandler
sk1p Jul 20, 2022
31dd7fa
merlin: simplify comparison test case
sk1p Jul 20, 2022
56ef8a8
Follow-up renaming: `get_controller` -> `get_task_comm_handler`
sk1p Jul 20, 2022
1eec10e
Allow running the Dectris simulator in pytest
uellue Jul 22, 2022
826409d
Mark as data test
uellue Jul 22, 2022
fd47000
Fix merlin tests to use `run_merlin_sim`; add flask
sk1p Jul 27, 2022
90fdaa4
Run most merlin tests in the PipelinedExecutor
sk1p Jul 27, 2022
84a63ef
Make the `OfflineReceiver` work again
sk1p Jul 28, 2022
d79b522
Depend on LiberTEM >= v0.10
sk1p Jul 28, 2022
ab035ad
It's not really a protocol...
sk1p Jul 28, 2022
6118026
Use PipelinedExecutor by default; add dectris to `prepare_acquisition`
sk1p Jul 28, 2022
0a87587
Update pipeline: add Python 3.10; `tox -r` for `numba_coverage`
sk1p Jul 28, 2022
2f7c209
More environment re-creation
sk1p Jul 28, 2022
c56db8c
Add missing DEigerClient
sk1p Jul 28, 2022
75f4efe
skip `test_sum` if dectris testdata is not available
sk1p Jul 28, 2022
8268426
docs: fix to close `LiveContext` after usage
sk1p Jul 28, 2022
75772c9
Move `ctx.close` to testcleanup block
sk1p Jul 28, 2022
e5f4e32
Make dectris dependencies optional
sk1p Aug 1, 2022
8fe94fa
Mark the memfd fixture Linux-only
sk1p Aug 1, 2022
f9a132a
More memfd stuff
sk1p Aug 1, 2022
0625285
ZMQReplay: fix type annotations for dectris
sk1p Aug 1, 2022
a474460
UDF for recording data
uellue Aug 1, 2022
8b8849b
Changelog, basic documentation and test
uellue Aug 1, 2022
72993da
Add tracing spans for trigger and LiveContext._do_acquisition
sk1p Aug 3, 2022
624821c
Add more tracing in DectrisAcquisition
sk1p Aug 3, 2022
1a3279b
tox.ini: install dectris extras; remove hdbscan
sk1p Aug 3, 2022
383d53b
detectors.merlin.data: cleanup; remove thread pool etc.
sk1p Aug 3, 2022
3cf67dd
Test case for a skipped frame
uellue Aug 4, 2022
22227ba
DECTRIS sim: send multipart messages; misc fixes
sk1p Aug 12, 2022
17e9a49
Use LiberTEM-dectris-rs
sk1p Aug 15, 2022
de1c860
merlin: fix for small partitions
sk1p Aug 15, 2022
ce2c0e9
Otel instrumentation for Eiger client
uellue Aug 15, 2022
201de86
Add optional dependency on LiberTEM-dectris
sk1p Aug 15, 2022
8c36640
Update to libertem_dectris>=0.2
sk1p Aug 16, 2022
ff200d9
Remove too recent f-string syntax
sk1p Aug 16, 2022
fc2090c
Require Python 3.7 for dectris support
sk1p Aug 16, 2022
2c7d2b8
Fix constraint syntax
sk1p Aug 16, 2022
a8d9000
Lazily import dectris dependencies
sk1p Aug 16, 2022
606996f
More lazy imports
sk1p Aug 16, 2022
761269d
Don't clobber the ctx_pipelined in test_frame_skip
sk1p Aug 16, 2022
9ede22d
Confirm positively that the executor survived the exception
uellue Aug 16, 2022
49adba0
dectris sim: fix for Python 3.6
sk1p Aug 17, 2022
e6b54f2
merlin: cleanup; `pool_size` is not used anymore
sk1p Aug 17, 2022
50bba77
Only run `test_frame_skip` on recent LiberTEM versions
sk1p Aug 17, 2022
f6abec7
sim: increase timeout; more lazy importing
sk1p Aug 17, 2022
5f32333
Add more tests for DectrisAcquisition
sk1p Aug 18, 2022
f2c6a83
Let docs-check have access to test data
sk1p Aug 18, 2022
6d09ba3
Improved documentation
sk1p Aug 18, 2022
549023f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2022
0e86c4b
Add dectris example notebook
sk1p Aug 18, 2022
eb274b9
Add changelog entries
sk1p Aug 18, 2022
312f456
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2022
2ff5fc0
Also run the DECTRIS simulator in the background
sk1p Aug 22, 2022
bb6da73
Update contributors and creators
uellue Aug 24, 2022
4389c70
Documentation and example review
uellue Aug 24, 2022
06dfcac
Fix copypasta
uellue Aug 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ data
.mypy_cache/
.benchmarks
junit.xml
profiles/
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ Detectors
---------

* `Quantum Detectors Merlin
<https://libertem.github.io/LiberTEM-live/reference.html#quantum-detectors-merlin>`_
<https://libertem.github.io/LiberTEM-live/detectors.html#merlin-detector>`_
* `DECTRIS EIGER2-based
<https://libertem.github.io/LiberTEM-live/detectors.html#dectris-detectors>`_

Support for the Gatan K2 IS is currently under development.
Support for the Gatan K2 IS and X-Spectrum cameras is currently under development.

License
-------
Expand Down
26 changes: 21 additions & 5 deletions azure-pipelines-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ stages:
Python36:
python.version: '3.6'
TOXENV: 'py36-data'
# 3.7: default in current Debian stable
Python37:
python.version: '3.7'
TOXENV: 'py37-data'
Expand All @@ -82,6 +81,9 @@ stages:
Python39:
python.version: '3.9'
TOXENV: 'py39-data'
Python310:
python.version: '3.10'
TOXENV: 'py310-data'
variables:
TESTDATA_BASE_PATH: '/data/'
steps:
Expand Down Expand Up @@ -133,6 +135,9 @@ stages:
Python39:
python.version: '3.9'
TOXENV: 'py39'
Python310:
python.version: '3.10'
TOXENV: 'py310'
variables:
TOXENV: '$(TOXENV)'
steps:
Expand All @@ -144,8 +149,13 @@ stages:
- bash: pip install -U tox
displayName: 'install requirements'

- bash: tox
displayName: 'Run tox tests $(TOXENV) $(Agent.OS)'
- ${{ if eq(parameters.recreate_tox, true) }}:
- bash: tox -r
displayName: 'Run tox tests $(TOXENV) $(Agent.OS) (recreating)'

- ${{ if eq(parameters.recreate_tox, false) }}:
- bash: tox
displayName: 'Run tox tests $(TOXENV) $(Agent.OS)'

- bash: bash <(curl -s https://codecov.io/bash) -f coverage.xml
displayName: 'Submit coverage to codecov.io'
Expand All @@ -169,8 +179,13 @@ stages:
- bash: pip install -U tox
displayName: 'install requirements'

- bash: tox
displayName: 'Run tox tests $(TOXENV) $(Agent.OS)'
- ${{ if eq(parameters.recreate_tox, true) }}:
- bash: tox -r
displayName: 'Run tox tests $(TOXENV) $(Agent.OS) (recreating)'

- ${{ if eq(parameters.recreate_tox, false) }}:
- bash: tox
displayName: 'Run tox tests $(TOXENV) $(Agent.OS)'

- bash: bash <(curl -s https://codecov.io/bash) -f coverage.xml
displayName: 'Submit coverage to codecov.io'
Expand All @@ -189,6 +204,7 @@ stages:
TOXENV: 'docs-check'
variables:
TOXENV: '$(TOXENV)'
TESTDATA_BASE_PATH: '/data/'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.9'
Expand Down
20 changes: 14 additions & 6 deletions ci/run-with-sim.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#!/bin/bash
# run both nbval and libertem-live-mib-sim
# assumes default ports are usable (i.e. isolated environment)

.tox/notebooks/bin/libertem-live-mib-sim --host 127.0.0.1 "$TESTDATA_BASE_PATH/20200518 165148/default.hdr" --cached=MEMFD --wait-trigger&
SIM_PID=$!
MERLIN_SIM_PID=$!

.tox/notebooks/bin/libertem-live-dectris-sim "$TESTDATA_BASE_PATH/dectris/zmqdump.dat.128x128-id34-exte-bslz4" --port 8910 --zmqport 9999&
DECTRIS_SIM_PID=$!

cleanup() {
kill "$SIM_PID"
kill "$MERLIN_SIM_PID"
kill "$DECTRIS_SIM_PID"
}

trap cleanup EXIT

echo "started simulator in background, pid=$SIM_PID"
echo "waiting for data socket to be ready..."
echo "started merlin simulator in background, pid=$MERLIN_SIM_PID"
echo "started dectris simulator in background, pid=$DECTRIS_SIM_PID"
echo "waiting for data sockets to be ready..."

while ! (echo "" > /dev/tcp/127.0.0.1/6342) 2>/dev/null; do echo "Waiting..."; sleep 1; done
while ! (echo "" > /dev/tcp/127.0.0.1/6342) 2>/dev/null; do echo "Waiting for 6342..."; sleep 1; done
while ! (echo "" > /dev/tcp/127.0.0.1/8910) 2>/dev/null; do echo "Waiting for 8910..."; sleep 1; done
while ! (echo "" > /dev/tcp/127.0.0.1/9999) 2>/dev/null; do echo "Waiting for 9999..."; sleep 1; done

echo "done waiting, data socket ready!"
echo "done waiting, sockets ready!"

"$@"
12 changes: 12 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
in both doctests and regular tests.
"""
from libertem.executor.inline import InlineJobExecutor
from libertem.executor.pipelined import PipelinedExecutor
import pytest

from libertem.viz.base import Dummy2DPlot
Expand All @@ -23,6 +24,17 @@ def ltl_ctx_fast():
return ltl.LiveContext(executor=inline_executor, plot_class=Dummy2DPlot)


@pytest.fixture(scope="session")
def ctx_pipelined():
executor = None
try:
executor = PipelinedExecutor()
yield ltl.LiveContext(executor=executor, plot_class=Dummy2DPlot)
finally:
if executor is not None:
executor.close()


@pytest.fixture()
def default_aq(ltl_ctx):
return ltl_ctx.prepare_acquisition('memory', trigger=None, datashape=[16, 16, 32, 32])
Expand Down
3 changes: 3 additions & 0 deletions docs/source/changelog/features/dectris.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Feature] Support for DECTRIS detectors
=======================================
* Initial support for DECTRIS detectors, including QUADRO and ARINA (:pr:`51`).
4 changes: 4 additions & 0 deletions docs/source/changelog/features/pipelined.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Feature] Parallel pipelined processing
=======================================
* Scalability improvements - now uses the pipelined executor added in LiberTEM
0.10 for parallel processing (:pr:`51`).
4 changes: 4 additions & 0 deletions docs/source/changelog/features/record.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Feature] Data recording
========================

* :ref:`recording` with :class:`~libertem_live.udf.record.RecordUDF` (:pr:`51`).
26 changes: 22 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'nbsphinx_link',
'IPython.sphinxext.ipython_console_highlighting',
'sphinx_issues',
'sphinx_rtd_theme',
]

bibtex_bibfiles = ['references-libertem_live.bib']
Expand All @@ -87,7 +88,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -103,7 +104,9 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

html_logo = '_static/logo.png'

html_favicon = '../../corporatedesign/logo/favicon.ico'

Expand All @@ -112,7 +115,6 @@
# documentation.
#
html_theme_options = {
'logo': 'logo.png'
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down Expand Up @@ -207,7 +209,7 @@

intersphinx_mapping = {
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'python': ('https://docs.python.org/3.7', None),
'python': ('https://docs.python.org/3.10', None),
'libertem': ('https://libertem.github.io/LiberTEM/', None),
}

Expand All @@ -220,3 +222,19 @@
# Freezes the link checker for unknown reasons within CI, hard to reproduce
r'http://quantumdetectors.com/wp-content/uploads/2017/01/1532-Merlin-for-EM-Technical-Datasheet-v2.pdf', # NOQA:E501
]

doctest_global_setup = '''
import os
def get_testdata_path():
return os.environ.get(
'TESTDATA_BASE_PATH',
os.path.normpath(
os.path.join(os.getcwd(), 'data')
)
)
DECTRIS_TESTDATA_PATH = os.path.join(
get_testdata_path(),
'dectris', 'zmqdump.dat.128x128-id34-exte-bslz4'
)
HAVE_DECTRIS_TESTDATA = os.path.exists(DECTRIS_TESTDATA_PATH)
'''
149 changes: 149 additions & 0 deletions docs/source/detectors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
Supported Detectors
===================

.. _`dectris detectors`:

DECTRIS EIGER2-based
--------------------

.. versionadded:: 0.2

LiberTEM-live has support for all DECTRIS detectors that support
the `SIMPLON API <https://media.dectris.com/210607-DECTRIS-SIMPLON-API-Manual_EIGER2-chip-based_detectros.pdf>`_,
including QUADRO and ARINA.

.. note::
Python 3.7+ is required to use the DECTRIS-related features of
LiberTEM-live, and we recommend to use Python 3.10. Currently, Windows and
Linux on x86_64 are supported.

Installation
............

There are a few extra dependencies needed for DECTRIS support. You can easily
install them using:

.. code-block:: shell

(libertem) $ python -m pip install "libertem-live[dectris]"

Currently, at least LiberTEM 0.10 is required. Using LiberTEM master is
recommended until a number of stability fixes for the pipelined executor are
released in LiberTEM.

Usage example
.............

.. testsetup::
:skipif: not HAVE_DECTRIS_TESTDATA

from libertem_live.detectors.dectris.sim import DectrisSim
server = DectrisSim(path=DECTRIS_TESTDATA_PATH, port=0, zmqport=0, verbose=False)
server.start()
server.wait_for_listen()
DCU_API_PORT = server.port
DCU_DATA_PORT = server.zmqport

.. testoutput::
:hide:

RustedReplay listening on tcp://127.0.0.1:...
Waiting for arm

.. testcode::
:skipif: not HAVE_DECTRIS_TESTDATA

from libertem.executor.pipelined import PipelinedExecutor
from libertem.viz.bqp import BQLive2DPlot
from libertem_live.api import LiveContext
from libertem.udf.sum import SumUDF

executor = PipelinedExecutor(spec=PipelinedExecutor.make_spec(cpus=range(10), cudas=[]))
ctx = LiveContext(executor=executor, plot_class=BQLive2DPlot)

def trigger(aq):
"""
You can trigger the scan here, if you have a microscope control API
"""
# you can imagine something like:
# trigger_scan(shape=tuple(aq.shape.nav), dwelltime=67e-6)
pass

# prepare for acquisition, setting up scan parameters etc.
aq = ctx.prepare_acquisition(
'dectris',
api_host="127.0.0.1",
api_port=DCU_API_PORT,
data_host="127.0.0.1",
data_port=DCU_DATA_PORT,
nav_shape=(128, 128),
trigger_mode="exte",
trigger=trigger,
frames_per_partition=512,
)

# run one or more UDFs on the live data stream:
# (this can be run multiple times on the same `aq` object)
ctx.run_udf(dataset=aq, udf=SumUDF(), plots=True)

.. testoutput::
:hide:

...

.. testcleanup::
:skipif: not HAVE_DECTRIS_TESTDATA

ctx.close()
server.stop()
server.maybe_raise()

See the :ref:`DECTRIS reference section <dectris reference>` for a description of
the acquisition parameters.

.. _`merlin detector`:

Quantum Detectors Merlin
------------------------

No extra dependencies are needed for using Merlin detectors.

Supported are currently 1 bit, 6 bit and 12 bit :code:`COUNTERDEPTH` for both the "binary"
(:code:`FILEFORMAT 0`) and the "raw binary" format (:code:`FILEFORMAT 2`).

For testing, an acquisition with soft trigger (:code:`TRIGGERSTART 5`) is
recommended since internal trigger (:code:`TRIGGERSTART 0`) may cause issues
with finding the beginning of the data stream. For a real STEM acquisition a
hardware trigger setup that matches the given instrument is required. See the
MerlinEM User Manual from Quantum Detectors for details!

A simple simulator for testing live acquisition without the actual hardware is
included in LiberTEM-live. It replays an MIB dataset and accepts the following
parameters:

.. code-block:: shell

(libertem) $ libertem-live-mib-sim --help
Usage: libertem-live-mib-sim [OPTIONS] PATH

Options:
--nav-shape <INTEGER INTEGER>...
--continuous
--cached [NONE|MEM|MEMFD]
--host TEXT Address to listen on (data, control, and
trigger sockets)
--data-port INTEGER
--control-port INTEGER
--wait-trigger Wait for a SOFTTRIGGER command on the
control port, or a trigger signal on the
trigger socket
--garbage Send garbage before trigger. Implies --wait-
trigger
--max-runs INTEGER
--help Show this message and exit.

A suitable MIB dataset for testing can be downloaded at
https://zenodo.org/record/5113449.

See the :ref:`Merlin reference section <merlin reference>` for a description of
the acquisition parameters.
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Documentation
:caption: Contents:

usage
detectors
reference
changelog
acknowledgments
reference


Indices and tables
------------------
Expand Down
Loading