devices#

Import: hklpy2.devices

Ophyd device construction helpers for hklpy2.

These utilities are called during diffractometer creation to build ophyd Component and Device objects dynamically from axis specifications and factory configurations.

VirtualPositionerBase(*[, physical_name])

Base class for a diffractometer's virtual axis.

define_real_axis(specs, kwargs)

Return class and kwargs of a real axis from its 'specs'.

dict_device_factory(data, **kwargs)

Create a DictionaryDevice() class using the supplied dictionary.

dynamic_import(full_path)

Import the object given its import path as text.

make_component(call_name, *args, **kwargs)

Create an Component for a custom ophyd Device class.

make_dynamic_instance(call_name, *args, **kwargs)

Return an instance of the Python 'call_name'.

parse_factory_axes(*[, space, axes, order, ...])

Parse a set of axis specifications, return Device class attributes.

Module Contents#

class hklpy2.devices.VirtualPositionerBase(*, physical_name: str = '', **kwargs)[source]#

Import: hklpy2.devices.VirtualPositionerBase

Bases: ophyd.SoftPositioner

Base class for a diffractometer’s virtual axis.

This base class also serves as an example where the virtual axis is twice the value of the physical axis. It is used as a Component of a ‘DiffractometerBase’ definition. The physical_name is the name of a sibling positioner attribute.

forward(physical: float) float[source]#

Return virtual position from physical position.

Subclass should override.

inverse(virtual: float) float[source]#

Return physical position from virtual position.

Subclass should override.

physical[source]#
hklpy2.devices.define_real_axis(specs: None | str | KeyValueMap, kwargs: KeyValueMap) tuple[str, Sequence, Mapping][source]#

Import: hklpy2.devices.define_real_axis

Return class and kwargs of a real axis from its ‘specs’.

hklpy2.devices.dict_device_factory(data: KeyValueMap, **kwargs: Any) type[source]#

Import: hklpy2.devices.dict_device_factory

Create a DictionaryDevice() class using the supplied dictionary.

hklpy2.devices.dynamic_import(full_path: str) type[source]#

Import: hklpy2.devices.dynamic_import

Import the object given its import path as text.

Motivated by specification of class names for plugins when using apstools.devices.ad_creator().

EXAMPLES:

klass = dynamic_import("ophyd.EpicsMotor")
m1 = klass("gp:m1", name="m1")

creator = dynamic_import("hklpy2.diffract.creator")
fourc = creator(name="fourc")

From the apstools package.

hklpy2.devices.make_component(call_name: str, *args: Any, **kwargs: Any) Component[source]#

Import: hklpy2.devices.make_component

Create an Component for a custom ophyd Device class.

hklpy2.devices.make_dynamic_instance(call_name: str, *args: Any, **kwargs: Any) Any[source]#

Import: hklpy2.devices.make_dynamic_instance

Return an instance of the Python ‘call_name’.

hklpy2.devices.parse_factory_axes(*, space: str | None = None, axes: KeyValueMap | None | Sequence[str] = None, order: Sequence[str] | None = None, canonical: Sequence[str] | None = None, labels: Sequence[str] | None = None, **_ignored: Any) Mapping[str, Component | Sequence[str]][source]#

Import: hklpy2.devices.parse_factory_axes

Parse a set of axis specifications, return Device class attributes.

Called from the diffract.diffractometer_class_factory().