Skip to content

Commit

Permalink
Merge pull request #1058 from BCDA-APS/1056-hklpy-configuration
Browse files Browse the repository at this point in the history
Callbacks should gather hklpy diffractometer configurations

@MDecarabas Thanks!
  • Loading branch information
prjemian authored Feb 7, 2025
2 parents 311d065 + 33deeaf commit 88f366d
Show file tree
Hide file tree
Showing 6 changed files with 5,943 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ build_log.txt

# setuptools-scm : generated version number
_version.py

# bs_model_instrument
.re_md_dict.yml
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe future plans.
Release expected by 2025-02-28.

Enhancements
-------------

* Recover diffractometer configurations in FileWriterCallbackBase.

Fixes
-----

Expand Down
19 changes: 19 additions & 0 deletions apstools/callbacks/callback_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FileWriterCallbackBase:
.. autosummary::
~clear
~get_hklpy_configurations
~make_file_name
~writer
Expand Down Expand Up @@ -101,6 +102,7 @@ def clear(self):
"""
self.acquisitions = {}
self.detectors = []
self.diffractometers = {}
self.exit_status = None
self.externals = {}
self.doc_timestamp = None
Expand Down Expand Up @@ -131,6 +133,20 @@ def file_path(self):
def file_path(self, value):
self._file_path = pathlib.Path(value)

def get_hklpy_configurations(self, doc: dict) -> dict:
"""Diffractometer details (from hklpy) in RE descriptor documents."""
configurations = {} # zero, one, or more diffractometers are possible
for diffractometer_name in doc.get("configuration", {}):
record = doc["configuration"][diffractometer_name].get("data", {})
attrs = record.get(f"{diffractometer_name}_orientation_attrs")
if attrs is not None:
configurations[diffractometer_name] = {
# empty when no orientation_attrs
attr: record[f"{diffractometer_name}_{attr}"]
for attr in attrs
}
return configurations

def make_file_name(self):
"""
generate a file name to be used as default
Expand Down Expand Up @@ -271,6 +287,9 @@ def descriptor(self, doc):
dd["time"] = [] # entry time stamps here
dd["external"] = entry.get("external") is not None
# logger.debug("dd %s: %s", k, data[k])

# Gather any available diffractometer configurations.
self.diffractometers.update(self.get_hklpy_configurations(doc))

def event(self, doc):
"""
Expand Down
1 change: 1 addition & 0 deletions apstools/callbacks/tests/hklpy-26aac337.json

Large diffs are not rendered by default.

Loading

0 comments on commit 88f366d

Please sign in to comment.