SlicedLowLevelWCS.pixel_to_world_values() fails when object initialized with np.int64
See original GitHub issueDescription
This bug came through the following code using NDCube, a sunpy affiliate project.
# Plot map of Stokes I in core
I_mean = np.mean(cube[0].data, axis=(1,2)) # mean profile over map
ix_I_min = np.argmin(I_mean) # index of minimum of mean profile over map
level1_cube[0,ix_I_min, :, :].plot()
Expected behavior
I expected to see a plot.
Actual behavior
The result was a long stack trace ending with:
...
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/astropy/wcs/wcsapi/wrappers/sliced_wcs.py in _pixel_to_world_values_all(self, *pixel_arrays)
219 else:
220 ipix_curr += 1
--> 221 if self._slices_pixel[ipix].start is not None:
222 pixel_arrays_new.append(pixel_arrays[ipix_curr] + self._slices_pixel[ipix].start)
223 else:
AttributeError: 'numpy.int64' object has no attribute 'start'
If I cast ix_I_min
to int
, there is no problem.
Steps to Reproduce
This code is a minimal example to reproduce what I think is the same bug.
import numpy as np
import astropy.wcs
from astropy.wcs.wcsapi import SlicedLowLevelWCS
wcs_dict = {
'CTYPE1': 'WAVE ', 'CUNIT1': 'Angstrom', 'CDELT1': 0.2, 'CRPIX1': 0, 'CRVAL1': 10, 'NAXIS1': 5,
'CTYPE2': 'HPLT-TAN', 'CUNIT2': 'deg', 'CDELT2': 0.5, 'CRPIX2': 2, 'CRVAL2': 0.5, 'NAXIS2': 4,
'CTYPE3': 'HPLN-TAN', 'CUNIT3': 'deg', 'CDELT3': 0.4, 'CRPIX3': 2, 'CRVAL3': 1, 'NAXIS3': 3}
input_wcs = astropy.wcs.WCS(wcs_dict)
low_level = SlicedLowLevelWCS(input_wcs, [np.int64(0), 0])
low_level.pixel_to_world_values(0)
this results in:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-415-f0f7b290cda9> in <module>
9 input_wcs = astropy.wcs.WCS(wcs_dict)
10 low_level = SlicedLowLevelWCS(input_wcs, [np.int64(0), 0])
---> 11 low_level.pixel_to_world_values(0)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/astropy/wcs/wcsapi/wrappers/sliced_wcs.py in pixel_to_world_values(self, *pixel_arrays)
228
229 def pixel_to_world_values(self, *pixel_arrays):
--> 230 world_arrays = self._pixel_to_world_values_all(*pixel_arrays)
231
232 # Detect the case of a length 0 array
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/astropy/wcs/wcsapi/wrappers/sliced_wcs.py in _pixel_to_world_values_all(self, *pixel_arrays)
219 else:
220 ipix_curr += 1
--> 221 if self._slices_pixel[ipix].start is not None:
222 pixel_arrays_new.append(pixel_arrays[ipix_curr] + self._slices_pixel[ipix].start)
223 else:
AttributeError: 'numpy.int64' object has no attribute 'start'
System Details
macOS-10.15.7-x86_64-i386-64bit Python 3.8.8 (default, Feb 25 2021, 17:03:48) [Clang 12.0.0 (clang-1200.0.26.2)] Numpy 1.20.1 astropy 4.2 Scipy 1.6.0 Matplotlib 3.3.4
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I didn’t try.
@Cadair , were you able to track down which PR actually fixed it? Thanks!