From 78c7dc41093f8fb76fe049682ce56de3cad4c488 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Wed, 20 Nov 2024 12:05:59 -0500 Subject: [PATCH] Clean up bounding box assignment (#1527) --- changes/1527.general.rst | 1 + romancal/assign_wcs/assign_wcs_step.py | 12 +++++++----- romancal/conftest.py | 2 +- romancal/tweakreg/tests/test_astrometric_utils.py | 2 +- romancal/tweakreg/tests/test_tweakreg.py | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 changes/1527.general.rst diff --git a/changes/1527.general.rst b/changes/1527.general.rst new file mode 100644 index 000000000..104f48191 --- /dev/null +++ b/changes/1527.general.rst @@ -0,0 +1 @@ +Perform bounding box assignment inline with the ordering that GWCS prefers. diff --git a/romancal/assign_wcs/assign_wcs_step.py b/romancal/assign_wcs/assign_wcs_step.py index 44147e6cb..c3c23542d 100644 --- a/romancal/assign_wcs/assign_wcs_step.py +++ b/romancal/assign_wcs/assign_wcs_step.py @@ -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 @@ -141,7 +142,7 @@ 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 @@ -149,9 +150,10 @@ def wfi_distortion(model, reference_files): 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 diff --git a/romancal/conftest.py b/romancal/conftest.py index c9fe82abd..6917a283d 100644 --- a/romancal/conftest.py +++ b/romancal/conftest.py @@ -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 @@ -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 diff --git a/romancal/tweakreg/tests/test_astrometric_utils.py b/romancal/tweakreg/tests/test_astrometric_utils.py index 04722d9e7..ee5071f46 100644 --- a/romancal/tweakreg/tests/test_astrometric_utils.py +++ b/romancal/tweakreg/tests/test_astrometric_utils.py @@ -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 @@ -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 diff --git a/romancal/tweakreg/tests/test_tweakreg.py b/romancal/tweakreg/tests/test_tweakreg.py index 094d5a9ff..d3823e70c 100644 --- a/romancal/tweakreg/tests/test_tweakreg.py +++ b/romancal/tweakreg/tests/test_tweakreg.py @@ -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 @@ -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