Skip to content

Commit 5dda08f

Browse files
committed
Refactor HEDM calibration for short-term changes
We eventually want to use features from our main calibration workflows, such as the "undo" button, and the relative constraints. However, we need to make short-term updates to the HEDM calibration workflow. This makes several changes, including allowing users to see how the refinement options get changed with different refinement settings, allowing users to select grains to be used, and allowing users to see and set all parameters used as input for `pull_spots()`. Fixes: #1741 Signed-off-by: Patrick Avery <[email protected]>
1 parent 935c43b commit 5dda08f

14 files changed

+770
-167
lines changed

hexrdgui/calibration/hedm/calibration_options_dialog.py

Lines changed: 453 additions & 33 deletions
Large diffs are not rendered by default.

hexrdgui/calibration/hedm/calibration_runner.py

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,15 @@ def clear(self):
4747
def run(self):
4848
self.clear()
4949
self.pre_validate()
50-
self.synchronize_omega_period()
5150

5251
# Create the grains table
53-
shape = (self.num_active_overlays, 21)
54-
self.grains_table = np.empty(shape, dtype=np.float64)
55-
56-
gw = instrument.GrainDataWriter(array=self.grains_table)
57-
for i, overlay in enumerate(self.active_overlays):
58-
gw.dump_grain(i, 1, 0, overlay.crystal_params)
52+
if self.num_active_overlays > 0:
53+
material = self.material
54+
else:
55+
material = HexrdConfig().active_material
5956

6057
kwargs = {
61-
'material': self.material,
62-
'grains_table': self.grains_table,
58+
'material': material,
6359
'parent': self.parent,
6460
}
6561
dialog = HEDMCalibrationOptionsDialog(**kwargs)
@@ -70,13 +66,16 @@ def run(self):
7066
def on_options_dialog_accepted(self):
7167
dialog = self.options_dialog
7268

69+
shape = (self.num_active_overlays, 21)
70+
self.grains_table = np.empty(shape, dtype=np.float64)
71+
gw = instrument.GrainDataWriter(array=self.grains_table)
72+
for i, overlay in enumerate(self.active_overlays):
73+
gw.dump_grain(i, 1, 0, overlay.crystal_params)
74+
75+
self.synchronize_omega_period()
76+
7377
# Grab some selections from the dialog
7478
self.do_refit = dialog.do_refit
75-
self.clobber_strain = dialog.clobber_strain
76-
self.clobber_centroid = dialog.clobber_centroid
77-
self.clobber_grain_Y = dialog.clobber_grain_Y
78-
79-
self.clobber_refinements()
8079
self.run_calibration()
8180

8281
def run_calibration(self):
@@ -99,9 +98,6 @@ def on_pull_spots_finished(self, spots_data_dict):
9998

10099
# User selected these from the dialog
101100
do_refit = self.do_refit
102-
clobber_strain = self.clobber_strain
103-
clobber_centroid = self.clobber_centroid
104-
clobber_grain_Y = self.clobber_grain_Y
105101

106102
# Our grains table only contains the grains that the user
107103
# selected.
@@ -118,15 +114,6 @@ def on_pull_spots_finished(self, spots_data_dict):
118114
ome_period = self.ome_period
119115

120116
grain_parameters = grain_parameters.copy()
121-
if clobber_strain:
122-
for grain in grain_parameters:
123-
grain[6:] = cnst.identity_6x1
124-
if clobber_centroid:
125-
for grain in grain_parameters:
126-
grain[3:6] = cnst.zeros_3
127-
if clobber_grain_Y:
128-
for grain in grain_parameters:
129-
grain[4] = 0.
130117
ngrains = len(grain_parameters)
131118

132119
# The styles we will use for plotting points
@@ -472,28 +459,6 @@ def material(self):
472459
def active_overlay_refinements(self):
473460
return [x.refinements for x in self.active_overlays]
474461

