Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert canonical axes names to user-defined names #311

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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