Skip to content

Commit

Permalink
AL-837: Compute resample output WCS from known s_region instead of re…
Browse files Browse the repository at this point in the history
…calculating footprints (#8893)
  • Loading branch information
emolter authored Nov 4, 2024
1 parent 504e16a commit c508146
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions changes/8893.resample.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use s_region list to calculate output footprint instead of re-computing via WCS transforms
4 changes: 4 additions & 0 deletions jwst/assign_mtwcs/moving_target_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from jwst.datamodels import ModelLibrary
from jwst.stpipe.utilities import record_step_status
from jwst.assign_wcs.util import update_s_region_imaging
from jwst.lib.exposure_types import IMAGING_TYPES

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -69,6 +71,8 @@ def assign_moving_target_wcs(input_models):
model.meta.wcsinfo.mt_ra, model.meta.wcsinfo.mt_dec)
del model.meta.wcs
model.meta.wcs = new_wcs
if model.meta.exposure.type.lower() in IMAGING_TYPES:
update_s_region_imaging(model)
record_step_status(model, "assign_mtwcs", True)
input_models.shelve(model, i, modify=True)

Expand Down
2 changes: 2 additions & 0 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from gwcs.wcs import WCS
from stdatamodels.jwst import datamodels
from stcal.alignment.util import compute_s_region_imaging

from jwst.datamodels import ModelContainer, ModelLibrary
from jwst.assign_wcs import AssignWcsStep
Expand Down Expand Up @@ -151,6 +152,7 @@ def we_many_sci(

# Replace the FITS-type WCS with an Identity WCS
sci1.meta.wcs = create_fitswcs(sci1)
sci1.meta.wcsinfo.s_region = compute_s_region_imaging(sci1.meta.wcs, shape=shape, center=False)
rng = np.random.default_rng(720)
sci1.data = rng.normal(loc=background, size=shape, scale=sigma)
sci1.err = np.zeros(shape) + sigma
Expand Down
29 changes: 17 additions & 12 deletions jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ def make_output_wcs(input_models, ref_wcs=None,
Parameters
----------
input_models : `~jwst.datamodel.ModelLibrary`
Each datamodel must have a ~gwcs.WCS object.
The datamodels to combine into a single output WCS. Each datamodel must
have a ``meta.wcs.s_region`` attribute.
pscale_ratio : float, optional
ref_wcs : gwcs.WCS, None, optional
Custom WCS to use as the output WCS. If not provided,
the reference WCS will be taken as the WCS of the first input model, with
its bounding box adjusted to encompass all input frames.
pscale_ratio : float, None, optional
Ratio of input to output pixel scale. Ignored when ``pscale``
is provided.
Expand Down Expand Up @@ -67,27 +73,26 @@ def make_output_wcs(input_models, ref_wcs=None,
WCS object, with defined domain, covering entire set of input frames
"""
if ref_wcs is None:
sregion_list = []
with input_models:
wcslist = []
for i, model in enumerate(input_models):
w = model.meta.wcs
if w.bounding_box is None:
w.bounding_box = wcs_bbox_from_shape(model.data.shape)
wcslist.append(w)
sregion_list.append(model.meta.wcsinfo.s_region)
if i == 0:
example_model = model
ref_wcs = example_model.meta.wcs
ref_wcsinfo = example_model.meta.wcsinfo.instance
input_models.shelve(model)
naxes = wcslist[0].output_frame.naxes
naxes = ref_wcs.output_frame.naxes

if naxes != 2:
msg = ("Output WCS needs 2 spatial axes "
f"but the supplied WCS has {naxes} axes.")
raise RuntimeError(msg)

output_wcs = util.wcs_from_footprints(
wcslist,
ref_wcs=wcslist[0],
ref_wcsinfo=example_model.meta.wcsinfo.instance,
output_wcs = util.wcs_from_sregions(
sregion_list,
ref_wcs,
ref_wcsinfo,
pscale_ratio=pscale_ratio,
pscale=pscale,
rotation=rotation,
Expand Down

0 comments on commit c508146

Please sign in to comment.