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

Mask with NaNs in the raw view as well #1558

Merged
merged 4 commits into from
Oct 11, 2023
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: 2 additions & 0 deletions hexrd/ui/calibration/panel_buffer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def on_accepted(self):

if self.update_config():
self.accepted.emit()
HexrdConfig().rerender_needed.emit()
self.finished.emit(self.ui.result())

def on_rejected(self):
Expand Down Expand Up @@ -211,6 +212,7 @@ def clear_panel_buffer(self):
# Clear the config options on the internal config
self.detector_config['buffer'] = self.default_buffer
self.update_enable_states()
HexrdConfig().rerender_needed.emit()

@property
def default_buffer(self):
Expand Down
29 changes: 28 additions & 1 deletion hexrd/ui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,39 @@ def raw_masks_dict(self):

@property
def masked_images_dict(self):
return self.create_masked_images_dict()

def create_masked_images_dict(self, fill_value=0):
"""Get an images dict where masks have been applied"""
from hexrd.ui.create_hedm_instrument import create_hedm_instrument

images_dict = self.images_dict
instr = create_hedm_instrument()

has_masks = bool(self.visible_masks)
has_panel_buffers = any(panel.panel_buffer is not None
for panel in instr.detectors.values())

if not has_masks and not has_panel_buffers:
# Force a fill_value of 0 if there are no visible masks
# and no panel buffers.
fill_value = 0

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

for name, img in images_dict.items():
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] = 0
img[~mask] = fill_value

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

return images_dict

Expand Down
2 changes: 1 addition & 1 deletion hexrd/ui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def load_images(self, image_names):
def unscaled_image_dict(self):
# Returns a dict of the unscaled images
if self.mode == ViewType.raw:
return HexrdConfig().masked_images_dict
return HexrdConfig().create_masked_images_dict(fill_value=np.nan)
else:
# Masks are already applied...
return {'img': self.iviewer.img}
Expand Down
Loading