From ce4a4b3c7219a9f4fa81365baaa087adb781c234 Mon Sep 17 00:00:00 2001 From: Mihai Cara Date: Wed, 12 Feb 2025 17:13:08 -0500 Subject: [PATCH 1/2] Fix a bug in resampled_wcs_from_models --- changes/9186.resample.rst | 1 + jwst/resample/resample_utils.py | 21 +++++---------------- 2 files changed, 6 insertions(+), 16 deletions(-) create mode 100644 changes/9186.resample.rst diff --git a/changes/9186.resample.rst b/changes/9186.resample.rst new file mode 100644 index 0000000000..f7ca70932e --- /dev/null +++ b/changes/9186.resample.rst @@ -0,0 +1 @@ +Fix a bug in ``resampled_wcs_from_models``. diff --git a/jwst/resample/resample_utils.py b/jwst/resample/resample_utils.py index 2eea260379..b4ac1bac32 100644 --- a/jwst/resample/resample_utils.py +++ b/jwst/resample/resample_utils.py @@ -12,7 +12,6 @@ from stcal.alignment.util import ( compute_scale, - wcs_bbox_from_shape, wcs_from_sregions, ) from stcal.resample import UnsupportedWCSError @@ -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, @@ -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 @@ -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.") @@ -173,6 +161,7 @@ def resampled_wcs_from_models( crpix=crpix, crval=crval ) + return wcs, pscale_in0, pixel_scale, pixel_scale_ratio From 6f8099100aab58822c346001eee3a4a16c21d782 Mon Sep 17 00:00:00 2001 From: Mihai Cara Date: Wed, 12 Feb 2025 17:43:15 -0500 Subject: [PATCH 2/2] fix-regtest --- jwst/resample/resample_spec.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jwst/resample/resample_spec.py b/jwst/resample/resample_spec.py index 5cc9db19fb..4f991d76ce 100644 --- a/jwst/resample/resample_spec.py +++ b/jwst/resample/resample_spec.py @@ -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 @@ -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 @@ -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 @@ -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