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
2 changes: 1 addition & 1 deletion hexrdgui/calibration/auto/powder_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def on_finished():
def save_picks_to_file(self, selected_file):
# Reuse the same logic from the HKLPicksTreeViewDialog
dialog = self.create_hkl_picks_tree_view_dialog()
dialog.export_picks(selected_file)
dialog.export_picks_from_overlays(selected_file, self.overlays)

def load_picks_from_file(self, selected_file):
# Reuse the same logic from the HKLPicksTreeViewDialog
Expand Down
28 changes: 24 additions & 4 deletions hexrdgui/calibration/calibration_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import contextmanager
import copy
from functools import partial
import itertools
Expand Down Expand Up @@ -519,9 +520,14 @@ def restore_overlay_visibilities(self):
HexrdConfig().overlay_config_changed.emit()

def set_highlighting(self, highlighting):
self.active_overlay.highlights = highlighting
HexrdConfig().flag_overlay_updates_for_all_materials()
HexrdConfig().overlay_config_changed.emit()
# Disable the zoom canvas to prevent the highlight from
# strangely switching back and forth (which is just caused
# by the fact that we did not re-use the canvas's blit manager
# for the zoom box blitting - we probably should).
with zoom_canvas_disabled(self.line_picker):
self.active_overlay.highlights = highlighting
HexrdConfig().flag_overlay_updates_for_all_materials()
HexrdConfig().overlay_config_changed.emit()

def remove_all_highlighting(self):
for overlay in self.overlays:
Expand Down Expand Up @@ -1039,10 +1045,24 @@ def on_finished():

def save_picks_to_file(self, selected_file):
# Reuse the same logic from the HKLPicksTreeViewDialog
self.edit_picks_dialog.export_picks(selected_file)
d = self.edit_picks_dialog
d.export_picks_from_overlays(selected_file, self.overlays)

def load_picks_from_file(self, selected_file):
# Reuse the same logic from the HKLPicksTreeViewDialog
dialog = self.edit_picks_dialog
dialog.import_picks(selected_file)
return dialog.dictionary


@contextmanager
def zoom_canvas_disabled(line_picker):
if line_picker:
prev = line_picker.zoom_canvas.disabled
line_picker.zoom_canvas.disabled = True

try:
yield
finally:
if line_picker:
line_picker.zoom_canvas.disabled = prev
61 changes: 45 additions & 16 deletions hexrdgui/calibration/hkl_picks_tree_view_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from hexrdgui.ui_loader import UiLoader
from hexrdgui.utils.conversions import angles_to_cart, cart_to_angles
from hexrdgui.utils.dicts import ndarrays_to_lists
from hexrdgui.utils.tth_distortion import apply_tth_distortion_if_needed


class HKLPicksTreeViewDialog:
Expand Down Expand Up @@ -92,18 +93,28 @@ def export_picks_clicked(self):
return self.export_picks(selected_file)

def export_picks(self, filename):
return self._export_dict_to_file(filename, {
'angular': self.dictionary,
'cartesian': self.dict_with_cart_coords,
})

def export_picks_from_overlays(self, filename, overlays):
# Export picks from overlays using the same export logic as
# the regular dictionary.
return self._export_dict_to_file(filename, {
'angular': overlays_to_tree_format(overlays, polar=True),
'cartesian': overlays_to_tree_format(overlays, polar=False),
})

def _export_dict_to_file(self, filename: str, export_data: dict):
filename = Path(filename)

if filename.exists():
filename.unlink()

# unwrap_dict_to_h5 unfortunately modifies the data
# make a deep copy to avoid the modification.
export_data = {
'angular': copy.deepcopy(self.dictionary),
'cartesian': self.dict_with_cart_coords,
}

# unwrap_dict_to_h5 unfortunately modifies the data.
# Make a deep copy to avoid the modification.
export_data = copy.deepcopy(export_data)
with h5py.File(filename, 'w') as wf:
unwrap_dict_to_h5(wf, export_data)

Expand Down Expand Up @@ -178,7 +189,7 @@ def button_box_visible(self, b):
self.ui.button_box.setVisible(b)


