Skip to content

Commit

Permalink
Merge pull request #1558 from bnmajor/raw-nans
Browse files Browse the repository at this point in the history
Mask with NaNs in the raw view as well
  • Loading branch information
bnmajor authored Oct 11, 2023
2 parents bae82d7 + ac4a229 commit 196ead7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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

0 comments on commit 196ead7

Please sign in to comment.