Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements to raw view loading #1679

Merged
merged 3 commits into from
Mar 28, 2024
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
29 changes: 15 additions & 14 deletions hexrdgui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,13 @@ def images_dict(self):

@property
def raw_masks_dict(self):
return self.create_raw_masks_dict(display=False)
return self.create_raw_masks_dict(self.images_dict, display=False)

def create_raw_masks_dict(self, display=False):
def create_raw_masks_dict(self, images_dict, display=False):
"""Get a masks dict"""
from hexrdgui.masking.mask_manager import MaskManager
masks_dict = {}
for name, img in self.images_dict.items():
psavery marked this conversation as resolved.
Show resolved Hide resolved
for name, img in images_dict.items():
final_mask = np.ones(img.shape, dtype=bool)
for mask in MaskManager().masks.values():
if display and not mask.visible:
Expand Down Expand Up @@ -940,22 +940,23 @@ def create_masked_images_dict(self, fill_value=0, display=False):
# and no panel buffers.
fill_value = 0

raw_masks_dict = self.create_raw_masks_dict(display=display)
raw_masks_dict = self.create_raw_masks_dict(images_dict,
display=display)
for det, mask in raw_masks_dict.items():
img = images_dict[det]
if has_panel_buffers:
panel = instr.detectors[det]
utils.convert_panel_buffer_to_2d_array(panel)

for name, img in images_dict.items():
psavery marked this conversation as resolved.
Show resolved Hide resolved
if (np.issubdtype(type(fill_value), np.floating) and
not np.issubdtype(img.dtype, np.floating)):
img = img.astype(float)
images_dict[name] = img
if det == name:
img[~mask] = fill_value

if has_panel_buffers:
img[~panel.panel_buffer] = fill_value
if (np.issubdtype(type(fill_value), np.floating) and
not np.issubdtype(img.dtype, np.floating)):
img = img.astype(float)
images_dict[det] = img

img[~mask] = fill_value

if has_panel_buffers:
img[~panel.panel_buffer] = fill_value

return images_dict

Expand Down
19 changes: 13 additions & 6 deletions hexrdgui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,16 @@ def load_images(self, image_names):
img = images_dict[name]
self.axes_images[i].set_data(img)

# Create a computed version for the images dict
computed_images_dict = self.scaled_image_dict
if HexrdConfig().stitch_raw_roi_images:
computed_images_dict = self.iviewer.raw_images_to_stitched(
image_names, computed_images_dict)
if MaskManager().contains_border_only_masks:
# Create a computed version for the images dict
computed_images_dict = self.scaled_image_dict
if HexrdConfig().stitch_raw_roi_images:
computed_images_dict = self.iviewer.raw_images_to_stitched(
image_names, computed_images_dict)
else:
# The computed image is the same as the display image.
# Save some computation time for faster rendering.
computed_images_dict = images_dict

self.raw_view_images_dict = computed_images_dict
for name, axis in self.raw_axes.items():
Expand Down Expand Up @@ -637,7 +642,9 @@ def update_overlays(self):
return

self.remove_all_overlay_artists()
if not HexrdConfig().show_overlays:
if not HexrdConfig().show_overlays or not HexrdConfig().overlays:
# Avoid proceeding if possible, as updating the blit manager
# can be time consuming.
self.remove_all_overlay_artists()
self.draw_idle()
return
Expand Down
8 changes: 8 additions & 0 deletions hexrdgui/masking/mask_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ def update_mask_visibility(self, name, visibility):
def update_border_visibility(self, name, visibility):
self.masks[name].update_border_visibility(visibility)

@property
def contains_border_only_masks(self):
# If we have any border-only masks, that means the display images
# are different from computed images, and require extra computation.
# If this returns False, we can skip that extra computation and
# set display images and computed images to be the same.
return any(x.show_border and not x.visible for x in self.masks)

def threshold_toggled(self):
if self.threshold_mask:
self.remove_mask(self.threshold_mask.name)
Expand Down
Loading