Skip to content

Commit

Permalink
Fix err computation for undefined variances
Browse files Browse the repository at this point in the history
  • Loading branch information
mcara committed Dec 12, 2024
1 parent d23e4a1 commit 7531f55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions jwst/resample/tests/test_resample_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ def test_resample_variance(nircam_rate, n_images, weight_type):

assert np.all((result1.err[mask] / err) <= 1.0)
assert_allclose(
np.sum(result.err[mask]**2) * twht**2,
np.sum(result1.err[mask]**2) * twht1**2,
np.sum(result.err[mask]**2) * twht,
np.sum(result1.err[mask]**2) * twht1,
rtol=1e-6,
atol=0.0,
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7531f55

Please sign in to comment.