This is a live view for data produced by Bluesky in the so called Documents and streamed via Kafka.
Project description
In order to use it, you’ll need to have an acessible Kafka Topic that you can publish your data. You will need to deploy Kafka in your PC and create this topic. If you are running this from a beamline configured GUI, the topic is probably already create and will be called <BL>_bluesky, (EMA_bluesky for instance). There a really easy-to-follow tutorial about Kafka Here.
After setting up Kafka and the topic that you will stream to, you will need a callback to subscribe to RunEngine and stream the run generated Documents, it is a simple callback:
from kafka import KafkaProducer import msgpack producer = KafkaProducer() def kafka_callback(name: str, doc: dict) -> None: """Callback to stream Bluesky Documents via Kafka""" producer = KafkaProducer(value_serializer=msgpack.dumps) producer.send(<kafkja_topic>, (name, doc))
Notice that you will need to install kafka-python and msgpack.
After the definition of the callback, subscribe it to Bluesky RunEngine:
from bluesky import RunEngine RE = RunEngine() kafka_callback_token = RE.subscribe(kafka_callback)
With this done, you can now launch kafka-bluesky-live, start a the run and see the data being plotted live.
First, install this project:
git clone https://gitlab.cnpem.br/SOL/bluesky/kafka-bluesky-live pip install kafka-bluesky-live
Then, run the in the terminal, run the following command:
kbl <kafka_topic_name>
With the interface already opened, start a run in Bluesky to see it being plotted live.
There are some special information that can be passed to kafka-bluesky-live via scan metadata that will change some of its behaviours. You can choose what scan motor that will be in the x-axis, set the counter that is going to be shown in the first tab and set the name that will identify the current run. This is all done by the special metada, they are: “file_name”, “main_motor” and “main_counter”.
To input then to the current run you must add them as a metadata for that run, there are several ways that this can be done, for example defining a dict and inputing it to the RunEngine afterwards:
md = {"file_name": "my_awesome_file", "main_motor": "motor2", "main_counter": "counter_5"} RunEngine(scan([counter_1, counter_2, counter_5], motor1, -1, 1, motor2, -5, 5, 100), **md)
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
kafka-bluesky-live-0.0.1.tar.gz
(118.1 kB
view details)
Built Distribution
File details
Details for the file kafka-bluesky-live-0.0.1.tar.gz
.
File metadata
- Download URL: kafka-bluesky-live-0.0.1.tar.gz
- Upload date:
- Size: 118.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe54d8286b25db683e4430e75a3df4af5f5ecd21f305ca8104a7bf5d95707668 |
|
MD5 | a6d0d5e28b97000be2b8aa79dc6182f7 |
|
BLAKE2b-256 | 42bc7af2943e122c8803279d2955f137cc611b5ebd993d697894b7c9ece30cdc |
File details
Details for the file kafka_bluesky_live-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: kafka_bluesky_live-0.0.1-py3-none-any.whl
- Upload date:
- Size: 117.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a9110bac7c762cff7c7e4f4c1f3d75945143e137cd4e85210fc5f08fe20e14 |
|
MD5 | a74be7c9ff718d7bca112451e501b8ac |
|
BLAKE2b-256 | d20964f855a4da7193d530a609f625f4f765a1de07cc05e7a0f0fee6dff6d7fd |