Skip to content

Commit

Permalink
Clean up bounding box assignment (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Nov 20, 2024
1 parent 281aa55 commit 78c7dc4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/1527.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Perform bounding box assignment inline with the ordering that GWCS prefers.
12 changes: 7 additions & 5 deletions romancal/assign_wcs/assign_wcs_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import gwcs.coordinate_frames as cf
from astropy import coordinates as coord
from astropy import units as u
from astropy.modeling import bind_bounding_box
from gwcs.wcs import WCS, Step
from roman_datamodels import datamodels as rdm

Expand Down Expand Up @@ -141,17 +142,18 @@ def wfi_distortion(model, reference_files):
transform = dist.coordinate_distortion_transform

try:
bbox = transform.bounding_box
bbox = transform.bounding_box.bounding_box(order="F")
except NotImplementedError:
# Check if the transform in the reference file has a ``bounding_box``.
# If not set a ``bounding_box`` equal to the size of the image after
# assembling all distortion corrections.
bbox = None
dist.close()

if bbox is None:
transform.bounding_box = wcs_bbox_from_shape(model.data.shape)
else:
transform.bounding_box = bbox
bind_bounding_box(
transform,
wcs_bbox_from_shape(model.data.shape) if bbox is None else bbox,
order="F",
)

return transform
2 changes: 1 addition & 1 deletion romancal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def _create_wcs(input_dm, shift_1=0, shift_2=0):

# create necessary transformations
distortion = Shift(-shift_1) & Shift(-shift_2)
distortion.bounding_box = ((-0.5, shape[-1] + 0.5), (-0.5, shape[-2] + 0.5))
tel2sky = pointing.v23tosky(input_dm)

# create required frames
Expand All @@ -219,6 +218,7 @@ def _create_wcs(input_dm, shift_1=0, shift_2=0):
]

wcs_obj = wcs.WCS(pipeline)
wcs_obj.bounding_box = ((-0.5, shape[-2] + 0.5), (-0.5, shape[-1] + 0.5))

input_dm.meta["wcs"] = wcs_obj

Expand Down
2 changes: 1 addition & 1 deletion romancal/tweakreg/tests/test_astrometric_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def create_wcs_for_tweakreg_pipeline(input_dm, shift_1=0, shift_2=0):

# create necessary transformations
distortion = Shift(-shift_1) & Shift(-shift_2)
distortion.bounding_box = ((-0.5, shape[-1] + 0.5), (-0.5, shape[-2] + 0.5))
tel2sky = _create_tel2sky_model(input_dm)

# create required frames
Expand All @@ -276,6 +275,7 @@ def create_wcs_for_tweakreg_pipeline(input_dm, shift_1=0, shift_2=0):
]

wcs_obj = wcs.WCS(pipeline)
wcs_obj.bounding_box = ((-0.5, shape[-2] + 0.5), (-0.5, shape[-1] + 0.5))

input_dm.meta["wcs"] = wcs_obj

Expand Down
2 changes: 1 addition & 1 deletion romancal/tweakreg/tests/test_tweakreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ def create_wcs_for_tweakreg_pipeline(input_dm, shift_1=0, shift_2=0):

# create necessary transformations
distortion = Shift(-shift_1) & Shift(-shift_2)
distortion.bounding_box = ((-0.5, shape[-1] + 0.5), (-0.5, shape[-2] + 0.5))
tel2sky = _create_tel2sky_model(input_dm)

# create required frames
Expand All @@ -337,6 +336,7 @@ def create_wcs_for_tweakreg_pipeline(input_dm, shift_1=0, shift_2=0):
]

wcs_obj = wcs.WCS(pipeline)
wcs_obj.bounding_box = ((-0.5, shape[-2] + 0.5), (-0.5, shape[-1] + 0.5))

input_dm.meta["wcs"] = wcs_obj

Expand Down

0 comments on commit 78c7dc4

Please sign in to comment.