You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WCS handles negative slice index incorrectly #8771
WCS objects can be sliced, with some restrictions (e.g. no negative steps). Currently, wcs.slice returns nonsensical results if the start of the slice is negative.
I don't know that WCS should be able to handle negative start since those require knowing the number of dimensions along each axis, and discussion of that topic has been vigorous in the past (see #4669 and #5461). My particular use case is with CCDData (well, really, NDSlicingMixin) where there will always image dimensions and a negative index can be converted to positive.
The example below demonstrates the issue.
fromastropy.wcsimportWCSwcs=WCS(naxis=2)
wcs.wcs.crpix= [5, 5]
wcs.wcs.crval= [0.0, 1.0]
wcs.wcs.cdelt= [1.0, 1.0]
wcs_good_slice=wcs[4:, 4:]
# The slice below would, for an array, give the same thing# as the slice above.wcs_bad_slice=wcs[-6:, -6:]
print('crval: ', wcs.wcs.crval)
print('coordinate value at pixel [0, 0] (should be crval): ', wcs_good_slice.all_pix2world([[0, 0]], 0))
print('coordinate value at pixel [0, 0] (should be crval): ', wcs_bad_slice.all_pix2world([[0, 0]], 0))
Activity
mwcraig commentedon May 28, 2019
I'm happy to implement any of these solutions:
wcs.sliceto raise an exception if it gets a negative index.wcs.sliceto use NAXISj to convert a negative slice to a positive one.