Skip to content

Commit

Permalink
Set invalid pixels in cartesian view to nan
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
psavery committed Dec 18, 2024
1 parent 38f7d64 commit d38e5a7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions hexrdgui/calibration/cartesian_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d38e5a7

Please sign in to comment.