Skip to content

Commit 88f366d

Browse files
authored
Merge pull request #1058 from BCDA-APS/1056-hklpy-configuration
Callbacks should gather hklpy diffractometer configurations @MDecarabas Thanks!
2 parents 311d065 + 33deeaf commit 88f366d

File tree

6 files changed

+5943
-0
lines changed

6 files changed

+5943
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ build_log.txt
4141

4242
# setuptools-scm : generated version number
4343
_version.py
44+
45+
# bs_model_instrument
46+
.re_md_dict.yml

CHANGES.rst

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ describe future plans.
2626
2727
Release expected by 2025-02-28.
2828

29+
Enhancements
30+
-------------
31+
32+
* Recover diffractometer configurations in FileWriterCallbackBase.
33+
2934
Fixes
3035
-----
3136

apstools/callbacks/callback_base.py

+19
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FileWriterCallbackBase:
4343
.. autosummary::
4444
4545
~clear
46+
~get_hklpy_configurations
4647
~make_file_name
4748
~writer
4849
@@ -101,6 +102,7 @@ def clear(self):
101102
"""
102103
self.acquisitions = {}
103104
self.detectors = []
105+
self.diffractometers = {}
104106
self.exit_status = None
105107
self.externals = {}
106108
self.doc_timestamp = None
@@ -131,6 +133,20 @@ def file_path(self):
131133
def file_path(self, value):
132134
self._file_path = pathlib.Path(value)
133135

136+
def get_hklpy_configurations(self, doc: dict) -> dict:
137+
"""Diffractometer details (from hklpy) in RE descriptor documents."""
138+
configurations = {} # zero, one, or more diffractometers are possible
139+
for diffractometer_name in doc.get("configuration", {}):
140+
record = doc["configuration"][diffractometer_name].get("data", {})
141+
attrs = record.get(f"{diffractometer_name}_orientation_attrs")
142+
if attrs is not None:
143+
configurations[diffractometer_name] = {
144+
# empty when no orientation_attrs
145+
attr: record[f"{diffractometer_name}_{attr}"]
146+
for attr in attrs
147+
}
148+
return configurations
149+
134150
def make_file_name(self):
135151
"""
136152
generate a file name to be used as default
@@ -271,6 +287,9 @@ def descriptor(self, doc):
271287
dd["time"] = [] # entry time stamps here
272288
dd["external"] = entry.get("external") is not None
273289
# logger.debug("dd %s: %s", k, data[k])
290+
291+
# Gather any available diffractometer configurations.
292+
self.diffractometers.update(self.get_hklpy_configurations(doc))
274293

275294
def event(self, doc):
276295
"""

apstools/callbacks/tests/hklpy-26aac337.json

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)