Skip to content

Commit

Permalink
Coverage tests for extract1d
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke committed Nov 21, 2024
1 parent 718d284 commit fd5b719
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jwst/extract_1d/extract1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def extract1d(image, profiles_2d, variance_rn, variance_phnoise, variance_flat,

else:
raise ValueError("bkg_fit_type should be 'median' or 'poly'. "
"If 'poly', bkg_order must be a nonnegative integer.")
"If 'poly', bkg_order must be an integer >= 0.")

image_sub = image - bkg_2d
else:
Expand Down
9 changes: 9 additions & 0 deletions jwst/extract_1d/tests/test_extract_src_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,12 @@ def test_extract_optimal(inputs_with_source):
# Now the flux can no longer be estimated in that column
assert np.isnan(total_flux[0][2])
assert npixels[0][2] == 0.


def test_too_many_profiles(inputs_constant):
(image, var_rnoise, var_poisson, var_rflat,
profile, weights, profile_bg) = inputs_constant

with pytest.raises(ValueError, match="not supported with 2 input profiles"):
extract1d.extract1d(image, [profile, profile.copy()],
var_rnoise, var_poisson, var_rflat)
34 changes: 34 additions & 0 deletions jwst/extract_1d/tests/test_fit_background_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,40 @@ def test_handles_empty_interval(inputs_constant):
assert np.allclose(b_var_flat[0], 0.0)


def test_bad_fit_type(inputs_constant):
(image, var_rnoise, var_poisson, var_rflat,
profile, weights, profile_bg, bkg_fit, bkg_order) = inputs_constant
with pytest.raises(ValueError, match="bkg_fit_type should be 'median' or 'poly'"):
extract1d.extract1d(
image, [profile], var_rnoise, var_poisson, var_rflat,
weights=weights, profile_bg=profile_bg, fit_bkg=True,
bkg_fit_type='mean', bkg_order=bkg_order)


@pytest.mark.parametrize('smooth', [1.5, 2])
def test_smooth_length(inputs_constant, smooth):
(image, var_rnoise, var_poisson, var_rflat,
profile, weights, profile_bg, bkg_fit, bkg_order) = inputs_constant
with pytest.raises(ValueError, match="should be an odd integer >= 1"):
extract1d.extract1d(
image, [profile], var_rnoise, var_poisson, var_rflat,
weights=weights, profile_bg=profile_bg, fit_bkg=True,
bkg_fit_type=bkg_fit, bkg_order=bkg_order, bg_smooth_length=smooth)


@pytest.mark.parametrize('extraction_type', ['box', 'optimal'])
@pytest.mark.parametrize('bkg_order_val', [-1, 2.3])
def test_bad_fit_order(inputs_constant, extraction_type, bkg_order_val):
(image, var_rnoise, var_poisson, var_rflat,
profile, weights, profile_bg, bkg_fit, bkg_order) = inputs_constant
with pytest.raises(ValueError, match="bkg_order must be an integer >= 0"):
extract1d.extract1d(
image, [profile], var_rnoise, var_poisson, var_rflat,
weights=weights, profile_bg=profile_bg, fit_bkg=True,
bkg_fit_type='poly', bkg_order=bkg_order_val,
extraction_type=extraction_type)


@pytest.mark.parametrize('bkg_order_val', [0, 1, 2])
def test_fit_background_optimal(inputs_with_source, bkg_order_val):
(image, var_rnoise, var_poisson, var_rflat,
Expand Down

0 comments on commit fd5b719

Please sign in to comment.