From d38e5a7ed49d71d62ae66a1f71cea0882a74ce39 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Wed, 18 Dec 2024 15:33:21 -0600 Subject: [PATCH] Set invalid pixels in cartesian view to nan This sets pixels to nan that are either: 1. Part of a detector's panel buffer 2. Not located on any detector This is important for making FIDDLE images appear nice. Signed-off-by: Patrick Avery --- hexrdgui/calibration/cartesian_plot.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/hexrdgui/calibration/cartesian_plot.py b/hexrdgui/calibration/cartesian_plot.py index 9a25d769f..45548722d 100644 --- a/hexrdgui/calibration/cartesian_plot.py +++ b/hexrdgui/calibration/cartesian_plot.py @@ -31,6 +31,10 @@ def __init__(self): self.type = ViewType.cartesian self.instr = create_hedm_instrument() self.images_dict = HexrdConfig().images_dict + + # Set invalid pixels to be nan + HexrdConfig().apply_panel_buffer_to_images(self.images_dict) + self.img = None # Perform some checks before proceeding @@ -283,8 +287,15 @@ def create_warped_image(self, detector_id): res = tf.warp(img, tform3, output_shape=(self.dpanel.rows, self.dpanel.cols), - preserve_range=True) - self.warp_dict[detector_id] = res + preserve_range=True, cval=np.nan) + nan_mask = np.isnan(res) + + self.warp_dict[detector_id] = np.ma.masked_array( + res, + mask=nan_mask, + fill_value=0, + ) + return res @property @@ -293,8 +304,15 @@ def display_img(self): def generate_image(self): img = np.zeros((self.dpanel.rows, self.dpanel.cols)) + always_nan = np.ones(img.shape, dtype=bool) for key in self.images_dict.keys(): - img += self.warp_dict[key] + # Use zeros when summing, but identify pixels that + # are nans in all images and set those to nan. + warp_img = self.warp_dict[key] + img += warp_img.filled(0) + always_nan = np.logical_and(always_nan, warp_img.mask) + + img[always_nan] = np.nan # In case there were any nans... nan_mask = np.isnan(img)