From bf24e673eb6d9cfe78e2cabff35c5cd6b0e20f8d 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 | 9 ++++++++- jwst/resample/tests/test_resample_step.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jwst/resample/resample.py b/jwst/resample/resample.py index 356748c4e2..c12670d5f6 100644 --- a/jwst/resample/resample.py +++ b/jwst/resample/resample.py @@ -494,9 +494,16 @@ def resample_many_to_one(self, input_models): else: var = driz.out_img2[k] valid_var.append(var) + print(f"\nvar:\n{var}\n") setattr(output_model, name, var) + print(f"\nvalid_var:\n{valid_var}\n") - 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.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)