Skip to content

Commit

Permalink
JP-3781: Use center=False for compute_s_region_imaging (spacetelescop…
Browse files Browse the repository at this point in the history
…e#8897)

Co-authored-by: Nadia Dencheva <nadia.astropy@gmail.com>
  • Loading branch information
emolter and nden authored Oct 18, 2024
1 parent 82932fa commit c275fa6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/8897.assign_wcs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use pixel vertices to define s_region instead of pixel centers."
29 changes: 29 additions & 0 deletions jwst/assign_wcs/tests/test_nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import numpy as np
import pytest
import re


from astropy.io import fits
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion jwst/assign_wcs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c275fa6

Please sign in to comment.