Skip to main content

Send McCode generated histograms to a Kafka server as da00 messages

Project description

McCode to Kafka monitor data converter

Convert McCode style monitor output files to FlatBuffer histograms for Kafka.

Background

McStas

McStas is one of the Monte Carlo ray tracing suites of McCode. It is used to simulate neutron scattering instruments and experiments. McStas can output monitor data in a text format that can be reformulated for transmission to Kafka.

The monitor data format contains a header, comprised of simulation parameters and metadata, and then either a number-of-dependent-variables (N) plus 1 by number of independent-variable-observations (M) 2D array in the case of one independent-variable; or N times M by L arrays in the case of two independent variables, where the second independent-variable has L observations. The dependent variables always include I, I_err, and N, from which the simulated cross section can be calculated as I/N and its uncertainty as I_err/N for each observation.

FlatBuffers

The European Spallation Source (ESS) data acquisition system uses FlatBuffers for data serialization. The exact schema used by ESS are part of the streaming-data-types library, exposed to python via ess-streaming-data-types.

One of the types defined in the streaming-data-types library, da00, can be used to represent related datasets, including histograms and their axes. This module can encode McStas histograms as da00 messages and send them to a Kafka stream. The histograms can then be retrieved by a kafka-to-nexus file writer for inclusion in a NeXus data file.

Motivation

The motivation for this project is to be able to use the McStas simulation output directly in the ESS data acquisition system, without having to keep track of monitor files in addition to the produced NeXus file.

This will enable storing beam-monitor data in the same file as the simulated event data, even in cases where the beam-monitor data is not available from the running simulation because it was produced in an earlier saved-run. E.g., in the case of a MCPL saved primary-spectrometer simulation, the beam-monitor data is not available during later simulations of the sample and secondary-spectrometer, but is required for the final data reduction.

Usage

The mccode-to-kafka script is used to convert McStas monitor files to FlatBuffer histograms and send them to Kafka. It is intended to be used as a command-line tool, but can also be used as a python module.

$ mccode-to-kafka --help
usage: mccode-to-kafka [-h] [-n NAME [NAME ...]] [--source SOURCE] [--broker BROKER] root

Send histograms to Kafka

positional arguments:
  root                  The root directory or file to send

options:
  -h, --help            show this help message and exit
  -n NAME [NAME ...], --name NAME [NAME ...]
                        The names of the histograms to send
  --source SOURCE       The source name to use
  --broker BROKER       The broker to send to

Expected usage is to specify the root directory of the McStas simulation output, and the names of the histograms to send. The names of the histograms are the names of the monitor files, without the .dat extension.

$ mccode-to-kafka -n monitor0 monitor1 --broker localhost:9092 /path/to/simulation/output

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

mccode_to_kafka-0.3.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

mccode_to_kafka-0.3.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file mccode_to_kafka-0.3.1.tar.gz.

File metadata

  • Download URL: mccode_to_kafka-0.3.1.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mccode_to_kafka-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cf6a9dad37d24c2fbe0c55a0bd61571dbaf675ced9a2c4675329c463a6062239
MD5 f92f0c9553f6fa1b6945310861af03f5
BLAKE2b-256 fe2b801c19aebdde421e91f105ffa598482084a8098f8c0ddd05ee9c929fd100

See more details on using hashes here.

Provenance

The following attestation bundles were made for mccode_to_kafka-0.3.1.tar.gz:

Publisher: wheels.yml on g5t/mccode-to-kafka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mccode_to_kafka-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mccode_to_kafka-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52fdbca3471652a1019aa10c9c7ecc535a8e351691c88565b2a2048bbb9494c6
MD5 2c970c931889b03bc90d73eb51a7a50a
BLAKE2b-256 b84b05b2374876e4a5528e71e5c80c7559791019c37a47bf9753630fffe6bd57

See more details on using hashes here.

Provenance

The following attestation bundles were made for mccode_to_kafka-0.3.1-py3-none-any.whl:

Publisher: wheels.yml on g5t/mccode-to-kafka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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