Skip to main content

guarneri

Project description

https://img.shields.io/pypi/v/guarneri.svg

A package for creating Ophyd and Ophyd-async devices from configuration files.

Instead of instantiating devices directly in python, Guarneri reads a configuration file and creates/connects the devices for you. This provides the following benefits:

  1. Beamline configuration is in a human-readable configuration file (e.g. TOML).

  2. Other tools can modify the configuration file if needed.

  3. Devices can be connected in parallel (faster).

  4. Missing devices are handled gracefully.

  5. Devices can be simulated/mocked by changing a single value in the config file.

Usage

Let’s say you have some ophyd and ophyd-async devices defined (with type hints) in a file called devices.py. This is not specific to guarneri, just regular Ophyd.

from ophyd_async.epics import epics_signal_rw
from ophyd_async.core import AsyncDevice
from ophyd import Device, Component

from guarneri import Instrument

class MyDevice(Device):
    description = Component(".DESC")


class MyAsyncDevice(AsyncDevice):
    def __init__(self, prefix: str, name: str = ""):
        self.description = epics_signal_rw(str, f"{prefix}.DESC")
    super().__init__(name=name)


def area_detector_factory(hdf: bool=True):
    # Create devices here using the arguments
    area_detector = ...
    return area_detector

Instead of instantiating these in a python startup script, Guarneri will let you create devices from a TOML configuration file. First we create a TOML file (e.g. instrument.toml) with the necessary parameters, these map directly onto the arguments of the device’s __init__(), or the arguments of a factory that returns a device.

[[ my_device ]]
name = "device1"
prefix = '255id:'

[[ async_device ]]
name = "device3"
prefix = '255id:'

[[ area_detector ]]
name = "sim_det"
hdf = true

Then in your beamline startup code, create a Guarneri instrument and load the config files.

from io import StringIO

from guarneri import Instrument

from devices import MyDevice, MyAsyncDevice, area_detector_factory

# Prepare the instrument device
instrument = Instrument({
    "my_device": MyDevice,
    "async_device": MyAsyncDevice,
    "area_detector": area_detector_factory,
})

# Create the devices from the TOML configuration file
instrument.load_config_files("instrument.toml")
# Optionally connect all the devices
await instrument.connect()

# Now use the devices for science!
instrument.devices['device_1'].description.get()

The first argument to guarneri.Instrument.__init__() is a mapping of TOML section names to device classes. Guarneri then introspects the device or factory to decide which TOML keys and types are valid. In the above example, the heading [my_device.device1] will create an instance of MyDevice() with the name "device1" and prefix "255id:". This is equivalent to MyDevice(prefix="255id:", name="device1").

What About Happi?

Happi has a similar goal to Guarneri, but with a different scope. While Happi is meant for facility-level configuration (e.g. LCLS), Guarneri is aimed at individual beamlines at a synchrotron. Happi uses HappiItem classes with ItemInfo objects to describe the devices definitions, while Guarneri uses the device classes themselves. Happi provides a python client for adding and modifying the devices, while Guarneri uses human-readable configuration files.

Which one is better? Depends on what you’re trying to do. If you want a flexible and scalable system that shares devices across a facility, try Happi. If you want a way to get devices running quickly on your beamline before users show up, try Guarneri.

Documentation

Sphinx-generated documentation for this project can be found here: https://spc-group.github.io/guarneri/

Requirements

Describe the project requirements (i.e. Python version, packages and how to install them)

Installation

The following will download the package and load it into the python environment.

pip install guarneri

For development of guarneri, install as an editable project with all development dependencies using:

git clone https://github.com/spc-group/guarneri
pip install -e ".[dev]"

Running the Tests

$ pip install -e .
$ pytest -vv

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

guarneri-0.3.0rc0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

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

guarneri-0.3.0rc0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file guarneri-0.3.0rc0.tar.gz.

File metadata

  • Download URL: guarneri-0.3.0rc0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for guarneri-0.3.0rc0.tar.gz
Algorithm Hash digest
SHA256 3890bffe0c14a24d92ac438b765d06d6bd6ac2290e74c2d4c461db28335bc48f
MD5 0ed9eb3f3aa8cc7e299075b8bc070398
BLAKE2b-256 b72a793edc65b3979eca3d5cb552e05e727fa7a27b75dbb938bd57e88844d42e

See more details on using hashes here.

File details

Details for the file guarneri-0.3.0rc0-py3-none-any.whl.

File metadata

  • Download URL: guarneri-0.3.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for guarneri-0.3.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe54f8f75d05d9f118b6cff89ab66ffac30d55b5787b34b14a4a0c5213363b14
MD5 0b552ac5becdd7f10ecbc795fe81d361
BLAKE2b-256 54400da1aeb9923a6b661af06621a16a266a0e945be8a5c8703b8fbadeebea0a

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