Skip to content

Commit

Permalink
Fix a bug in resampled_wcs_from_models (spacetelescope#9186)
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke authored Feb 13, 2025
2 parents 7a69919 + 6f80991 commit 0a2231a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions changes/9186.resample.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in ``resampled_wcs_from_models``.
9 changes: 4 additions & 5 deletions jwst/resample/resample_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from stdatamodels.jwst import datamodels

from jwst.assign_wcs.util import compute_scale, wrap_ra
from jwst.assign_wcs.util import compute_scale, wcs_bbox_from_shape, wrap_ra
from jwst.resample import resample_utils
from jwst.resample.resample import ResampleImage
from jwst.datamodels import ModelLibrary
Expand Down Expand Up @@ -512,8 +512,7 @@ def build_nirspec_output_wcs(self, input_models, refmodel=None,

# Compute bounding box and output array shape.
data_size = (ny, n_lam)
bounding_box = resample_utils.wcs_bbox_from_shape(data_size)
output_wcs.bounding_box = bounding_box
output_wcs.bounding_box = wcs_bbox_from_shape(data_size)
output_wcs.array_shape = data_size

return output_wcs
Expand Down Expand Up @@ -795,7 +794,7 @@ def build_interpolated_output_wcs(self, input_models, pixel_scale_ratio=1.0):
# turn the size into a numpy shape in (y, x) order
output_wcs.array_shape = output_array_size[::-1]
output_wcs.pixel_shape = output_array_size
bounding_box = resample_utils.wcs_bbox_from_shape(output_array_size[::-1])
bounding_box = wcs_bbox_from_shape(output_array_size[::-1])
output_wcs.bounding_box = bounding_box

return output_wcs
Expand Down Expand Up @@ -904,7 +903,7 @@ def build_nirspec_lamp_output_wcs(self, input_models, pixel_scale_ratio):
# turn the size into a numpy shape in (y, x) order
output_wcs.array_shape = output_array_size[::-1]
output_wcs.pixel_shape = output_array_size
bounding_box = resample_utils.wcs_bbox_from_shape(output_array_size[::-1])
bounding_box = wcs_bbox_from_shape(output_array_size[::-1])
output_wcs.bounding_box = bounding_box

return output_wcs
Expand Down
21 changes: 5 additions & 16 deletions jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from stcal.alignment.util import (
compute_scale,
wcs_bbox_from_shape,
wcs_from_sregions,
)
from stcal.resample import UnsupportedWCSError
Expand All @@ -36,7 +35,6 @@

def resampled_wcs_from_models(
input_models,
ref_wcs=None,
pixel_scale_ratio=1.0,
pixel_scale=None,
output_shape=None,
Expand All @@ -54,10 +52,6 @@ def resampled_wcs_from_models(
input_models : `~jwst.datamodel.ModelLibrary`
Each datamodel must have a ``model.meta.wcs`` set to a ~gwcs.WCS object.
ref_wcs : WCS object
A WCS used as reference for the creation of the output
coordinate frame, projection, and scaling and rotation transforms.
pixel_scale_ratio : float, optional
Desired pixel scale ratio defined as the ratio of the desired output
pixel scale to the first input model's pixel scale computed from this
Expand Down Expand Up @@ -111,22 +105,16 @@ def resampled_wcs_from_models(
# build a list of WCS of all input models:
sregion_list = []
ref_wcs = None
ref_wcsinfo = None
shape = None

with input_models:
for model in input_models:
w = model.meta.wcs
if ref_wcsinfo is None:
if ref_wcs is None:
ref_wcsinfo = model.meta.wcsinfo.instance
ref_wcs = deepcopy(model.meta.wcs)
shape = model.data.shape
if ref_wcs is None:
ref_wcs = w
# make sure all WCS objects have the bounding_box defined:
if w.bounding_box is None:
w.bounding_box = wcs_bbox_from_shape(shape)

sregion_list.append(model.meta.wcsinfo.s_region)
input_models.shelve(model)
input_models.shelve(model, modify=False)

if not sregion_list:
raise ValueError("No input models.")
Expand Down Expand Up @@ -173,6 +161,7 @@ def resampled_wcs_from_models(
crpix=crpix,
crval=crval
)

return wcs, pscale_in0, pixel_scale, pixel_scale_ratio


Expand Down

0 comments on commit 0a2231a

Please sign in to comment.