diff --git a/hexrd/ui/calibration/auto/powder_runner.py b/hexrd/ui/calibration/auto/powder_runner.py index fc93f71ca..1cd4bbb8f 100644 --- a/hexrd/ui/calibration/auto/powder_runner.py +++ b/hexrd/ui/calibration/auto/powder_runner.py @@ -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 diff --git a/hexrd/ui/calibration/calibration_runner.py b/hexrd/ui/calibration/calibration_runner.py index ac02a985e..f44219cb1 100644 --- a/hexrd/ui/calibration/calibration_runner.py +++ b/hexrd/ui/calibration/calibration_runner.py @@ -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) @@ -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 @@ -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'] diff --git a/hexrd/ui/calibration/stereo_plot.py b/hexrd/ui/calibration/stereo_plot.py index e6b938e44..66bdbd462 100644 --- a/hexrd/ui/calibration/stereo_plot.py +++ b/hexrd/ui/calibration/stereo_plot.py @@ -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): diff --git a/hexrd/ui/hexrd_config.py b/hexrd/ui/hexrd_config.py index 3943ca804..4ede9f72e 100644 --- a/hexrd/ui/hexrd_config.py +++ b/hexrd/ui/hexrd_config.py @@ -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 diff --git a/hexrd/ui/image_canvas.py b/hexrd/ui/image_canvas.py index 406921107..a65e308f0 100644 --- a/hexrd/ui/image_canvas.py +++ b/hexrd/ui/image_canvas.py @@ -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}