def convert_picks(picks, conversion_function, **kwargs):
def convert_picks(picks, conversion_function):
instr = create_hedm_instrument()
ret = copy.deepcopy(picks)
for name, detectors in ret.items():
Expand All @@ -191,25 +202,43 @@ def convert_picks(picks, conversion_function, **kwargs):
# Avoid the runtime warning
hkls[hkl] = [np.nan, np.nan]
else:
hkls[hkl] = conversion_function([spot], panel,
**kwargs)[0]
hkls[hkl] = conversion_function([spot], panel)[0]
continue

# Must be powder
for hkl, line in hkls.items():
if len(line) != 0:
hkls[hkl] = conversion_function(line, panel, **kwargs)
hkls[hkl] = conversion_function(line, panel)

return ret


def picks_angles_to_cartesian(picks):
return convert_picks(picks, angles_to_cart)
# Create the conversion function
def func(angs, panel):
# Reverse the tth distortion first
angs = apply_tth_distortion_if_needed(
angs,
in_degrees=True,
reverse=True,
)
# Now convert to cart
return angles_to_cart(angs, panel)

return convert_picks(picks, func)


def picks_cartesian_to_angles(picks):
kwargs = {'eta_period': HexrdConfig().polar_res_eta_period}
return convert_picks(picks, cart_to_angles, **kwargs)
# Create the conversion function
eta_period = HexrdConfig().polar_res_eta_period

def func(xys, panel):
angs = cart_to_angles(xys, panel, eta_period=eta_period)

# Apply tth distortion now as well
return apply_tth_distortion_if_needed(angs, in_degrees=True)

return convert_picks(picks, func)


def generate_picks_results(overlays, polar=True):
Expand Down Expand Up @@ -249,8 +278,8 @@ def generate_picks_results(overlays, polar=True):
return pick_results


def overlays_to_tree_format(overlays):
picks = generate_picks_results(overlays)
def overlays_to_tree_format(overlays, polar=True):
picks = generate_picks_results(overlays, polar=polar)
return picks_to_tree_format(picks)


Expand Down
23 changes: 18 additions & 5 deletions hexrdgui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,11 +2586,9 @@ def set_intensity_subtract_minimum(self, v):
set_intensity_subtract_minimum)

@property
def any_intensity_corrections(self):
"""Are we to perform any intensity corrections on the images?"""

def _intensity_correction_names(self) -> list[str]:
# Add to the list here as needed
corrections = [
return [
'apply_pixel_solid_angle_correction',
'apply_polarization_correction',
'apply_lorentz_correction',
Expand All @@ -2599,7 +2597,22 @@ def any_intensity_corrections(self):
'apply_median_filter_correction',
]

return any(getattr(self, x) for x in corrections)
@property
def any_intensity_corrections(self):
"""Are we to perform any intensity corrections on the images?"""
return any(getattr(self, x) for x in self._intensity_correction_names)

def disable_all_intensity_corrections(self):
if not self.any_intensity_corrections:
# Nothing to do...
return

# Block our own signals as we disable all of these
with utils.block_signals(self):
for name in self._intensity_correction_names:
setattr(self, name, False)

self.deep_rerender_needed.emit()

def get_show_saturation_level(self):
return self._show_saturation_level
Expand Down
57 changes: 15 additions & 42 deletions hexrdgui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,6 @@ def overlay_draw_func(self, type):

return overlay_funcs[type]

def get_overlay_highlight_ids(self, overlay):
highlights = overlay.highlights
if not highlights:
return []

def recursive_get(cur, path):
for p in path:
cur = cur[p]
return cur

return [id(recursive_get(overlay.data, h)) for h in highlights]

def draw_overlay(self, overlay):
if not overlay.visible:
return
Expand All @@ -477,19 +465,19 @@ def draw_overlay(self, overlay):
# It's already present. Skip it.
return

# Keep track of any overlays we need to highlight
self.overlay_highlight_ids += self.get_overlay_highlight_ids(overlay)

type = overlay.type
style = overlay.style
highlight_style = overlay.highlight_style
self.overlay_axes_data(overlay)
for axis, det_key, data in self.overlay_axes_data(overlay):
highlights = [x[2] for x in overlay.highlights if x[0] == det_key]
kwargs = {
'artist_key': overlay.name,
'det_key': det_key,
'axis': axis,
'data': data,
'style': style,
'highlight_indices': highlights,
'highlight_style': highlight_style,
}
self.overlay_draw_func(type)(**kwargs)
Expand All @@ -498,10 +486,11 @@ def draw_overlay(self, overlay):
self.draw_azimuthal_powder_lines(overlay)

def draw_powder_overlay(self, artist_key, det_key, axis, data, style,
highlight_style):
highlight_indices, highlight_style):
rings = data['rings']
ranges = data['rbnds']
rbnd_indices = data['rbnd_indices']
ring_idx_map = data['ring_idx_map']

