Skip to content

Commit

Permalink
Replace masked_images_dict with create_masked_images_dict
Browse files Browse the repository at this point in the history
The default behavior of create_masked_images_dict is the same as
masked_images_dict, but with the additional option to set the fill value for
the mask. If the fill type and mask type do not match the image will be cast to
the correct type.

Signed-off-by: Brianna Major <[email protected]>
  • Loading branch information
bnmajor committed Oct 10, 2023
1 parent bae82d7 commit 7deb855
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hexrd/ui/calibration/auto/powder_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _run(self):
fwhm_estimate = options['initial_fwhm']

# Get an intensity-corrected masked dict of the images
img_dict = HexrdConfig().masked_images_dict
img_dict = HexrdConfig().create_masked_images_dict()

statuses = self.refinement_flags_without_overlays
self.cf = statuses
Expand Down
6 changes: 3 additions & 3 deletions hexrd/ui/calibration/calibration_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def run_calibration(self):
flags = HexrdConfig().get_statuses_instrument_format()
instr.calibration_flags = flags

img_dict = HexrdConfig().masked_images_dict
img_dict = HexrdConfig().create_masked_images_dict()

instr_calibrator = run_calibration(picks, instr, img_dict, materials)
self.write_instrument_to_hexrd_config(instr)
Expand Down Expand Up @@ -753,7 +753,7 @@ def auto_pick_powder_points(self):
options = HexrdConfig().config['calibration']['powder']
self.instr = create_hedm_instrument()

img_dict = HexrdConfig().masked_images_dict
img_dict = HexrdConfig().create_masked_images_dict()

statuses = HexrdConfig().get_statuses_instrument_format()
self.instr.calibration_flags = statuses
Expand Down Expand Up @@ -835,7 +835,7 @@ def auto_pick_laue_spots(self):
self.async_runner.run(self.run_auto_laue_pick)

def run_auto_laue_pick(self):
img_dict = HexrdConfig().masked_images_dict
img_dict = HexrdConfig().create_masked_images_dict()

# These are the options the user chose earlier...
options = HexrdConfig().config['calibration']['laue_auto_picker']
Expand Down
2 changes: 1 addition & 1 deletion hexrd/ui/calibration/stereo_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def extent(self):

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

@property
def stereo_size(self):
Expand Down
13 changes: 10 additions & 3 deletions hexrd/ui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,21 @@ def raw_masks_dict(self):

return masks_dict

@property
def masked_images_dict(self):
def create_masked_images_dict(self, fill_value=0):
"""Get an images dict where masks have been applied"""
images_dict = self.images_dict
have_masks = len(self.visible_masks)
for det, mask in self.raw_masks_dict.items():
for name, img in images_dict.items():
if (have_masks and
np.issubdtype(type(fill_value), np.floating) and
not np.issubdtype(img.dtype, np.floating)):
img = img.astype(float)
if det == name:
img[~mask] = 0
# Masks always exist but may not be masking any regions out.
# Only use the fill value if any of the masks are
# actually being applied (visible masks).
img[~mask] = fill_value if have_masks else 0

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 7deb855

Please sign in to comment.