From 1351461f08a218a7a4a99017e44d2e6c21515676 Mon Sep 17 00:00:00 2001 From: Tyler Pauly Date: Thu, 11 May 2023 15:00:38 -0400 Subject: [PATCH 1/2] mask NaN values --- jwst/background/background_sub.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jwst/background/background_sub.py b/jwst/background/background_sub.py index 1ee04c2e19..3567f21259 100755 --- a/jwst/background/background_sub.py +++ b/jwst/background/background_sub.py @@ -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 From 2a836ecf4edbb8e0ef24c5c22395c7f592d568f2 Mon Sep 17 00:00:00 2001 From: Tyler Pauly Date: Thu, 11 May 2023 15:04:32 -0400 Subject: [PATCH 2/2] changelog --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 210c3afd20..70fa679627 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ----------