data_style = style['data']
ranges_style = style['ranges']
Expand All @@ -512,13 +501,6 @@ def draw_powder_overlay(self, artist_key, det_key, axis, data, style,
overlay_artists = self.overlay_artists.setdefault(artist_key, {})
artists = overlay_artists.setdefault(det_key, {})

highlight_indices = []

if self.overlay_highlight_ids:
# Split up highlighted and non-highlighted components for all
highlight_indices = [i for i, x in enumerate(rings)
if id(x) in self.overlay_highlight_ids]

def split(data):
if not highlight_indices or len(data) == 0:
return [], data
Expand All @@ -533,13 +515,18 @@ def split(data):
h_ranges = []
reg_ranges = []

highlight_indices_mapped = [ring_idx_map[i] for i in highlight_indices]

found = False
for i, ind in enumerate(rbnd_indices):
if len(ind) > 1:
merged_ranges.append(ranges[i])
found = True

if highlight_indices and any(x in highlight_indices for x in ind):
if (
highlight_indices and
any(x in highlight_indices_mapped for x in ind)
):
h_ranges.append(ranges[i])
found = True

Expand Down Expand Up @@ -620,7 +607,7 @@ def az_plot(data, key, kwargs):
az_plot(merged_ranges, 'merged_ranges', merged_ranges_style)

def draw_laue_overlay(self, artist_key, det_key, axis, data, style,
highlight_style):
highlight_indices, highlight_style):
spots = data['spots']
ranges = data['ranges']
labels = data['labels']
Expand All @@ -630,13 +617,6 @@ def draw_laue_overlay(self, artist_key, det_key, axis, data, style,
ranges_style = style['ranges']
label_style = style['labels']

highlight_indices = []

if self.overlay_highlight_ids:
# Split up highlighted and non-highlighted components for all
highlight_indices = [i for i, x in enumerate(spots)
if id(x) in self.overlay_highlight_ids]

def split(data):
if not highlight_indices or len(data) == 0:
return [], data
Expand Down Expand Up @@ -696,7 +676,8 @@ def plot_label(x, y, label, style):
artists['h_labels'].append(plot_label(x, y, label, style))

def draw_rotation_series_overlay(self, artist_key, det_key, axis, data,
style, highlight_style):
style, highlight_indices,
highlight_style):
is_aggregated = HexrdConfig().is_aggregated
ome_range = HexrdConfig().omega_ranges
aggregated = data['aggregated'] or is_aggregated or ome_range is None
Expand Down Expand Up @@ -741,20 +722,13 @@ def draw_rotation_series_overlay(self, artist_key, det_key, axis, data,
animated=True, **ranges_style)

def draw_const_chi_overlay(self, artist_key, det_key, axis, data, style,
highlight_style):
highlight_indices, highlight_style):
points = data['data']
data_style = style['data']

overlay_artists = self.overlay_artists.setdefault(artist_key, {})
artists = overlay_artists.setdefault(det_key, {})

highlight_indices = []

if self.overlay_highlight_ids:
# Split up highlighted and non-highlighted components for all
highlight_indices = [i for i, x in enumerate(points)
if id(x) in self.overlay_highlight_ids]

def split(data):
if not highlight_indices or len(data) == 0:
return [], data
Expand Down Expand Up @@ -807,7 +781,6 @@ def update_overlays(self):

self.iviewer.update_overlay_data()

self.overlay_highlight_ids = []
for overlay in HexrdConfig().overlays:
self.draw_overlay(overlay)

Expand Down
3 changes: 3 additions & 0 deletions hexrdgui/image_tab_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ def allocate_toolbars(self):
# The new one to add
idx = len(self.toolbars)
tb = NavigationToolbar(self.image_canvases[idx], parent, False)
tb.setVisible(False)
# Current detector
ims = self.ims_for_name(self.image_names[idx])
sb = ImageSeriesToolbar(ims, self)
ib = ImageSeriesInfoToolbar(self)
sb.set_visible(False)
ib.set_visible(False)

# This will put it at the bottom of the central widget
toolbar = QHBoxLayout()
Expand Down
Loading
Loading