Skip to content

Commit

Permalink
avoid duplicate bbox generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro committed Aug 16, 2023
1 parent 98706f9 commit 5471ad9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
47 changes: 27 additions & 20 deletions jwst/assign_wcs/assign_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import importlib
from gwcs.wcs import WCS
from .util import (update_s_region_spectral, update_s_region_imaging,
update_s_region_nrs_ifu, update_s_region_mrs)
update_s_region_nrs_ifu, update_s_region_mrs,
wcs_bbox_from_shape)
from ..lib.exposure_types import IMAGING_TYPES, SPEC_TYPES, NRS_LAMP_MODE_SPEC_TYPES
from ..lib.dispaxis import get_dispersion_direction
from ..lib.wcs_utils import get_wavelengths
Expand Down Expand Up @@ -72,27 +73,33 @@ def load_wcs(input_model, reference_files={}, nrs_slit_y_range=None):
if output_model.meta.exposure.type.lower() not in exclude_types:
imaging_types = IMAGING_TYPES.copy()
imaging_types.update(['mir_lrs-fixedslit', 'mir_lrs-slitless'])
if output_model.meta.exposure.type.lower() in imaging_types:
try:
update_s_region_imaging(output_model)
except Exception as exc:
log.error("Unable to update S_REGION for type {}: {}".format(
output_model.meta.exposure.type, exc))
else:
log.info("assign_wcs updated S_REGION to {0}".format(
output_model.meta.wcsinfo.s_region))
if output_model.meta.exposure.type.lower() == 'mir_lrs-slitless':
output_model.wavelength = get_wavelengths(output_model)
elif output_model.meta.exposure.type.lower() == "nrs_ifu":
if output_model.meta.exposure.type.lower() == "nrs_ifu":
update_s_region_nrs_ifu(output_model, mod)
elif output_model.meta.exposure.type.lower() == 'mir_mrs':
update_s_region_mrs(output_model)
else:
try:
update_s_region_spectral(output_model)
except Exception as exc:
log.info("Unable to update S_REGION for type {}: {}".format(
output_model.meta.exposure.type, exc))
# Generate bounding_box if one does not yet exist,
# needed for all modes but NRS_IFU
if output_model.meta.wcs.bounding_box is None:
output_model.meta.wcs.bounding_box = wcs_bbox_from_shape(output_model.data.shape)

if output_model.meta.exposure.type.lower() in imaging_types:
try:
update_s_region_imaging(output_model)
except Exception as exc:
log.error("Unable to update S_REGION for type {}: {}".format(
output_model.meta.exposure.type, exc))
else:
log.info("assign_wcs updated S_REGION to {0}".format(
output_model.meta.wcsinfo.s_region))
if output_model.meta.exposure.type.lower() == 'mir_lrs-slitless':
output_model.wavelength = get_wavelengths(output_model)
elif output_model.meta.exposure.type.lower() == 'mir_mrs':
update_s_region_mrs(output_model)
else:
try:
update_s_region_spectral(output_model)
except Exception as exc:
log.info("Unable to update S_REGION for type {}: {}".format(
output_model.meta.exposure.type, exc))

log.info("COMPLETED assign_wcs")
return output_model
6 changes: 0 additions & 6 deletions jwst/assign_wcs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,6 @@ def update_s_region_imaging(model):

bbox = model.meta.wcs.bounding_box

if bbox is None:
bbox = wcs_bbox_from_shape(model.data.shape)
model.meta.wcs.bounding_box = bbox

# footprint is an array of shape (2, 4) as we
# are interested only in the footprint on the sky
footprint = model.meta.wcs.footprint(bbox, center=True, axis_type="spatial").T
Expand All @@ -986,8 +982,6 @@ def compute_footprint_spectral(model):
"""
swcs = model.meta.wcs
bbox = swcs.bounding_box
if bbox is None:
bbox = wcs_bbox_from_shape(model.data.shape)

x, y = grid_from_bounding_box(bbox)
ra, dec, lam = swcs(x, y)
Expand Down

0 comments on commit 5471ad9

Please sign in to comment.