diff --git a/hexrdgui/calibration/calibration_dialog.py b/hexrdgui/calibration/calibration_dialog.py
index 61c1a7d8c..6fa6dc6e4 100644
--- a/hexrdgui/calibration/calibration_dialog.py
+++ b/hexrdgui/calibration/calibration_dialog.py
@@ -45,6 +45,7 @@ class CalibrationDialog(QObject):
relative_constraints_changed = Signal(RelativeConstraintsType)
tilt_center_of_rotation_changed = Signal(RotationCenter)
engineering_constraints_changed = Signal(str)
+ reset_relative_params_to_zero_clicked = Signal()
pinhole_correction_settings_modified = Signal()
@@ -107,6 +108,8 @@ def setup_connections(self):
self.on_active_beam_changed)
self.ui.show_picks_from_all_xray_sources.toggled.connect(
self.show_picks_from_all_xray_sources_toggled)
+ self.ui.reset_relative_params_to_zero.clicked.connect(
+ self.on_reset_relative_params_to_zero_clicked)
self.ui.relative_constraints.currentIndexChanged.connect(
self.on_relative_constraints_changed)
self.ui.tilt_center_of_rotation.currentIndexChanged.connect(
@@ -245,6 +248,7 @@ def update_relative_constraint_visibilities(self):
visible = self.relative_constraints != RelativeConstraintsType.none
tilt_center_widgets = [
+ self.ui.reset_relative_params_to_zero,
self.ui.tilt_center_of_rotation,
self.ui.tilt_center_of_rotation_label,
]
@@ -432,6 +436,9 @@ def tth_distortion(self, v):
first = next(iter(v.values()))
self.pinhole_correction_editor.update_from_object(first)
+ def on_reset_relative_params_to_zero_clicked(self):
+ self.reset_relative_params_to_zero_clicked.emit()
+
def on_relative_constraints_changed(self):
# If the relative constraints is not None, then the engineering
# constraints must be set to None
diff --git a/hexrdgui/calibration/calibration_dialog_callbacks.py b/hexrdgui/calibration/calibration_dialog_callbacks.py
index f9983e2bc..8d9b84783 100644
--- a/hexrdgui/calibration/calibration_dialog_callbacks.py
+++ b/hexrdgui/calibration/calibration_dialog_callbacks.py
@@ -6,6 +6,9 @@
import lmfit
+from hexrd.fitting.calibration.relative_constraints import (
+ RelativeConstraintsType,
+)
from hexrd.fitting.calibration.lmfit_param_handling import (
create_instr_params,
update_instrument_from_params,
@@ -17,6 +20,10 @@
from hexrdgui.utils.abc_qobject import ABCQObject
+# Number of decimal places to round calibration parameters
+ROUND_DECIMALS = 3
+
+
class CalibrationDialogCallbacks(ABCQObject):
"""A class with default behavior for calibration dialog callbacks"""
@@ -59,6 +66,8 @@ def setup_connections(self):
dialog.load_picks_clicked.connect(self.on_load_picks_clicked)
dialog.relative_constraints_changed.connect(
self.on_relative_constraints_changed)
+ dialog.reset_relative_params_to_zero_clicked.connect(
+ self.on_reset_relative_params_to_zero_clicked)
dialog.tilt_center_of_rotation_changed.connect(
self.on_tilt_center_of_rotation_changed)
dialog.engineering_constraints_changed.connect(
@@ -162,18 +171,54 @@ def pop_undo_stack(self):
self.dialog.advanced_options = stack_item['advanced_options']
self.update_undo_enable_state()
+ self.save_constraint_params()
def update_undo_enable_state(self):
self.dialog.undo_enabled = bool(self.undo_stack)
def on_relative_constraints_changed(self, new_constraint):
self.calibrator.relative_constraints_type = new_constraint
+ self.restore_constraint_params()
# Reset the tilt center of rotation in the dialog
self.dialog.tilt_center_of_rotation = (
self.calibrator.relative_constraints.rotation_center
)
self.on_constraints_changed()
+ def on_reset_relative_params_to_zero_clicked(self):
+ self.reset_saved_constraint_params()
+
+ def save_constraint_params(self):
+ constraints = self.calibrator.relative_constraints
+ if constraints.type != RelativeConstraintsType.system:
+ # Instead of saving, reset them
+ self.reset_saved_constraint_params()
+ return
+
+ HexrdConfig()._instrument_rigid_body_params = copy.deepcopy(
+ constraints.params)
+
+ def restore_constraint_params(self):
+ constraints = self.calibrator.relative_constraints
+ if constraints.type != RelativeConstraintsType.system:
+ return
+
+ params = copy.deepcopy(HexrdConfig()._instrument_rigid_body_params)
+ if not params:
+ return
+
+ constraints.params.update(**params)
+ self.calibrator.reset_lmfit_params()
+ self.round_param_numbers()
+ self.update_dialog_from_calibrator()
+
+ def reset_saved_constraint_params(self):
+ HexrdConfig()._instrument_rigid_body_params.clear()
+ constraints = self.calibrator.relative_constraints
+ constraints.reset_params()
+ self.calibrator.reset_lmfit_params()
+ self.update_dialog_from_calibrator()
+
def on_tilt_center_of_rotation_changed(self, new_center):
relative_constraints = self.calibrator.relative_constraints
if relative_constraints.rotation_center != new_center:
@@ -270,6 +315,7 @@ def run_calibration(self, **extra_kwargs):
def on_calibration_finished(self):
self.update_config_from_instrument()
+ self.save_constraint_params()
self.dialog.params_dict = self.calibrator.params
def update_config_from_instrument(self):
@@ -299,7 +345,7 @@ def update_config_from_instrument(self):
def update_tth_distortion_from_dialog(self):
self.calibrator.tth_distortion = self.dialog.tth_distortion
- def round_param_numbers(self, decimals=3):
+ def round_param_numbers(self):
params_dict = self.calibrator.params
attrs = [
@@ -309,7 +355,11 @@ def round_param_numbers(self, decimals=3):
]
for param in params_dict.values():
for attr in attrs:
- setattr(param, attr, round(getattr(param, attr), 3))
+ setattr(
+ param,
+ attr,
+ round(getattr(param, attr), ROUND_DECIMALS)
+ )
def on_edit_picks_finished(self):
# Show this again
diff --git a/hexrdgui/hexrd_config.py b/hexrdgui/hexrd_config.py
index bc16c669a..e50a9e14c 100644
--- a/hexrdgui/hexrd_config.py
+++ b/hexrdgui/hexrd_config.py
@@ -326,6 +326,7 @@ def __init__(self):
self._apply_absorption_correction = False
self._physics_package = None
self._detector_coatings = {}
+ self._instrument_rigid_body_params = {}
# Make sure that the matplotlib font size matches the application
self.font_size = self.font_size
@@ -428,6 +429,7 @@ def _attributes_to_persist(self):
('sample_tilt', [0, 0, 0]),
('azimuthal_offset', 0.0),
('_active_beam_name', None),
+ ('_instrument_rigid_body_params', {}),
('recent_state_files', []),
('apply_absorption_correction', False),
('physics_package_dictified', None),
@@ -467,6 +469,7 @@ def _load_state_from_settings(self, settings):
'azimuthal_overlays',
'azimuthal_offset',
'_recent_images',
+ '_instrument_rigid_body_params',
]
state = {}
diff --git a/hexrdgui/resources/ui/calibration_dialog.ui b/hexrdgui/resources/ui/calibration_dialog.ui
index 4d8b16105..07742fb14 100644
--- a/hexrdgui/resources/ui/calibration_dialog.ui
+++ b/hexrdgui/resources/ui/calibration_dialog.ui
@@ -20,24 +20,24 @@
Constraints
- -
-
+
-
+
- <html><head/><body><p>Options to set relative constraints between the detectors.</p><p><br/></p><p>"None" means no relative constraints.</p><p><br/></p><p>"System" means all detectors are relatively constrained to one another. In this case, the mean center of the detectors and a mean tilt may be refined.</p></body></html>
-
-
- Relative constraints:
+ <html><head/><body><p>Options to set relative constraints between the detectors.</p><p><br/></p><p>"None" means no relative constraints.</p><p><br/></p><p>"Instrument Rigid Body" means all detectors in the entire instrument are relatively constrained to one another. In this case, the mean center of the detectors and a mean tilt may be refined.</p></body></html>
- -
-
+
-
+
+
+ <html><head/><body><p>The center of rotation to be used for tilt parameters when relative constraints are enabled.</p><p><br/></p><p>"Mean Instrument Center" will cause the panels to be rotated about the mean center of the detectors when the tilt is modified.</p><p><br/></p><p>"Origin" will cause the panels to be rotated about lab origin (i. e., [0, 0, 0]) when the tilt is modified.</p></body></html>
+
- Use delta for boundaries
+ Tilt center of rotation:
- -
+
-
<html><head/><body><p>If clicked, the "Vary" and "Delta" (if "Use delta for boundaries" is checked) settings of the first detector's tilt/translation parameters will be copied to all other detectors' tilt/translation parameters.</p><p>This is helpful if you have many detectors and want to modify all of their "Vary" and "Delta" settings in a similar way.</p></body></html>
@@ -47,24 +47,7 @@
- -
-
-
- <html><head/><body><p>Options to set relative constraints between the detectors.</p><p><br/></p><p>"None" means no relative constraints.</p><p><br/></p><p>"Instrument Rigid Body" means all detectors in the entire instrument are relatively constrained to one another. In this case, the mean center of the detectors and a mean tilt may be refined.</p></body></html>
-
-
-
- -
-
-
- <html><head/><body><p>Add engineering constraints for certain instrument types. This may add extra parameters to the table.</p><p><br/></p><p>For example, for TARDIS, the distance between IMAGE-PLATE-2 and IMAGE-PLATE-4 must be within a certain range. If TARDIS is selected, a new parameter is added with default values for this distance.</p><p><br/></p><p>If the instrument type can be guessed, it will be selected automatically when the dialog first appears. For example, TARDIS is automatically selected if any of the detector names are IMAGE-PLATE-2, IMAGE-PLATE-3, or IMAGE-PLATE-4.</p></body></html>
-
-
- Add engineering constraints for:
-
-
-
- -
+
-
<html><head/><body><p>Add engineering constraints for certain instrument types. This may add extra parameters to the table.</p><p><br/></p><p>For example, for TARDIS, the distance between IMAGE-PLATE-2 and IMAGE-PLATE-4 must be within a certain range. If TARDIS is selected, a new parameter is added with default values for this distance.</p><p><br/></p><p>If the instrument type can be guessed, it will be selected automatically when the dialog first appears. For example, TARDIS is automatically selected if any of the detector names are IMAGE-PLATE-2, IMAGE-PLATE-3, or IMAGE-PLATE-4.</p></body></html>
@@ -81,23 +64,47 @@
- -
-
+
-
+
- <html><head/><body><p>The center of rotation to be used for tilt parameters when relative constraints are enabled.</p><p><br/></p><p>"Mean Instrument Center" will cause the panels to be rotated about the mean center of the detectors when the tilt is modified.</p><p><br/></p><p>"Origin" will cause the panels to be rotated about lab origin (i. e., [0, 0, 0]) when the tilt is modified.</p></body></html>
+ <html><head/><body><p>Add engineering constraints for certain instrument types. This may add extra parameters to the table.</p><p><br/></p><p>For example, for TARDIS, the distance between IMAGE-PLATE-2 and IMAGE-PLATE-4 must be within a certain range. If TARDIS is selected, a new parameter is added with default values for this distance.</p><p><br/></p><p>If the instrument type can be guessed, it will be selected automatically when the dialog first appears. For example, TARDIS is automatically selected if any of the detector names are IMAGE-PLATE-2, IMAGE-PLATE-3, or IMAGE-PLATE-4.</p></body></html>
- Tilt center of rotation:
+ Add engineering constraints for:
- -
+
-
+
+
+ <html><head/><body><p>Options to set relative constraints between the detectors.</p><p><br/></p><p>"None" means no relative constraints.</p><p><br/></p><p>"System" means all detectors are relatively constrained to one another. In this case, the mean center of the detectors and a mean tilt may be refined.</p></body></html>
+
+
+ Relative constraints:
+
+
+
+ -
<html><head/><body><p>The center of rotation to be used for tilt parameters when relative constraints are enabled.</p><p><br/></p><p>"Mean Instrument Center" will cause the panels to be rotated about the mean center of the detectors when the tilt is modified.</p><p><br/></p><p>"Origin" will cause the panels to be rotated about lab origin (i. e., [0, 0, 0]) when the tilt is modified.</p></body></html>
+ -
+
+
+ Use delta for boundaries
+
+
+
+ -
+
+
+ Reset Relative Params to Zero
+
+
+
@@ -501,6 +508,7 @@ See scipy.optimize.least_squares for more details.
active_beam
show_picks_from_all_xray_sources
relative_constraints
+ reset_relative_params_to_zero
tilt_center_of_rotation
engineering_constraints
delta_boundaries