Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If shape_out is specified, use this over the array_shape attribute of a WCS object #361

Merged
merged 4 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions reproject/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from astropy.utils.data import get_pkg_data_filename
from astropy.wcs import WCS

from reproject.conftest import set_wcs_array_shape
from reproject.tests.helpers import assert_wcs_allclose
from reproject.utils import parse_input_data, parse_input_shape, parse_output_projection
from reproject.wcs_utils import has_celestial
Expand Down Expand Up @@ -92,6 +93,26 @@ def test_parse_output_projection_invalid_wcs(simple_celestial_fits_wcs):
parse_output_projection(simple_celestial_fits_wcs)


def test_parse_output_projection_override_shape_out(simple_celestial_wcs):
# Regression test for a bug that caused shape_out to be ignored if the
# WCS object had array_shape set - but shape_out should override the WCS
# shape.

wcs_ref = simple_celestial_wcs

set_wcs_array_shape(wcs_ref, (10, 20))

if hasattr(wcs_ref, "low_level_wcs"):
assert wcs_ref.low_level_wcs.array_shape == (10, 20)
else:
assert wcs_ref.array_shape == (10, 20)

wcs, shape = parse_output_projection(wcs_ref, shape_out=(30, 40))

assert shape == (30, 40)
assert_wcs_allclose(wcs, wcs_ref)


@pytest.mark.filterwarnings("ignore::astropy.utils.exceptions.AstropyUserWarning")
@pytest.mark.filterwarnings("ignore::astropy.wcs.wcs.FITSFixedWarning")
def test_has_celestial():
Expand Down
13 changes: 7 additions & 6 deletions reproject/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ def parse_output_projection(output_projection, shape_in=None, shape_out=None, ou
wcs_out = HighLevelWCSWrapper(output_projection)
else:
wcs_out = output_projection
if wcs_out.low_level_wcs.array_shape is not None:
shape_out = wcs_out.low_level_wcs.array_shape
elif shape_out is None:
raise ValueError(
"Need to specify shape_out when specifying output_projection as WCS object"
)
if shape_out is None:
if wcs_out.low_level_wcs.array_shape is not None:
shape_out = wcs_out.low_level_wcs.array_shape
else:
raise ValueError(
"Need to specify shape_out when specifying output_projection as WCS object"
)
elif isinstance(output_projection, str):
hdu_list = fits.open(output_projection)
shape_out = hdu_list[0].data.shape
Expand Down