Skip to content

resampled wcs hates us precious #857

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions ndcube/wcs/wrappers/resampled_wcs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import numpy as np

from astropy.wcs.wcsapi.wrappers.base import BaseWCSWrapper
Expand Down Expand Up @@ -42,13 +43,13 @@ def _top_to_underlying_pixels(self, top_pixels):
# Convert user-facing pixel indices to the pixel grid of underlying WCS.
factor = self._pad_dims(self._factor, top_pixels.ndim)
offset = self._pad_dims(self._offset, top_pixels.ndim)
return top_pixels * factor + offset
return (top_pixels * factor) + 1 + offset

def _underlying_to_top_pixels(self, underlying_pixels):
# Convert pixel indices of underlying pixel grid to user-facing grid.
factor = self._pad_dims(self._factor, underlying_pixels.ndim)
offset = self._pad_dims(self._offset, underlying_pixels.ndim)
return (underlying_pixels - offset) / factor
return (underlying_pixels - 1 - offset) / factor

def _pad_dims(self, arr, ndim):
# Pad array with trailing degenerate dimensions.
Expand Down
31 changes: 31 additions & 0 deletions ndcube/wcs/wrappers/tests/test_resampled_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,34 @@ def test_int_fraction_pixel_shape(celestial_wcs):
assert wcs.pixel_shape == (18, 21)
for dim in wcs.pixel_shape:
assert isinstance(dim, numbers.Integral)

@pytest.fixture
def nine_nine_wcs():
from astropy.wcs import WCS

wcs = WCS(naxis=2)
wcs.wcs.ctype = ["HPLN-TAN", "HPLT-TAN"]
wcs.wcs.cdelt = [2, 2]
wcs.wcs.crval = [0, 0]
wcs.wcs.crpix = [1, 1]

wcs.wcs.set()
wcs.pixel_shape = [9, 9]
return wcs

def test_corner_pixels(nine_nine_wcs):
owcs = nine_nine_wcs
# original corner
ocorner = owcs.pixel_to_world_values(-0.5, -0.5)
# one super pixel along (3 original pixels)
osone = owcs.pixel_to_world_values(2.5, 2.5)

wcs = ResampledLowLevelWCS(owcs, 3)

# resampled corner == original corner
corner = wcs.pixel_to_world_values(-0.5, -0.5)
# One super pixel along
sone = wcs.pixel_to_world_values(0.5, 0.5)

assert np.allclose(ocorner, corner)
assert np.allclose(osone, sone)
Loading