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 78244e5 commit 64aad44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 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.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
2 changes: 1 addition & 1 deletion jwst/resample/tests/test_resample_step.py
Original file line number Diff line number Diff line change
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 64aad44

Please sign in to comment.