475-
def clobber_refinements(self):
476-
any_clobbering = (
477-
self.clobber_strain or
478-
self.clobber_centroid or
479-
self.clobber_grain_Y
480-
)
481-
if not any_clobbering:
482-
return
483-
484-
for overlay in self.active_overlays:
485-
refinements = overlay.refinements
486-
if self.clobber_strain:
487-
for i in range(6, len(refinements)):
488-
refinements[i] = False
489-
if self.clobber_centroid:
490-
for i in range(3, 6):
491-
refinements[i] = False
492-
if self.clobber_grain_Y:
493-
refinements[4] = False
494-
495-
HexrdConfig().update_overlay_editor.emit()
496-
497462
def synchronize_material(self):
498463
# This material is used for creating the indexing config.
499464
# Make sure it matches the material we are using.
@@ -509,8 +474,8 @@ def synchronize_omega_period(self):
509474
def pre_validate(self):
510475
# Validation to perform before we do anything else
511476
if not self.active_overlays:
512-
msg = 'There must be at least one visible rotation series overlay'
513-
raise Exception(msg)
477+
# No more validation needed.
478+
return
514479

515480
ome_periods = []
516481
for overlay in self.active_overlays:
@@ -539,10 +504,6 @@ def pre_validate(self):
539504
)
540505
raise Exception(msg)
541506

542-
if not np.any(self.all_flags):
543-
msg = 'There are no refinable parameters'
544-
raise Exception(msg)
545-
546507
# Make sure the material is updated in the indexing config
547508
self.synchronize_material()
548509

hexrdgui/hexrd_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,15 @@ class HexrdConfig(QObject, metaclass=QSingleton):
194194
"""Indicate that the state was loaded..."""
195195
state_loaded = Signal()
196196

197+
"""Indicate that the overlay manager should update its table"""
198+
update_overlay_manager = Signal()
199+
197200
"""Indicate that the overlay editor should update its GUI"""
198201
update_overlay_editor = Signal()
199202

203+
"""Indicate that the main window should update it's instrument toolbox"""
204+
update_instrument_toolbox = Signal()
205+
200206
"""Indicate that the beam marker has been modified"""
201207
beam_marker_modified = Signal()
202208

hexrdgui/image_canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ def beam_vector_changed(self):
894894
# Right now, hexrd doesn't want this to be inf.
895895
# Maybe that will change in the future...
896896
self.iviewer.instr.source_distance = (
897-
beam_config['source_distance']['value'],
897+
beam_config['source_distance']['value']
898898
)
899899

900900
self.update_overlays()

hexrdgui/main_window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ def setup_connections(self):
332332
self.update_drawn_mask_line_picker_canvas)
333333
HexrdConfig().tab_images_changed.connect(
334334
self.update_mask_region_canvas)
335+
HexrdConfig().update_instrument_toolbox.connect(
336+
self.update_config_gui)
335337

336338
ImageLoadManager().update_needed.connect(self.update_all)
337339
ImageLoadManager().new_images_loaded.connect(self.new_images_loaded)

hexrdgui/overlay_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def setup_connections(self):
4747
self.ui.add_button.pressed.connect(self.add)
4848
self.ui.remove_button.pressed.connect(self.remove)
4949
self.ui.edit_style_button.pressed.connect(self.edit_style)
50+
HexrdConfig().update_overlay_manager.connect(self.update_table)
5051
HexrdConfig().update_overlay_editor.connect(self.update_overlay_editor)
5152
HexrdConfig().materials_added.connect(self.update_table)
5253
HexrdConfig().material_renamed.connect(self.on_material_renamed)

hexrdgui/overlays/rotation_series_overlay.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class RotationSeriesOverlay(Overlay):
2020

