Skip to content

Commit

Permalink
parametrize basic test for shift-free input
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Apr 22, 2024
1 parent 2c9b2dd commit 46fd867
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions jwst/tweakreg/tests/test_tweakreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from jwst.datamodels import ModelContainer


BKG_LEVEL = 0.001
N_EXAMPLE_SOURCES = 21
N_CUSTOM_SOURCES = 15

Expand Down Expand Up @@ -132,7 +133,7 @@ def example_input(example_wcs):
m0.meta.wcsinfo = _wcsinfo_from_wcs_transform(example_wcs)

# and a few 'sources'
m0.data[:] = 0.001
m0.data[:] = BKG_LEVEL
n_sources = N_EXAMPLE_SOURCES # a few more than default minobj
rng = np.random.default_rng(26)
xs = rng.choice(50, n_sources, replace=False) * 8 + 10
Expand All @@ -152,13 +153,17 @@ def example_input(example_wcs):
return c


def test_tweakreg_step(example_input):
@pytest.mark.parametrize("with_shift", [True, False])
def test_tweakreg_step(example_input, with_shift):
"""
A simplified unit test for basic operation of the TweakRegStep
when run with or without a small shift in the input image sources
"""
# shift 9 pixels so that the sources in one of the 2 images
# appear at different locations (resulting in a correct wcs update)
example_input[1].data = np.roll(example_input[1].data, 9, axis=0)
if with_shift:
# shift 9 pixels so that the sources in one of the 2 images
# appear at different locations (resulting in a correct wcs update)
example_input[1].data[:-9] = example_input[1].data[9:]
example_input[1].data[-9:] = BKG_LEVEL

# assign images to different groups (so they are aligned to each other)
example_input[0].meta.group_id = 'a'
Expand All @@ -177,7 +182,10 @@ def test_tweakreg_step(example_input):
# and that the wcses differ by a small amount due to the shift above
# by projecting one point through each wcs and comparing the difference
abs_delta = abs(result[1].meta.wcs(0, 0)[0] - result[0].meta.wcs(0, 0)[0])
assert abs_delta > 1E-5
if with_shift:
assert abs_delta > 1E-5
else:
assert abs_delta < 1E-12


@pytest.fixture()
Expand Down

0 comments on commit 46fd867

Please sign in to comment.