run_utils#
Import: hklpy2.run_utils
Bluesky run-engine and databroker integration for hklpy2.
These utilities write diffractometer configuration into Bluesky run metadata and retrieve orientation information from previously recorded runs.
|
Write configuration of supported device(s) to a bluesky run. |
|
Create a simulated diffractometer from a saved configuration. |
|
Return the orientation information dictionary from a run. |
|
List the runs with orientation information. |
Module Contents#
- class hklpy2.run_utils.ConfigurationRunWrapper(*devices, knowns=None)[source]#
Import:
hklpy2.run_utils.ConfigurationRunWrapperWrite configuration of supported device(s) to a bluesky run.
EXAMPLE:
crw = ConfigurationRunWrapper(sim4c2) RE.preprocessors.append(crw.wrapper) RE(bp.rel_scan([noisy], m1, -1.2, 1.2, 11))
Disable the preprocessor:
crw.enable = False # 'True' to enable
Remove the last preprocessor:
RE.preprocessors.pop()
Add another diffractometer:
crw.devices.append(e4cv)
Return list of configured device names.
List of devices to be reported.
Is it permitted to write device configuration?
Known device base classes.
Top-level key in run's metadata dictionary.
validate(devices)Verify all are recognized objects.
wrapper(plan)Bluesky plan wrapper (preprocessor).
- hklpy2.run_utils.get_run_orientation(run: Any, name=None, start_key: str = DEFAULT_START_KEY) KeyValueMap[source]#
Import:
hklpy2.run_utils.get_run_orientationReturn the orientation information dictionary from a run.
EXAMPLE:
In [3]: get_run_orientation(cat[9752], name="sim4c2") Out[3]: {'_header': {'datetime': '2025-02-27 15:54:33.364719', 'hklpy2_version': '0.0.26.dev72+gcf9a65a.d20250227', 'python_class': 'Hklpy2Diffractometer', 'source_type': 'X-ray', 'energy_units': 'keV', 'energy': 12.398419843856837, 'wavelength_units': 'angstrom', 'wavelength': 1.0}, 'name': 'sim4c2', 'axes': {'pseudo_axes': ['h', 'k', 'l'], 'real_axes': ['omega', 'chi', 'phi', 'tth'], 'axes_xref': {'h': 'h', 'k': 'k', 'l': 'l', 'omega': 'omega', 'chi': 'chi', 'phi': 'phi', 'tth': 'tth'}, 'extra_axes': {}}, 'sample_name': 'sample', 'samples': {'sample': {'name': 'sample', 'lattice': {'a': 1, 'b': 1, 'c': 1, 'alpha': 90.0, 'beta': 90.0, 'gamma': 90.0}, 'reflections': {}, 'reflections_order': [], 'U': [[1, 0, 0], [0, 1, 0], [0, 0, 1]], 'UB': [[1, 0, 0], [0, 1, 0], [0, 0, 1]], 'digits': 4}}, 'constraints': {'omega': {'label': 'omega', 'low_limit': -180.0, 'high_limit': 180.0, 'class': 'LimitsConstraint'}, 'chi': {'label': 'chi', 'low_limit': -180.0, 'high_limit': 180.0, 'class': 'LimitsConstraint'}, 'phi': {'label': 'phi', 'low_limit': -180.0, 'high_limit': 180.0, 'class': 'LimitsConstraint'}, 'tth': {'label': 'tth', 'low_limit': -180.0, 'high_limit': 180.0, 'class': 'LimitsConstraint'}}, 'solver': {'name': 'hkl_soleil', 'description': "HklSolver(name='hkl_soleil', version='5.1.2', geometry='E4CV', engine_name='hkl', mode='bissector')", 'geometry': 'E4CV', 'real_axes': ['omega', 'chi', 'phi', 'tth'], 'version': '5.1.2', 'engine': 'hkl'}}
- hklpy2.run_utils.list_orientation_runs(catalog: Any, limit: int = 10, start_key: str = DEFAULT_START_KEY, **kwargs: Mapping) DataFrame[source]#
Import:
hklpy2.run_utils.list_orientation_runsList the runs with orientation information.
EXAMPLE:
In [42]: list_orientation_runs(cat, limit=5, date="_header.datetime") Out[42]: scan_id uid sample diffractometer geometry solver date 0 9752 41f71e9 sample sim4c2 E4CV hkl_soleil 2025-02-27 15:54:33.364719 1 9751 36e38bc sample sim4c2 E4CV hkl_soleil 2025-02-27 15:54:33.364719 2 9750 62e425d sample sim4c2 E4CV hkl_soleil 2025-02-27 15:54:33.364719 3 9749 18b11f0 sample sim4c2 E4CV hkl_soleil 2025-02-27 15:53:55.958929 4 9748 bf9912f sample sim4c2 E4CV hkl_soleil 2025-02-27 15:53:55.958929
- Returns:
Table of orientation runs
- Return type:
Pandas DataFrame object
- Parameters:
catalog (object) – Catalog of bluesky runs.
limit (int) – Limit the list to at most
limitruns. (default=10) It could take a long time to search an entire catalog.start_key (str) – Metadata key where the orientation information is stored in the start document. (default=”diffractometers”)
**kwargs (dict[str:str]) – Keyword parameters describing data column names to be displayed. The value of each column name is the dotted path to the orientation information (in the start document’s metadata).
- hklpy2.run_utils.register_aux_reconstructor(category: str, builder: Callable[[Mapping[str, Any]], Any]) None[source]#
Import:
hklpy2.run_utils.register_aux_reconstructorRegister a builder for a given aux-record
category.The
builderreceives a normalised record (dictwith at leastnameandcategory) and returns whatevercreator()accepts as areals=value:Nonefor a scalarSoftPositioner(the historic default);a
dictspec of the form{"class": <callable or import path>, ...kwargs}for any nested device.
Built-in categories —
"scalar"and"pseudo_positioner"— may be overridden by a later registration.PARAMETERS
- categorystr
The
categoryvalue the builder handles (e.g. a custom"device_group").- buildercallable
builder(record) -> creator-reals-spec.
- hklpy2.run_utils.simulator_from_config(config)[source]#
Import:
hklpy2.run_utils.simulator_from_configCreate a simulated diffractometer from a saved configuration.
All axes are soft positioners — no hardware connections are made. Auxiliary axes and solver mode saved by
export()are restored automatically.If the diffractometer requires auxiliary axes that are not in the configuration file, use
creator()withrestore()instead:sim = hklpy2.creator(name="e4cv", reals=dict(..., extra_axis=None)) sim.restore("e4cv-config.yml")
PARAMETERS
- configdict, str, pathlib.Path, or DiffractometerBase
One of:
a configuration dictionary,
a path to a YAML configuration file previously saved with
diffractometer.export(), ora
DiffractometerBaseinstance (its current configuration snapshot will be used).
RETURNS
- DiffractometerBase
A fully configured simulated diffractometer instance.
EXAMPLE:
>>> import hklpy2 >>> sim = hklpy2.simulator_from_config("e4cv-config.yml") >>> sim.wh() Or directly from an existing diffractometer:: >>> sim = hklpy2.simulator_from_config(diffractometer)
Solver construction kwargs
Every key in the persisted
solver:block except the reserved set{"name", "description", "geometry", "real_axes", "version", "mode"}is forwarded to the solver’s constructor as asolver_kwargsentry. This lets a solver persist arbitrary construction state by overriding its_metadataproperty and accepting the matching keyword in its__init__. See issue #405. Solver authors are responsible for choosing_metadatakey names that do not collide with the reserved set.SEE ALSO
creator()— create a diffractometer from scratch.