diff --git a/hexrdgui/calibration/auto/powder_runner.py b/hexrdgui/calibration/auto/powder_runner.py index f07cc3b80..ab40ce737 100644 --- a/hexrdgui/calibration/auto/powder_runner.py +++ b/hexrdgui/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 = MaskManager().masked_images_dict statuses = self.refinement_flags_without_overlays self.cf = statuses diff --git a/hexrdgui/calibration/calibration_runner.py b/hexrdgui/calibration/calibration_runner.py index 440f1608d..af5208410 100644 --- a/hexrdgui/calibration/calibration_runner.py +++ b/hexrdgui/calibration/calibration_runner.py @@ -398,7 +398,7 @@ def run_calibration(self): flags = HexrdConfig().get_statuses_instrument_format() instr.calibration_flags = flags - img_dict = HexrdConfig().masked_images_dict + img_dict = MaskManager().masked_images_dict instr_calibrator = run_calibration(picks, instr, img_dict, materials) self.write_instrument_to_hexrd_config(instr) @@ -763,7 +763,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 = MaskManager().masked_images_dict statuses = HexrdConfig().get_statuses_instrument_format() self.instr.calibration_flags = statuses @@ -845,7 +845,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 = MaskManager().masked_images_dict # These are the options the user chose earlier... options = HexrdConfig().config['calibration']['laue_auto_picker'] diff --git a/hexrdgui/calibration/stereo_plot.py b/hexrdgui/calibration/stereo_plot.py index d71814a4f..b91411bb6 100644 --- a/hexrdgui/calibration/stereo_plot.py +++ b/hexrdgui/calibration/stereo_plot.py @@ -42,7 +42,7 @@ def extent(self): @property def raw_img_dict(self): - return HexrdConfig().masked_images_dict + return MaskManager().masked_images_dict @property def stereo_size(self): diff --git a/hexrdgui/hexrd_config.py b/hexrdgui/hexrd_config.py index b4558af5e..d78e57cdb 100644 --- a/hexrdgui/hexrd_config.py +++ b/hexrdgui/hexrd_config.py @@ -861,76 +861,6 @@ def images_dict(self): """Default to intensity corrected images dict""" return self.intensity_corrected_images_dict - @property - def raw_masks_dict(self): - """Get a masks dict""" - # We must ensure that we are using raw masks - from hexrdgui.create_raw_mask import rebuild_raw_masks - prev_masks = copy.deepcopy(self.masks) - try: - rebuild_raw_masks() - masks = copy.deepcopy(self.masks) - finally: - self.masks = prev_masks - - masks_dict = {} - images_dict = self.images_dict - for name, img in images_dict.items(): - final_mask = np.ones(img.shape, dtype=bool) - for mask_name, data in masks.items(): - if mask_name not in self.visible_masks: - continue - - for det, mask in data: - if det == name: - final_mask = np.logical_and(final_mask, mask) - if (self.threshold_mask_status and - self.threshold_masks.get(name) is not None): - idx = self.current_imageseries_idx - thresh_mask = self.threshold_masks[name][idx] - final_mask = np.logical_and(final_mask, thresh_mask) - masks_dict[name] = final_mask - - return masks_dict - - @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 hexrdgui.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] = fill_value - - if has_panel_buffers: - img[~panel.panel_buffer] = fill_value - - return images_dict - def save_imageseries(self, ims, name, write_file, selected_format, **kwargs): hexrd.imageseries.save.write(ims, write_file, selected_format, @@ -2679,20 +2609,6 @@ def recent_images(self, images): self._recent_images = v self.recent_images_changed.emit() - def apply_masks_to_panel_buffers(self, instr): - # Apply raw masks to the panel buffers on the passed instrument - for det_key, mask in self.raw_masks_dict.items(): - panel = instr.detectors[det_key] - - # Make sure it is a 2D array - utils.convert_panel_buffer_to_2d_array(panel) - - # Add the mask - # NOTE: the mask here is False when pixels should be masked. - # This is the same as the panel buffer, which is why we are - # doing a `np.logical_and()`. - panel.panel_buffer = np.logical_and(mask, panel.panel_buffer) - def clean_panel_buffers(self): # Ensure that the panel buffer sizes match the pixel sizes. # If not, clear the panel buffer and print a warning.