Skip to content

Commit

Permalink
Merge pull request #1762 from HEXRD/restore-grain-settings
Browse files Browse the repository at this point in the history
HEDM Calibration: restore grain settings
  • Loading branch information
psavery authored Dec 11, 2024
2 parents 8aa9dfc + 78dcf2c commit 83cd7ae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
60 changes: 57 additions & 3 deletions hexrdgui/calibration/hedm/calibration_options_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def on_accepted(self):
self.accepted.emit()

def on_rejected(self):
self.restore_cached_overlay_properties()
self.refinements_editor.ui.hide()
self.rejected.emit()

def validate(self):
Expand Down Expand Up @@ -301,6 +303,10 @@ def on_refinements_editor_modified(self):
# Trigger an update to the config
self.refinements_editor.update_config()

# Restore all cached overlay properties
self.restore_cached_overlay_properties()
self.update_refinements_editor()

@property
def selected_material(self) -> str:
return self.ui.material.currentText()
Expand Down Expand Up @@ -451,12 +457,20 @@ def perform_updates():
HexrdConfig().update_overlay_editor.emit()
HexrdConfig().update_instrument_toolbox.emit()

# Before anything else, restore cached properties (in case
# they were unchecked).
self.restore_cached_overlay_properties()

# First, apply strain settings
for overlay in self.active_overlays:
refinements = overlay.refinements
crystal_params = overlay.crystal_params
if self.fix_strain:
crystal_params[6:] = cnst.identity_6x1
if not np.allclose(crystal_params[6:], cnst.identity_6x1):
# Store the strain in case we want to use it again
overlay._cached_strain = crystal_params[6:].copy()
crystal_params[6:] = cnst.identity_6x1

for i in range(6, len(refinements)):
refinements[i] = False
elif not self.custom_refinements:
Expand All @@ -482,11 +496,18 @@ def perform_updates():
if idx == 0:
# First grain may be affected by refinement choices
if self.fix_grain_centroid:
crystal_params[3:6] = cnst.zeros_3
if not np.allclose(crystal_params[3:6], cnst.zeros_3):
overlay._cached_pos = crystal_params[3:6].copy()
crystal_params[3:6] = cnst.zeros_3

for i in range(3, 6):
refinements[i] = False
elif self.fix_grain_y:
crystal_params[4] = 0
if not np.isclose(crystal_params[4], 0):
# Store the grain y in case we want to use it again
overlay._cached_pos_y = crystal_params[4]
crystal_params[4] = 0

refinements[4] = False

def recursive_set_refinable(cur, b):
Expand Down Expand Up @@ -519,6 +540,39 @@ def recursive_set_refinable(cur, b):
# Now trigger updates everywhere
perform_updates()

def restore_cached_overlay_properties(self):
for overlay in self.active_overlays:
crystal_params = overlay.crystal_params
reset_cached_strain = (
not self.fix_strain and
np.allclose(crystal_params[6:], cnst.identity_6x1) and
hasattr(overlay, '_cached_strain')
)
if reset_cached_strain:
# It must have been unchecked. Restore the previous strain.
crystal_params[6:] = overlay._cached_strain
del overlay._cached_strain

reset_cached_pos_y = (
not self.fix_grain_y and
np.isclose(crystal_params[4], 0) and
hasattr(overlay, '_cached_pos_y')
)
if reset_cached_pos_y:
# The setting must have been changed. Restore the previous.
crystal_params[4] = overlay._cached_pos_y
del overlay._cached_pos_y

reset_cached_pos = (
not self.fix_grain_centroid and
np.allclose(crystal_params[3:6], cnst.zeros_3) and
hasattr(overlay, '_cached_pos')
)
if reset_cached_pos:
# The setting must have been changed. Restore the previous.
crystal_params[3:6] = overlay._cached_pos
del overlay._cached_pos

def view_refinements(self):
self.update_refinements_editor()
self.refinements_editor.ui.show()
Expand Down
2 changes: 1 addition & 1 deletion hexrdgui/resources/ui/hedm_calibration_options_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<string>Assume calibration grains strain-free</string>
</property>
<property name="checked">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
Expand Down

0 comments on commit 83cd7ae

Please sign in to comment.