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 bf24e67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 bf24e67

Please sign in to comment.