Skip to content

Mask out invalid pixels in the polar view#755

Merged
psavery merged 2 commits intomasterfrom
polar-view-mask-invalid-pixels
Feb 4, 2025
Merged

Mask out invalid pixels in the polar view#755
psavery merged 2 commits intomasterfrom
polar-view-mask-invalid-pixels

Conversation

@psavery
Copy link
Copy Markdown
Collaborator

@psavery psavery commented Feb 4, 2025

This makes it so that any invalid pixels (as defined by the detector's panel buffer) do not have an effect on the resulting polar image and lineout. Any polar view pixels that were interpolated with an invalid pixel will be nan.

The intended usage is as follows:

img = pv.warp_image(image_dict, pad_with_nans=True,
                    do_interpolation=True)
cake = np.mean(img, axis=0)

The img that is returned from the warp image is a masked array, with all invalid pixels being masked out. If np.mean(img, axis=0) is applied to this, it ignores all masked out pixels when computing the mean along the axis (which is the behavior we want). This is preferred over doing something like np.sum(img.filled(0), axis=0), since columns with invalid pixels will be reduced in value.

A previous caking that didn't mask out the invalid pixels for Eiger data looked like this:

original

Note that invalid Eiger pixels have a very high value, and this resulted in very high values in intensity for
any column that were interpolated using invalid pixels.

The new caking looks correct:

new

This makes it so that any invalid pixels (as defined by the detector's
panel buffer) do not have an effect on the resulting polar image and
lineout. Any polar view pixels that were interpolated with an invalid
pixel will be nan.

The intended usage is as follows:

```python
img = pv.warp_image(image_dict, pad_with_nans=True,
                    do_interpolation=True)
cake = np.mean(img, axis=0)
```

The `img` that is returned from the warp image is a masked array,
with all invalid pixels being masked out. If `np.mean(img, axis=0)` is
applied to this, it ignores all masked out pixels when computing the
mean along the axis (which is the behavior we want). This is preferred
over doing something like `np.sum(img.filled(0), axis=0)`, since columns
with invalid pixels will be reduced in value.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 39.82%. Comparing base (c6f1247) to head (162bb45).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
hexrd/utils/panel_buffer.py 53.84% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #755      +/-   ##
==========================================
+ Coverage   39.79%   39.82%   +0.02%     
==========================================
  Files         141      142       +1     
  Lines       22744    22763      +19     
==========================================
+ Hits         9052     9065      +13     
- Misses      13692    13698       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@psavery psavery merged commit e81a786 into master Feb 4, 2025
7 checks passed
@psavery psavery deleted the polar-view-mask-invalid-pixels branch February 4, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants