Skip to content

Commit

Permalink
Raise exception for unsupported weight type. Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcara committed Feb 25, 2025
1 parent 95c1d8f commit e5b4166
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/348.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``build_driz_weight`` to raise an exception when requested ``weight_type`` is not supported.
8 changes: 7 additions & 1 deletion src/stcal/resample/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ def build_driz_weight(model, weight_type=None, good_bits=None,
exptime, s = get_tmeasure(model)
result = exptime * dqmask

else:
elif weight_type is None:
result = np.ones(data.shape, dtype=data.dtype) * dqmask

else:
raise ValueError(
f"Invalid weight type: {repr(weight_type)}. "
"Allowed weight types are 'ivm', 'exptime', or None."
)

return result.astype(np.float32)


Expand Down
10 changes: 3 additions & 7 deletions tests/resample/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ def test_resample_mostly_defaults(weight_type):


@pytest.mark.parametrize(
"compute_err,weight_type",
[
("from_var", "ivm-smed"),
("driz_err", "ivm-med5")
]
"compute_err", ["from_var", "driz_err"]
)
def test_resample_compute_error_mode(compute_err, weight_type):
def test_resample_compute_error_mode(compute_err):
crval = (150.0, 2.0)
crpix = (500.0, 500.0)
shape = (1000, 1000)
Expand All @@ -114,7 +110,7 @@ def test_resample_compute_error_mode(compute_err, weight_type):
resample = Resample(
n_input_models=nmodels,
output_wcs=output_model,
weight_type=weight_type,
weight_type="ivm",
compute_err=compute_err,
)
resample.dq_flag_name_map = JWST_DQ_FLAG_DEF
Expand Down
10 changes: 10 additions & 0 deletions tests/resample/test_resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ def test_build_driz_weight_zeros(weight_type):
weight_map = build_driz_weight(model, weight_type=weight_type)

assert_array_equal(weight_map, 1)


@pytest.mark.parametrize("weight_type", ["ivm-smed", "ivm-med5"])
def test_unsupported_weight_type(weight_type):
model = make_input_model((10, 10))
with pytest.raises(ValueError) as err_info:
build_driz_weight(model, weight_type=weight_type)
assert str(err_info.value).startswith(
f"Invalid weight type: {repr(weight_type)}."
)

0 comments on commit e5b4166

Please sign in to comment.