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
In [5]: wcs=WCS(naxis=3)[:8, :10, :10]
---------------------------------------------------------------------------IndexErrorTraceback (mostrecentcalllast)
CellIn[5], line1---->1wcs=WCS(naxis=3)[:8, :10, :10]
File~/Code/astropy/astropy/wcs/wcs.py:3438, inWCS.__getitem__(self, item)
3433def__getitem__(self, item):
3434# "getitem" is a shortcut for self.slice; it is very limited3435# there is no obvious and unambiguous interpretation of wcs[1,2,3]3436# We COULD allow wcs[1] to link to wcs.sub([2])3437# (wcs[i] -> wcs.sub([i+1])->3438returnself.slice(item)
File~/Code/astropy/astropy/wcs/wcs.py:3414, inWCS.slice(self, view, numpy_order)
3409table.crval[wcs_index] -=iview.start3411try:
3412# range requires integers but the other attributes can also3413# handle arbitrary values, so this needs to be in a try/except.->3414nitems=len(builtins.range(self._naxis[wcs_index])[iview])
3415exceptTypeErrorasexc:
3416if"indices must be integers"notinstr(exc):
IndexError: listindexoutofrange
This works fine for 2D WCS, I think the issue might be that _naxis is always of length 2.
As clarification, _naxis is set to the sentinel value of [0, 0] when the pixel/array shape is undefined. (I just tangled with this sentinel value on #18405.) Apparently slice() has no awareness of this sentinel value. If you define the pixel/array shape for the 3D WCS, _naxis will properly be a 3-element list, and then slicing works fine:
Activity
astrofrog commentedon Jul 9, 2025
This works fine for 2D WCS, I think the issue might be that
_naxisis always of length 2.pllim commentedon Jul 9, 2025
Why does this sound familiar? Why does @Cadair pop up in this suppressed memory?
ayshih commentedon Jul 9, 2025
As clarification,
_naxisis set to the sentinel value of[0, 0]when the pixel/array shape is undefined. (I just tangled with this sentinel value on #18405.) Apparentlyslice()has no awareness of this sentinel value. If you define the pixel/array shape for the 3D WCS,_naxiswill properly be a 3-element list, and then slicing works fine: