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.describe_aux(diffractometer: object, name: str) dict[source]#

Import: hklpy2.devices.describe_aux

Build a single axes.auxiliary_axes record for name.

Categorises the auxiliary into one of the schema-v2 categories:

  • "scalar" — a plain PositionerBase (the historic default; the round-tripped simulator stand-in is an SoftPositioner).

  • "pseudo_positioner" — a nested PseudoPositioner; sub-axis names are recorded as ordered pseudos / reals lists. class / module are advisory metadata only — never imported by hklpy2 on restore.

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_aux_pseudo_positioner_class(name: str, pseudos: Sequence[str], reals: Sequence[str]) type[source]#

Import: hklpy2.devices.make_aux_pseudo_positioner_class

Build a synthetic PseudoPositioner subclass with the given sub-axis names.

The resulting class is structural only: forward() and inverse() return zeros for every sub-axis. Its purpose is to let downstream code (printers, plan inspection, etc.) traverse the same component tree the original device exposed.

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

Import: hklpy2.devices.make_component

Create an Component for a custom ophyd Device class.

call_name may be either a dotted import path (str) or an already-resolved callable (type). The callable form is used by hklpy2.run_utils.simulator_from_config() when restoring a nested PseudoPositioner auxiliary whose synthetic stand-in class is built at runtime and therefore cannot be addressed by an import path.

Changed in version 0.7.0: Accept a callable in addition to a dotted import-path string. See issue #388.

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().