Skip to content
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
486 changes: 453 additions & 33 deletions hexrdgui/calibration/hedm/calibration_options_dialog.py

Large diffs are not rendered by default.

69 changes: 15 additions & 54 deletions hexrdgui/calibration/hedm/calibration_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ def clear(self):
def run(self):
self.clear()
self.pre_validate()
self.synchronize_omega_period()

# Create the grains table
shape = (self.num_active_overlays, 21)
self.grains_table = np.empty(shape, dtype=np.float64)

gw = instrument.GrainDataWriter(array=self.grains_table)
for i, overlay in enumerate(self.active_overlays):
gw.dump_grain(i, 1, 0, overlay.crystal_params)
if self.num_active_overlays > 0:
material = self.material
else:
material = HexrdConfig().active_material

kwargs = {
'material': self.material,
'grains_table': self.grains_table,
'material': material,
'parent': self.parent,
}
dialog = HEDMCalibrationOptionsDialog(**kwargs)
Expand All @@ -70,13 +66,16 @@ def run(self):
def on_options_dialog_accepted(self):
dialog = self.options_dialog

shape = (self.num_active_overlays, 21)
self.grains_table = np.empty(shape, dtype=np.float64)
gw = instrument.GrainDataWriter(array=self.grains_table)
for i, overlay in enumerate(self.active_overlays):
gw.dump_grain(i, 1, 0, overlay.crystal_params)

self.synchronize_omega_period()

# Grab some selections from the dialog
self.do_refit = dialog.do_refit
self.clobber_strain = dialog.clobber_strain
self.clobber_centroid = dialog.clobber_centroid
self.clobber_grain_Y = dialog.clobber_grain_Y

self.clobber_refinements()
self.run_calibration()

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

# User selected these from the dialog
do_refit = self.do_refit
clobber_strain = self.clobber_strain
clobber_centroid = self.clobber_centroid
clobber_grain_Y = self.clobber_grain_Y

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

grain_parameters = grain_parameters.copy()
if clobber_strain:
for grain in grain_parameters:
grain[6:] = cnst.identity_6x1
if clobber_centroid:
for grain in grain_parameters:
grain[3:6] = cnst.zeros_3
if clobber_grain_Y:
for grain in grain_parameters:
grain[4] = 0.
ngrains = len(grain_parameters)

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

def clobber_refinements(self):
any_clobbering = (
self.clobber_strain or
self.clobber_centroid or
self.clobber_grain_Y
)
if not any_clobbering:
return

for overlay in self.active_overlays:
refinements = overlay.refinements
if self.clobber_strain:
for i in range(6, len(refinements)):
refinements[i] = False
if self.clobber_centroid:
for i in range(3, 6):
refinements[i] = False
if self.clobber_grain_Y:
refinements[4] = False

HexrdConfig().update_overlay_editor.emit()

def synchronize_material(self):
# This material is used for creating the indexing config.
# Make sure it matches the material we are using.
Expand All @@ -509,8 +474,8 @@ def synchronize_omega_period(self):
def pre_validate(self):
# Validation to perform before we do anything else
if not self.active_overlays:
msg = 'There must be at least one visible rotation series overlay'
raise Exception(msg)
# No more validation needed.
return

ome_periods = []
for overlay in self.active_overlays:
Expand Down Expand Up @@ -539,10 +504,6 @@ def pre_validate(self):
)
raise Exception(msg)

if not np.any(self.all_flags):
msg = 'There are no refinable parameters'
raise Exception(msg)

# Make sure the material is updated in the indexing config
self.synchronize_material()

Expand Down
6 changes: 6 additions & 0 deletions hexrdgui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,15 @@ class HexrdConfig(QObject, metaclass=QSingleton):
"""Indicate that the state was loaded..."""
state_loaded = Signal()

"""Indicate that the overlay manager should update its table"""
update_overlay_manager = Signal()

"""Indicate that the overlay editor should update its GUI"""
update_overlay_editor = Signal()

"""Indicate that the main window should update it's instrument toolbox"""
update_instrument_toolbox = Signal()

"""Indicate that the beam marker has been modified"""
beam_marker_modified = Signal()

Expand Down
2 changes: 1 addition & 1 deletion hexrdgui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def beam_vector_changed(self):
# Right now, hexrd doesn't want this to be inf.
# Maybe that will change in the future...
self.iviewer.instr.source_distance = (
beam_config['source_distance']['value'],
beam_config['source_distance']['value']
)

