A simulated Dectris Simplon API. Aims to have the same RESTlike interface and produce a ZMQ stream of data from an input Hdf5 file.
Supports both Stream V2 and Legacy ZMQ stream formats.
You can build and run the app by simply running:
docker compose up --detachThe app's behavior can be optionally modified by setting environment variables in the
docker-compose.yml file
The following environment variables can be configured:
-
AS_DELAY_BETWEEN_FRAMES: Specifies the delay between frames in seconds (default: 0.01 s). This number can be modified during runtime via the/ansto_endpoints/delay_between_framesendpoint. -
AS_NUMBER_OF_DATA_FILES: Sets the number of data files from the master file loaded into memory (default: 1). This can be updated when loading a new master file via the/ansto_endpoints/hdf5_master_file endpoint. -
AS_HDF5_MASTER_FILE: The absolute path to an HDF5 master file. If unset, the project's default master file is used. You can switch master files at runtime via the/ansto_endpoints/hdf5_master_fileendpoint. -
AS_FRAME_SOURCE: Sets the initial frame source at startup. Allowed values arehdf5anddynamic-frame(default:hdf5). IfAS_DYNAMIC_FRAME_ENABLED=false, adynamic-framevalue is coerced tohdf5with a warning. -
AS_DYNAMIC_FRAME_ENABLED: Controls whether dynamic-frame routes are exposed (default:false). If set totrue,pyFAImust be installed or the app fails at startup.
Example docker-compose configuration for dynamic-frame mode.
Note: for Docker, setting AS_DYNAMIC_FRAME_ENABLED=true is not enough by itself.
You must also build the image with the optional dependency extra:
UV_SYNC_EXTRA="--extra dynamic-frame".
services:
ansto_simplon_api:
build:
dockerfile: Dockerfile
args:
UV_SYNC_EXTRA: "--extra dynamic-frame"
environment:
- AS_DYNAMIC_FRAME_ENABLED=true
- AS_FRAME_SOURCE=dynamic-frameFollow these steps to run the app locally:
-
Install the Library
This repository uses UV.
To install the dependencies run
uv syncNote: For Ubuntu users, additionally install the following packagesapt update apt-get install -y gcc libhdf5-serial-dev
For other operating systems, Install the equivalent libraries for
gccandlibhdf5-serial-dev.The same environment variables described in the
dockersection can be updated if necessary. -
Run the FAST-API application
uvicorn ansto_simplon_api.main:app
Once the simulated SIMPLON API is up and running, you can verify its functionality by:
- Starting the ZMQ Consumer
python examples/cbor_stream/receiver.py- Triggering the detector
You can arm, trigger, and disarm the detector using the following script:
python examples/cbor_stream/trigger_detector.pyAfter running this script, you should see messages being received by the receiver.py
script.
Legacy ZMQ stream examples can be found in the examples/legacy_stream/ folder.
This project can optionally stream generated ring images (pyFAI LaB6 calibrant) instead of HDF5-backed static images.
- Install optional dependency:
uv sync --extra dynamic-frame
- For Docker builds, see the dynamic-frame docker-compose example above
(includes
UV_SYNC_EXTRA="--extra dynamic-frame"). - Dynamic-frame enablement and startup behavior are described in the Docker/config section above.
- Dynamic-frame source is supported only for
cborstream format.
- Set stream format to CBOR:
PUT /stream/api/1.8.0/config/formatwith{ "value": "cbor" }
- Switch frame source to dynamic-frame:
PUT /ansto_endpoints/dynamic_frame/sourcewith{ "value": "dynamic-frame" }
- Change one or more detector geometry values below and trigger acquisition.
These endpoints update metadata used by the dynamic image generator:
- Beam center X:
PUT /detector/api/1.8.0/config/beam_center_x
- Beam center Y:
PUT /detector/api/1.8.0/config/beam_center_y
- Detector distance:
PUT /detector/api/1.8.0/config/detector_distance
- Detector description (changes pyFAI detector selection):
PUT /detector/api/1.8.0/config/description
- Pixel sizes:
PUT /detector/api/1.8.0/config/x_pixel_sizePUT /detector/api/1.8.0/config/y_pixel_size
- Image size:
PUT /detector/api/1.8.0/config/x_pixels_in_detectorPUT /detector/api/1.8.0/config/y_pixels_in_detector
- Compression (forces dynamic-frame cache refresh):
PUT /detector/api/1.8.0/config/compression
- Dynamic frames are cached and regenerated when key parameters change.
- Cache key currently includes: incident wavelength, beam center X/Y, detector distance, image size X/Y, image dtype, detector description, and compression.
incident_wavelengthandimage_dtypeare currently not directly exposed as dedicated REST endpoints in this API.PUT /detector/api/1.8.0/config/photon_energyupdates bothincident_energyandincident_wavelengthused by dynamic-frame generation.- Source switching endpoint:
PUT /ansto_endpoints/dynamic_frame/sourcewith{ "value": "dynamic-frame" }PUT /ansto_endpoints/dynamic_frame/sourcewith{ "value": "hdf5" }
You can see the endpoints currently implemented by accessing the interactive API documentation at http://localhost:8000/swagger. Ensure that the simulated SIMPLON API is up and running to access the documentation.