Skip to content

Commit ae2c7c2

Browse files
committed
resampled wcs hates us precious
1 parent df88a3f commit ae2c7c2

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ndcube/wcs/wrappers/resampled_wcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _top_to_underlying_pixels(self, top_pixels):
4242
# Convert user-facing pixel indices to the pixel grid of underlying WCS.
4343
factor = self._pad_dims(self._factor, top_pixels.ndim)
4444
offset = self._pad_dims(self._offset, top_pixels.ndim)
45-
return top_pixels * factor + offset
45+
return (top_pixels + factor/2) * factor + offset
4646

4747
def _underlying_to_top_pixels(self, underlying_pixels):
4848
# Convert pixel indices of underlying pixel grid to user-facing grid.

ndcube/wcs/wrappers/tests/test_resampled_wcs.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,34 @@ def test_int_fraction_pixel_shape(celestial_wcs):
183183
assert wcs.pixel_shape == (18, 21)
184184
for dim in wcs.pixel_shape:
185185
assert isinstance(dim, numbers.Integral)
186+
187+
@pytest.fixture
188+
def nine_nine_wcs():
189+
from astropy.wcs import WCS
190+
191+
wcs = WCS(naxis=2)
192+
wcs.wcs.ctype = ["HPLN-TAN", "HPLT-TAN"]
193+
wcs.wcs.cdelt = [2, 2]
194+
wcs.wcs.crval = [0, 0]
195+
wcs.wcs.crpix = [1, 1]
196+
197+
wcs.wcs.set()
198+
wcs.pixel_shape = [9, 9]
199+
return wcs
200+
201+
def test_corner_pixels(nine_nine_wcs):
202+
owcs = nine_nine_wcs
203+
# original corner
204+
ocorner = owcs.pixel_to_world_values(-0.5, -0.5)
205+
# one super pixel along (3 original pixels)
206+
osone = owcs.pixel_to_world_values(2.5, 2.5)
207+
208+
wcs = ResampledLowLevelWCS(owcs, 3)
209+
210+
# resampled corner == original corner
211+
corner = wcs.pixel_to_world_values(-0.5, -0.5)
212+
# One super pixel along
213+
sone = wcs.pixel_to_world_values(0.5, 0.5)
214+
215+
assert np.allclose(ocorner, corner)
216+
assert np.allclose(osone, sone)

0 commit comments

Comments
 (0)