Skip to content

Commit

Permalink
Issue warning when var_rnoise doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Feb 25, 2021
1 parent ad9d56a commit c283048
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
6 changes: 5 additions & 1 deletion jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,19 @@ def build_driz_weight(model, weight_type=None, good_bits=None):
inv_variance = model.var_rnoise**-1
inv_variance[~np.isfinite(inv_variance)] = 1
else:
warnings.warn("var_rnoise array not available. Setting drizzle weight map to 1",
RuntimeWarning)
inv_variance = 1.0
result = inv_variance * dqmask
elif weight_type == 'exptime':
exptime = model.meta.exposure.exposure_time
result = exptime * dqmask
else:
warnings.warn("weight_type set to None. Setting drizzle weight map to 1",
RuntimeWarning)
result = np.ones(model.data.shape, dtype=model.data.dtype)

return result
return result.astype(np.float32)


def build_mask(dqarr, bitvalue):
Expand Down
33 changes: 14 additions & 19 deletions jwst/resample/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test various utility functions"""
import pytest

from numpy.testing import assert_array_equal
import numpy as np
import pytest

from jwst.datamodels import SlitModel, ImageModel, dqflags
from jwst.resample.resample_spec import find_dispersion_axis
Expand Down Expand Up @@ -44,37 +44,32 @@ def test_build_mask(dq, bitvalues, expected):
Expected mask array
"""
result = build_mask(dq, bitvalues)
np.testing.assert_array_equal(result, expected)
assert_array_equal(result, expected)


@pytest.mark.parametrize("weight_type, expected_value", [
("ivm", 0.1),
("exptime", 10),
(None, 1.0),
]
)
def test_build_driz_weight(weight_type, expected_value):
@pytest.mark.parametrize("weight_type", ["ivm", "exptime"])
def test_build_driz_weight(weight_type):
"""Check that correct weight map is returned of different weight types"""
model = ImageModel((10, 10))
model.dq[0] = DO_NOT_USE
model.meta.exposure.exposure_time = 10.0
model.var_rnoise += 10.0
model.var_rnoise += 0.1

weight_map = build_driz_weight(model, weight_type=weight_type, good_bits="GOOD")
np.testing.assert_array_equal(weight_map[0], 0)
np.testing.assert_array_equal(weight_map[1:], expected_value)
assert_array_equal(weight_map[0], 0)
assert_array_equal(weight_map[1:], 10.0)
assert weight_map.dtype == np.float32


@pytest.mark.parametrize("weight_type", ["ivm", "exptime"])
@pytest.mark.parametrize("weight_type", ["ivm", None])
def test_build_driz_weight_zeros(weight_type):
"""Check that zero or not finite weight maps raise an error"""
"""Check that zero or not finite weight maps get set to 1"""
model = ImageModel((10, 10))
model.var_rnoise += 0
model.meta.exposure.exposure_time = 0.0

with pytest.raises(ValueError):
build_driz_weight(model, weight_type=weight_type)
with pytest.warns(RuntimeWarning):
weight_map = build_driz_weight(model, weight_type=weight_type)

assert_array_equal(weight_map, 1)


def test_find_dispersion_axis():
Expand Down

0 comments on commit c283048

Please sign in to comment.