From a817c79a9b00ad430225dfe05239dbb832d342b6 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Fri, 31 Jan 2025 16:32:36 -0500 Subject: [PATCH] Fix error propagation for inverse correction --- jwst/barshadow/bar_shadow.py | 15 ++++++++++----- jwst/barshadow/tests/test_barshadow_step.py | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/jwst/barshadow/bar_shadow.py b/jwst/barshadow/bar_shadow.py index ad5f27677e..0de4530bce 100644 --- a/jwst/barshadow/bar_shadow.py +++ b/jwst/barshadow/bar_shadow.py @@ -78,13 +78,18 @@ def do_correction( # because they're variance, while err is standard deviation if not inverse: slitlet.data /= correction.data + slitlet.err /= correction.data + slitlet.var_poisson /= correction.data**2 + slitlet.var_rnoise /= correction.data**2 + if slitlet.var_flat is not None and np.size(slitlet.var_flat) > 0: + slitlet.var_flat /= correction.data**2 else: slitlet.data *= correction.data - slitlet.err /= correction.data - slitlet.var_poisson /= correction.data**2 - slitlet.var_rnoise /= correction.data**2 - if slitlet.var_flat is not None and np.size(slitlet.var_flat) > 0: - slitlet.var_flat /= correction.data**2 + slitlet.err *= correction.data + slitlet.var_poisson *= correction.data**2 + slitlet.var_rnoise *= correction.data**2 + if slitlet.var_flat is not None and np.size(slitlet.var_flat) > 0: + slitlet.var_flat *= correction.data**2 slitlet.barshadow = correction.data return output_model, corrections diff --git a/jwst/barshadow/tests/test_barshadow_step.py b/jwst/barshadow/tests/test_barshadow_step.py index d6b6d3be71..9b9284b70b 100644 --- a/jwst/barshadow/tests/test_barshadow_step.py +++ b/jwst/barshadow/tests/test_barshadow_step.py @@ -160,6 +160,10 @@ def test_barshadow_correction_pars(nirspec_mos_model): # output data is the same as input, except that NaNs do not invert assert np.allclose(inverse_result.slits[0].data[nnan], model.slits[0].data[nnan]) + assert np.allclose(inverse_result.slits[0].err[nnan], model.slits[0].err[nnan]) + assert np.allclose(inverse_result.slits[0].var_rnoise[nnan], model.slits[0].var_rnoise[nnan]) + assert np.allclose(inverse_result.slits[0].var_poisson[nnan], model.slits[0].var_poisson[nnan]) + assert np.allclose(inverse_result.slits[0].var_flat[nnan], model.slits[0].var_flat[nnan]) result.close() inverse_result.close()