Package: ophyd-registry
Ophyd RegistryA registry to keep track of, and retrieve, Ophyd objects.TheOphyd registryprovides a way to keep track of the devices
(including components, motors, signals, etc.) that have been defined
across a project. In order for the registry to know of a device, that
device must first be registered, though there are ways to do this
automatically.This allows for a simple way to keep track of the Ophyd devices that were
created in your project.importophydfromophydregistryimportOphydRegistry# Register the devices when they're createdregistry=OphydRegistry()registry.register(ophyd.sim.motor)# Then elsewhere in your project, use them...registry['motor'].set(15.3)InstallationThe easiest way to install the ophyd registry is with pip from PyPI:python-mpipinstallophyd-registryTo create adeveloper installation:gitclonehttps://github.com/spc-group/ophyd-registry.git
python-mpipinstall"ophyd_registry[dev]"UsageRegistering DevicesThere are three ways to have an instrument registry know about a
device.Implicitly capture all Ophyd objectsRegister a device classRegister individual objectsBy default, a new instrument registry will alert itself to all future
devices:fromophydregistryimportRegistryregistry=Registry()the_device=MyDevice("255id:Dev:",name="my_device")assertregistry.find("my_device")isthe_deviceIf this greedy behavior is suppressed with theauto_registerparameter. Ifauto_registeris false, then a device class can be
decorated to allow the registry to find it:fromophydimportDevicefromophydregistryimportRegistryregistry=Registry(auto_register=False)@registry.registerclassMyDevice(Device):...the_device=MyDevice("255id:Dev:",name="my_device")assertregistry.find("my_device")isthe_deviceLastly, individual instantions of a device can be explicitly
registered.fromophydimportDevicefromophydregistryimportRegistryregistry=Registry(auto_register=False)classMyDevice(Device):...the_device=MyDevice("255id:Dev:",name="my_device")registry.register(the_device)assertregistry.find("my_device")isthe_deviceLooking Up Registered Devices/ComponentsRegistered objects can be found byname,label, or both. The
easist way is to treat the registry like a dictionary:registry['motor1']. This will look for an individual device first
bynamethen bylabel. It will raise an exception if the number of
devices is not 1.For more sophisticated queries, theRegistry.find()method will
return a single result, whileRegistry.findall()returns more than
one. By default,findall()will raise an exception if no objects
match the criteria, but this can be overridden with theallow_nonekeyword argument.The registry uses the built-in concept of device labels in Ophyd. The
registry'sfind()andfindall()methods allows devices to be
looked up by label or device name. For example, assuming four devices
exist with the label "ion_chambers", then these devices can be
retrieved using the registry:ion_chambers=registry.findall(label="ion_chambers")assertlen(ion_chambers)==4Devices can also be found by name:ion_chambers=registry.find(name="I0")assertlen(ion_chambers)==4A set of theroot devices, those without a parent, can be
retrieved atRegistry.root_devices.Looking Up Sub-Components by Dot-NotationFor simple devices, the full name of the sub-component should be
enough to retrieve the device. For example, to find the signalpreset_timeon the device named "vortex_me4", the following may work
fine:preset_time=haven.registry.find("vortex_me4_preset_time")However,if the component is lazyand has not been accessed prior
to being registered, thenit will not be available in the
registry. Sub-components can instead be accessed by dot
notation. Unlike the full device name, dot-notation names only resolve
when the component is requested from the registry, at which point the
lazy components can be accessed.For example, area detectors use many lazy components. Ifsim_detis an area detector with a camera componentsim_det.cam, then the
name of the gain channel is "sim_det_cam_gain", however this is a lazy
component so is not available. Instead, retrieving the device byhaven.registry.find("sim_det.cam.gain")will first find the area
detector ("sim_det"), then access thecamattribute, and then cam'sgainattribute. This has the side-effect of instantiating the lazy
components.Integrating with TyphosTyphos includes a PyDM plugin that can directly interact with ophyd
devices. It requires ophyd objects to be registered in order to find
them.ophyd_registrycan automatically register devices with
Typhos by simply passing theuse_typhosargument when creating the
registry:.. code:: pythonfrom ophydregistry import Registry
registry = Registry(use_typos=True)or setting theuse_typhosattribute on an existing registry:.. code:: pythonfrom ophydregistry import Registry
registry = Registry()
registry.use_typhos = TrueIf using the typhos registry, calling theclear()method on the
ophyd registry will also clear the Typhos registry.