Skip to content

Commit

Permalink
Merge pull request #311 from bluesky/310-unit-tests
Browse files Browse the repository at this point in the history
convert canonical axes names to user-defined names

@padraic-shafer : Thanks for the review!
  • Loading branch information
prjemian authored Dec 14, 2023
2 parents 95be6c9 + c49c516 commit 84a2c25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hkl/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def has_valid_position(pos):
if pos is None:
# so use the current motor positions
return False
elif type(pos).__name__.startswith("Pos"):
elif type(pos).__name__.startswith("Pos") or type(pos).__name__.endswith("RealPos"):
# This is (probably) a calc.Position namedtuple
if False in [isinstance(v, (int, float)) for v in pos]:
raise TypeError(f"All values must be numeric, received {pos!r}")
Expand Down
18 changes: 11 additions & 7 deletions hkl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,23 @@ def restore_reflections(orientation, diffractometer):
Diffractometer object.
"""
_check_geometry(orientation, diffractometer)
calc = diffractometer.calc
# remember this wavelength
wavelength0 = diffractometer.calc.wavelength
wavelength0 = calc.wavelength

# short aliases
pseudos = orientation["_pseudos"]
reals = orientation["_reals"]
if reals != calc.physical_axis_names and reals == calc._geometry.axis_names_get():
# Substitute user-defined axes names for canonical axes names.
reals = calc.physical_axis_names
orientation_reflections = []
# might be renamed axes
renaming = diffractometer.calc._axis_name_to_original
renaming = calc._axis_name_to_original

for ref_base in orientation["reflections_details"]:
# every reflection has its own wavelength
diffractometer.calc.wavelength = ref_base["wavelength"]
calc.wavelength = ref_base["wavelength"]

# Order of the items is important.
# Can't just use the dictionaries in ``orientation``.
Expand All @@ -471,17 +475,17 @@ def restore_reflections(orientation, diffractometer):

# assemble the final form of the reflection for add_reflection()
reflection = tuple([*miller_indices, ppp])
r = diffractometer.calc.sample.add_reflection(*reflection)
r = calc.sample.add_reflection(*reflection)
if ref_base["orientation_reflection"]:
orientation_reflections.append(r)

if len(orientation_reflections) > 1:
# compute **UB** from the last two orientation reflections
diffractometer.calc.sample.compute_UB(*orientation_reflections[-2:])
calc.sample.compute_UB(*orientation_reflections[-2:])

# restore previous wavelength
if diffractometer.calc.wavelength != wavelength0:
diffractometer.calc.wavelength = wavelength0
if calc.wavelength != wavelength0:
calc.wavelength = wavelength0


def restore_orientation(orientation, diffractometer):
Expand Down

0 comments on commit 84a2c25

Please sign in to comment.