From 7569db0431f739c3743ba8f5e7b08244eb633925 Mon Sep 17 00:00:00 2001 From: Brianna Major Date: Tue, 10 Oct 2023 11:39:06 -0400 Subject: [PATCH] Replace masked_images_dict with create_masked_images_dict 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 --- hexrd/ui/calibration/auto/powder_runner.py | 2 +- hexrd/ui/calibration/calibration_runner.py | 6 +++--- hexrd/ui/calibration/stereo_plot.py | 2 +- hexrd/ui/hexrd_config.py | 10 +++++++--- hexrd/ui/image_canvas.py | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) 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..215de8202 100644 --- a/hexrd/ui/hexrd_config.py +++ b/hexrd/ui/hexrd_config.py @@ -890,14 +890,18 @@ 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 + img[~mask] = fill_value 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}