From 3bd0f8e0c26b44d08e845e9a7f007a6d8b79d90c Mon Sep 17 00:00:00 2001 From: Mihai Cara Date: Thu, 12 Dec 2024 09:49:35 -0500 Subject: [PATCH] Fix err computation for undefined variances --- jwst/resample/resample.py | 7 ++++++- jwst/resample/tests/test_resample_step.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jwst/resample/resample.py b/jwst/resample/resample.py index 356748c4e2..9a5c883b55 100644 --- a/jwst/resample/resample.py +++ b/jwst/resample/resample.py @@ -496,7 +496,12 @@ def resample_many_to_one(self, input_models): valid_var.append(var) setattr(output_model, name, var) - err = np.sum(valid_var, axis=0).astype(np.float32) + if len(valid_var) > 0: + all_nan = np.all(np.isnan(valid_var), axis=0) + err = np.sqrt(np.nansum(valid_var, axis=0)).astype(np.float32) + err[all_nan] = np.nan + else: + err = np.full_like(output_model.data, np.nan) output_model.err = err del driz, err, valid_var, var diff --git a/jwst/resample/tests/test_resample_step.py b/jwst/resample/tests/test_resample_step.py index 7c4ca1d798..00d4c1dd07 100644 --- a/jwst/resample/tests/test_resample_step.py +++ b/jwst/resample/tests/test_resample_step.py @@ -849,7 +849,7 @@ def test_resample_undefined_variance(nircam_rate, shape): result = ResampleStep.call(c, blendheaders=False) # no valid variance - variance are all NaN - assert np.any(np.isfinite(result.err)) + assert_allclose(result.err, np.nan) assert_allclose(result.var_rnoise, np.nan) assert_allclose(result.var_poisson, np.nan) assert_allclose(result.var_flat, np.nan)