diff --git a/changes/8897.assign_wcs.rst b/changes/8897.assign_wcs.rst new file mode 100644 index 0000000000..fb209a0fdc --- /dev/null +++ b/changes/8897.assign_wcs.rst @@ -0,0 +1 @@ +Use pixel vertices to define s_region instead of pixel centers." diff --git a/jwst/assign_wcs/tests/test_nircam.py b/jwst/assign_wcs/tests/test_nircam.py index 3ee141f0f9..839e3f2e56 100644 --- a/jwst/assign_wcs/tests/test_nircam.py +++ b/jwst/assign_wcs/tests/test_nircam.py @@ -10,6 +10,7 @@ """ import numpy as np import pytest +import re from astropy.io import fits @@ -244,3 +245,31 @@ def test_wfss_sip(): util.wfss_imaging_wcs(wfss_model, nircam.imaging, bbox=((1, 1024), (1, 1024))) for key in ['a_order', 'b_order', 'crpix1', 'crpix2', 'crval1', 'crval2', 'cd1_1']: assert key in wfss_model.meta.wcsinfo.instance + + +def _sregion_to_footprint(s_region): + """ + Parameters + ---------- + s_region : str + The S_REGION header keyword + + Returns + ------- + footprint : np.array + A 2D array of the footprint of the region, shape (N, 2) + """ + no_prefix = re.sub(r"[a-zA-Z]", "", s_region) + return np.array(no_prefix.split(), dtype=float).reshape(-1, 2) + + +def test_update_s_region_imaging(): + """Ensure the s_region keyword matches output of wcs.footprint()""" + model = ImageModel(create_hdul()) + model.meta.wcs = create_imaging_wcs() + util.update_s_region_imaging(model) + + s_region = model.meta.wcsinfo.s_region + footprint = model.meta.wcs.footprint().flatten() + footprint_sregion = _sregion_to_footprint(s_region).flatten() + assert np.allclose(footprint, footprint_sregion, rtol=1e-9) diff --git a/jwst/assign_wcs/util.py b/jwst/assign_wcs/util.py index b33620ed8b..d8e492587f 100644 --- a/jwst/assign_wcs/util.py +++ b/jwst/assign_wcs/util.py @@ -795,7 +795,7 @@ def update_s_region_imaging(model): """ Update the ``S_REGION`` keyword using ``WCS.footprint``. """ - s_region = compute_s_region_imaging(model.meta.wcs, shape=model.data.shape) + s_region = compute_s_region_imaging(model.meta.wcs, shape=model.data.shape, center=False) if s_region is not None: model.meta.wcsinfo.s_region = s_region