self.update_overlays()
Expand Down
2 changes: 2 additions & 0 deletions hexrdgui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ def setup_connections(self):
self.update_drawn_mask_line_picker_canvas)
HexrdConfig().tab_images_changed.connect(
self.update_mask_region_canvas)
HexrdConfig().update_instrument_toolbox.connect(
self.update_config_gui)

ImageLoadManager().update_needed.connect(self.update_all)
ImageLoadManager().new_images_loaded.connect(self.new_images_loaded)
Expand Down
1 change: 1 addition & 0 deletions hexrdgui/overlay_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setup_connections(self):
self.ui.add_button.pressed.connect(self.add)
self.ui.remove_button.pressed.connect(self.remove)
self.ui.edit_style_button.pressed.connect(self.edit_style)
HexrdConfig().update_overlay_manager.connect(self.update_table)
HexrdConfig().update_overlay_editor.connect(self.update_overlay_editor)
HexrdConfig().materials_added.connect(self.update_table)
HexrdConfig().material_renamed.connect(self.on_material_renamed)
Expand Down
7 changes: 4 additions & 3 deletions hexrdgui/overlays/rotation_series_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class RotationSeriesOverlay(Overlay):

def __init__(self, material_name, crystal_params=None, eta_ranges=None,
ome_ranges=None, ome_period=None, aggregated=True,
ome_width=np.radians(5.0).item(), tth_width=None,
eta_width=None, sync_ome_period=True, sync_ome_ranges=True,
**overlay_kwargs):
ome_width=np.radians(1.5).item(),
tth_width=np.radians(0.25).item(),
eta_width=np.radians(1.0).item(),
sync_ome_period=True, sync_ome_ranges=True, **overlay_kwargs):
super().__init__(material_name, **overlay_kwargs)

if crystal_params is None:
Expand Down
25 changes: 21 additions & 4 deletions hexrdgui/refinements_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, parent=None):

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

self._hide_bottom_buttons = False
self.iconfig_values_modified = False
self.material_values_modified = False

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

@property
def hide_bottom_buttons(self):
return self._hide_bottom_buttons

@hide_bottom_buttons.setter
def hide_bottom_buttons(self, b):
self._hide_bottom_buttons = b

self.ui.reset.setVisible(not b)
self.ui.button_box.setVisible(not b)

def reset_dict(self):
config = {}
config['instrument'] = self.create_instrument_dict()
Expand All @@ -65,7 +77,7 @@ def create_instrument_dict(self):
# Recurse through it, setting all status keys and renaming them to
# "_refinable".
blacklisted = ['saturation_level', 'buffer', 'pixels', 'id',
'source_distance']
'source_distance', 'detector_type']

def recurse(cur, idict):
if 'status' in cur:
Expand Down Expand Up @@ -98,7 +110,7 @@ def recurse(cur, idict):

def create_materials_dict(self):
mdict = {}
for overlay in self.overlays:
for overlay in self.visible_overlays:
name = overlay.name
values = refinement_values(overlay)
if not values:
Expand Down Expand Up @@ -152,7 +164,7 @@ def recurse(cur, idict):

def update_materials_config(self):
mdict = self.dict['materials']
for overlay in self.overlays:
for overlay in self.visible_overlays:
name = overlay.name
refinements = []
values = []
Expand All @@ -168,6 +180,10 @@ def update_materials_config(self):
def overlays(self):
return HexrdConfig().overlays

@property
def visible_overlays(self):
return [x for x in self.overlays if x.visible]

def setup_actions(self):
labels = list(self.actions.keys())
self.ui.action.clear()
Expand All @@ -180,6 +196,7 @@ def apply_action(self):

# Update the tree view
self.update_tree_view()
self.tree_view.dict_modified.emit()

@property
def actions(self):
Expand Down Expand Up @@ -238,7 +255,7 @@ def powder_values():
return ret

def laue_values():
params = overlay.crystal_params
params = copy.deepcopy(overlay.crystal_params)
# These params should be in the same order as the refinements
params[:3] = to_convention(params[:3])
for i, label in enumerate(overlay.refinement_labels):
Expand Down
6 changes: 3 additions & 3 deletions hexrdgui/resources/indexing/default_indexing_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fit_grains:

# Some custom ones we have added for the GUI
_hedm_calibration:
do_refit: false
clobber_strain: false
do_refit: true
clobber_strain: true
clobber_grain_Y: true
clobber_centroid: false
clobber_grain_Y: false
Loading
Loading