Skip to content

Commit

Permalink
Merge pull request HEXRD#1701 from HEXRD/calibration-euler-convention
Browse files Browse the repository at this point in the history
Allow Euler convention setting for calibration
  • Loading branch information
psavery authored May 1, 2024
2 parents e3df3a1 + 1949465 commit d3550c7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
4 changes: 3 additions & 1 deletion hexrdgui/calibration/auto/powder_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def _run(self):

self.pc = PowderCalibrator(**kwargs)
self.ic = InstrumentCalibrator(
self.pc, engineering_constraints=engineering_constraints
self.pc,
engineering_constraints=engineering_constraints,
euler_convention=HexrdConfig().euler_angle_convention,
)
self.extract_powder_lines()

Expand Down
24 changes: 23 additions & 1 deletion hexrdgui/calibration/calibration_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QComboBox, QDoubleSpinBox, QMessageBox, QSpinBox

from hexrd.fitting.calibration.lmfit_param_handling import (
normalize_euler_convention,
param_names_euler_convention,
)

from hexrdgui import resource_loader
from hexrdgui.constants import ViewType
from hexrdgui.hexrd_config import HexrdConfig
Expand Down Expand Up @@ -341,6 +346,16 @@ def recursively_format_det(det, this_config, this_template):
this_dict[i + 1] = create_param_item(param)
i += 1
current = template.format(det=det, i=i)
elif k == 'tilt':
# Special case. Take into account euler angles.
convention = HexrdConfig().euler_angle_convention
normalized = normalize_euler_convention(convention)
param_names = param_names_euler_convention(det, convention)
labels = TILT_LABELS_EULER[normalized]
this_dict = this_config.setdefault(k, {})
for label, param_name in zip(labels, param_names):
param = params_dict[param_name]
this_dict[label] = create_param_item(param)
else:
# Should be a string. Replace {det} with det if needed
if '{det}' in v:
Expand All @@ -367,7 +382,7 @@ def recursively_format_det(det, this_config, this_template):
used = ', '.join(sorted(used_params))
params = ', '.join(sorted(params_dict))
msg = (
f'Internal error: used_params ({used}) did not match '
f'Internal error: used_params ({used})\n\ndid not match '
f'params_dict! ({params})'
)
raise Exception(msg)
Expand Down Expand Up @@ -460,3 +475,10 @@ def set_config_val(self, path, value):
# Now set the attribute on the param
attribute = path[-1].removeprefix('_')
setattr(param, attribute, value)


TILT_LABELS_EULER = {
None: ('X', 'Y', 'Z'),
('xyz', True): ('X', 'Y', 'Z'),
('zxz', False): ('Z', "X'", "Z''"),
}
14 changes: 13 additions & 1 deletion hexrdgui/calibration/calibration_dialog_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QFileDialog

from hexrd.fitting.calibration.lmfit_param_handling import (
update_instrument_from_params,
)

from hexrdgui.hexrd_config import HexrdConfig
from hexrdgui.utils import instr_to_internal_dict
from hexrdgui.utils.abc_qobject import ABCQObject
Expand Down Expand Up @@ -55,6 +59,10 @@ def setup_connections(self):
def canvas(self):
return HexrdConfig().active_canvas

@property
def euler_convention(self):
return HexrdConfig().euler_angle_convention

@abstractmethod
def draw_picks_on_canvas(self):
pass
Expand Down Expand Up @@ -127,7 +135,11 @@ def pop_undo_stack(self):
v = stack_item[k]
setattr(self.calibrator, k, v)

self.instr.update_from_lmfit_parameter_list(self.calibrator.params)
update_instrument_from_params(
self.instr,
self.calibrator.params,
self.euler_convention,
)
self.update_config_from_instrument()
self.update_dialog_from_calibrator()
self.dialog.advanced_options = stack_item['advanced_options']
Expand Down
1 change: 1 addition & 0 deletions hexrdgui/calibration/calibration_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ def auto_pick_laue_points(self):
'grain_params': overlay.crystal_params,
'min_energy': overlay.min_energy,
'max_energy': overlay.max_energy,
'euler_convention': HexrdConfig().euler_angle_convention,
}

self.laue_auto_picker = LaueCalibrator(**init_kwargs)
Expand Down
10 changes: 9 additions & 1 deletion hexrdgui/calibration/material_calibration_dialog_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from hexrd.fitting.calibration.lmfit_param_handling import (
normalize_euler_convention
)

from hexrdgui.calibration.calibration_dialog import TILT_LABELS_EULER
from hexrdgui.calibration.calibration_dialog_callbacks import (
CalibrationDialogCallbacks,
)
from hexrdgui.calibration.hkl_picks_tree_view_dialog import (
overlays_to_tree_format, HKLPicksTreeViewDialog,
)
from hexrdgui.constants import ViewType
from hexrdgui.hexrd_config import HexrdConfig


class MaterialCalibrationDialogCallbacks(CalibrationDialogCallbacks):
Expand Down Expand Up @@ -118,7 +124,9 @@ def format_material_params_func(params_dict, tree_dict, create_param_item,
else:
# Assume grain parameters
d['Orientation'] = {}
labels = ['Z', "X'", "Z''"]
euler_convention = normalize_euler_convention(
HexrdConfig().euler_angle_convention)
labels = TILT_LABELS_EULER[euler_convention]
for i in range(3):
param = params_dict[calibrator.param_names[i]]
d['Orientation'][labels[i]] = create_param_item(param)
Expand Down
9 changes: 7 additions & 2 deletions hexrdgui/calibration/pick_based_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
LaueCalibrator,
PowderCalibrator,
)
from hexrdgui.hexrd_config import HexrdConfig
from hexrdgui.utils.guess_instrument_type import guess_instrument_type


def make_calibrators_from_picks(instr, processed_picks, materials, img_dict):
def make_calibrators_from_picks(instr, processed_picks, materials, img_dict,
euler_convention):
calibrators = []
for pick_data in processed_picks:
if pick_data['type'] == 'powder':
Expand All @@ -30,17 +32,20 @@ def make_calibrators_from_picks(instr, processed_picks, materials, img_dict):
'min_energy': pick_data['options']['min_energy'],
'max_energy': pick_data['options']['max_energy'],
'calibration_picks': pick_data['picks'],
'euler_convention': euler_convention,
}
calibrators.append(LaueCalibrator(**kwargs))
return calibrators


def create_instrument_calibrator(picks, instr, img_dict, materials):
euler_convention = HexrdConfig().euler_angle_convention
engineering_constraints = guess_instrument_type(instr.detectors)
calibrators = make_calibrators_from_picks(instr, picks, materials,
img_dict)
img_dict, euler_convention)

return InstrumentCalibrator(
*calibrators,
engineering_constraints=engineering_constraints,
euler_convention=euler_convention,
)
1 change: 1 addition & 0 deletions hexrdgui/calibration/structureless/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def show_calibration_dialog(self, calibrator_lines):
'instr': self.instr,
'data': calibrator_lines,
'engineering_constraints': engineering_constraints,
'euler_convention': HexrdConfig().euler_angle_convention,
}
self.calibrator = StructurelessCalibrator(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ detectors:
'{det}':
transform:
tilt:
Z: '{det}_euler_z'
"X'": '{det}_euler_xp'
"Z''": '{det}_euler_zpp'
translation:
X: '{det}_tvec_x'
Y: '{det}_tvec_y'
Expand Down

0 comments on commit d3550c7

Please sign in to comment.