2121
def __init__(self, material_name, crystal_params=None, eta_ranges=None,
2222
ome_ranges=None, ome_period=None, aggregated=True,
23-
ome_width=np.radians(5.0).item(), tth_width=None,
24-
eta_width=None, sync_ome_period=True, sync_ome_ranges=True,
25-
**overlay_kwargs):
23+
ome_width=np.radians(1.5).item(),
24+
tth_width=np.radians(0.25).item(),
25+
eta_width=np.radians(1.0).item(),
26+
sync_ome_period=True, sync_ome_ranges=True, **overlay_kwargs):
2627
super().__init__(material_name, **overlay_kwargs)
2728

2829
if crystal_params is None:

hexrdgui/refinements_editor.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, parent=None):
2929

3030
self.ui.tree_view_layout.addWidget(self.tree_view)
3131

32+
self._hide_bottom_buttons = False
3233
self.iconfig_values_modified = False
3334
self.material_values_modified = False
3435

@@ -43,6 +44,17 @@ def setup_connections(self):
4344
self.ui.button_box.accepted.connect(self.ui.accept)
4445
self.ui.button_box.rejected.connect(self.ui.reject)
4546

47+
@property
48+
def hide_bottom_buttons(self):
49+
return self._hide_bottom_buttons
50+
51+
@hide_bottom_buttons.setter
52+
def hide_bottom_buttons(self, b):
53+
self._hide_bottom_buttons = b
54+
55+
self.ui.reset.setVisible(not b)
56+
self.ui.button_box.setVisible(not b)
57+
4658
def reset_dict(self):
4759
config = {}
4860
config['instrument'] = self.create_instrument_dict()
@@ -65,7 +77,7 @@ def create_instrument_dict(self):
6577
# Recurse through it, setting all status keys and renaming them to
6678
# "_refinable".
6779
blacklisted = ['saturation_level', 'buffer', 'pixels', 'id',
68-
'source_distance']
80+
'source_distance', 'detector_type']
6981

7082
def recurse(cur, idict):
7183
if 'status' in cur:
@@ -98,7 +110,7 @@ def recurse(cur, idict):
98110

99111
def create_materials_dict(self):
100112
mdict = {}
101-
for overlay in self.overlays:
113+
for overlay in self.visible_overlays:
102114
name = overlay.name
103115
values = refinement_values(overlay)
104116
if not values:
@@ -152,7 +164,7 @@ def recurse(cur, idict):
152164

153165
def update_materials_config(self):
154166
mdict = self.dict['materials']
155-
for overlay in self.overlays:
167+
for overlay in self.visible_overlays:
156168
name = overlay.name
157169
refinements = []
158170
values = []
@@ -168,6 +180,10 @@ def update_materials_config(self):
168180
def overlays(self):
169181
return HexrdConfig().overlays
170182

183+
@property
184+
def visible_overlays(self):
185+
return [x for x in self.overlays if x.visible]
186+
171187
def setup_actions(self):
172188
labels = list(self.actions.keys())
173189
self.ui.action.clear()
@@ -180,6 +196,7 @@ def apply_action(self):
180196

181197
# Update the tree view
182198
self.update_tree_view()
199+
self.tree_view.dict_modified.emit()
183200

184201
@property
185202
def actions(self):
@@ -238,7 +255,7 @@ def powder_values():
238255
return ret
239256

240257
def laue_values():
241-
params = overlay.crystal_params
258+
params = copy.deepcopy(overlay.crystal_params)
242259
# These params should be in the same order as the refinements
243260
params[:3] = to_convention(params[:3])
244261
for i, label in enumerate(overlay.refinement_labels):

hexrdgui/resources/indexing/default_indexing_config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fit_grains:
147147

148148
# Some custom ones we have added for the GUI
149149
_hedm_calibration:
150-
do_refit: false
151-
clobber_strain: false
150+
do_refit: true
151+
clobber_strain: true
152+
clobber_grain_Y: true
152153
clobber_centroid: false
153-
clobber_grain_Y: false

0 commit comments

Comments
 (0)