From 816345ca6b31db9af32c020b3b1e4ffccb3740f7 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Tue, 17 Oct 2023 15:34:21 -0500 Subject: [PATCH 1/3] TST #215 --- hkl/tests/test_util.py | 119 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/hkl/tests/test_util.py b/hkl/tests/test_util.py index ede3554c..f7987b40 100644 --- a/hkl/tests/test_util.py +++ b/hkl/tests/test_util.py @@ -6,6 +6,75 @@ NO_SUCH_PACKAGE_NAME = "no-such-package" +@pytest.fixture(scope="function") +def cat(): + import databroker + + yield databroker.temp().v2 + + +@pytest.fixture(scope="function") +def RE(cat): + import bluesky + + engine = bluesky.RunEngine() + engine.subscribe(cat.v1.insert) + yield engine + + +@pytest.fixture(scope="function") +def fourc(): + """4-circle with renamed axes and oriented sample.""" + from hkl import E4CV, SimMixin + from ophyd import Component + from ophyd import SoftPositioner + + class FourCircle(SimMixin, E4CV): + theta = Component(SoftPositioner, kind="hinted", init_pos=0) + chi = Component(SoftPositioner, kind="hinted", init_pos=0) + phi = Component(SoftPositioner, kind="hinted", init_pos=0) + ttheta = Component(SoftPositioner, kind="hinted", init_pos=0) + + fourc = FourCircle("", name="fourc") + # rename the physical axes + fourc.calc.physical_axis_names = { + # E4CV: local + "omega": "theta", + "chi": "chi", + "phi": "phi", + "tth": "ttheta", + } + + # fourc.wait_for_connection() + fourc._update_calc_energy() + crystal_setup(fourc) + + yield fourc + + +def crystal_setup(diffractometer): + from hkl import Lattice + + diffractometer.calc.wavelength = 1.0 + a0 = 5.4321 + # fmt: off + diffractometer.calc.new_sample( + "vibranium", + lattice=Lattice(a=a0, b=a0, c=a0, alpha=90, beta=90, gamma=90) + ) + + diffractometer.calc.sample.add_reflection( + 1, 2, 3, + position=diffractometer.calc.Position( + ttheta=60, + theta=40, + chi=0, + phi=0, + ), + ) + # fmt: on + + def test__package_info_states(): assert hkl.util._package_info is None hkl.util.get_package_info("hkl") @@ -74,3 +143,53 @@ def test_software_versions_items(package_name, minimum_version): assert v_package >= version.parse(minimum_version) else: assert package_name in ("hklpy", NO_SUCH_PACKAGE_NAME) + + +def test_issue215(cat, RE, fourc): + """restore_reflections(orientation, fourc) cannot find renamed positioner.""" + from bluesky import plans as bp + + canonical_names = "omega chi phi tth".split() + our_names = "theta chi phi ttheta".split() + assert our_names != canonical_names + assert fourc.calc.physical_axis_names != canonical_names + assert fourc.calc.physical_axis_names == our_names + + problem_reflection_dict = { + "reflection": {"h": 1.0, "k": -3.0, "l": -1.0}, + "flag": 1, + "wavelength": 1.1169734383241103, + "position": { + "omega": -8.208399999999983, + "chi": -47.47651999999994, + "phi": -5.684341886080802e-14, + "tth": 25.09473789610388, + }, + "orientation_reflection": False, + } + problem_positioner_names = list(problem_reflection_dict["position"].keys()) + assert problem_positioner_names == canonical_names + + assert len(cat) == 0 + uids = RE(bp.count([fourc])) + assert len(uids) == 1 + assert len(cat) == 1 + + orientation = hkl.util.run_orientation_info(cat[-1]) + assert isinstance(orientation, dict) + assert fourc.name in orientation + # assert list(orientation.keys()) == [] + + orient = orientation[fourc.name] + assert orient["_reals"] != canonical_names + assert orient["_reals"] == our_names + for reflection in orient["reflections_details"]: + assert list(reflection["position"].keys()) == canonical_names + + success = False + try: + # since it is just a problem of motor names in reflections ... + hkl.util.restore_reflections(orient, fourc) + success = True + finally: + assert success, "Could not restore orientation reflections." From 3bdf537d7ae90e736b7f8e93dd8559b8f3f9bf2b Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Tue, 17 Oct 2023 15:34:47 -0500 Subject: [PATCH 2/3] MNT #215 remap the names if needed --- hkl/util.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hkl/util.py b/hkl/util.py index 91611012..ebacd59a 100644 --- a/hkl/util.py +++ b/hkl/util.py @@ -423,6 +423,10 @@ def restore_reflections(orientation, diffractometer): pseudos = orientation["_pseudos"] reals = orientation["_reals"] orientation_reflections = [] + # might be renamed axes + renaming = diffractometer.calc._axis_name_to_original + if len(renaming) > 0: + reals = [renaming[k] for k in reals] for ref_base in orientation["reflections_details"]: # every reflection has its own wavelength From 81fe2f09e1a6dc38a8ab4a4b180ab0fca793a1c2 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Tue, 17 Oct 2023 15:43:29 -0500 Subject: [PATCH 3/3] DOC #215 --- RELEASE_NOTES.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index b5179ebe..7cefff79 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -11,11 +11,21 @@ Release History Deprecations Contributors -v1.1 (expected 2024) +v1.2 (expected 2024) ====================================== User-requested changes +v1.1 (expected 2023-12) +====================================== + +Add new geometries from upstream *libhkl*. + +Fixes +----- + +* ``util.restore_reflections()`` use renamed motor axes if so defined. + v1.0.4 (released 2023-10-06) ======================================