Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP-3234: Mask NaN values for background subtraction of "robust mean" #7587

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ associations
contains the target as coron, while treating the others as regular imaging. Also
create an image3 ASN that contains data from all 4 detectors. [#7556]

background
----------

- Mask out NaN pixels before removing outlier values and calculating mean in
``robust_mean`` function. [#7587]

datamodels
----------

Expand Down
9 changes: 6 additions & 3 deletions jwst/background/background_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ def robust_mean(x, lowlim=25., highlim=75.):
percentile limits.
"""

limits = np.percentile(x, (lowlim, highlim))
mask = np.logical_and(x >= limits[0], x <= limits[1])
mean_value = x[mask].mean(dtype=float)
nan_mask = np.isnan(x)
cleaned_x = x[~nan_mask]
limits = np.percentile(cleaned_x, (lowlim, highlim))
mask = np.logical_and(cleaned_x >= limits[0], cleaned_x <= limits[1])

mean_value = np.mean(cleaned_x[mask], dtype=float)

return mean_value