我有一个名为“my_cube.fits”的带有 WCS 的 FITS 文件。该文件在轴 1 和 2(X 和 Y)上具有空间信息,在轴 3 (Z) 上具有光谱信息。当我使用astropy.io.fits加载它时,光谱轴为 0,空间轴为 1 和 2。文件加载如下:
import astropy.io.fits as pyfits
filename = 'my_cube.fits'
my_data = pyfits.getdata(filename)
my_header = pyfits.getheader(filename)
我一直在使用 matplotlib 来显示数据,我想知道如何使用它的 WCS 显示我的数据立方体的单个光谱框架。比方说:
from astropy.wcs import WCS
from matplotlib import pyplot as plt
my_wcs = WCS(my_header)
fig = plt.figure()
ax = fig.add_subplot(111, projection=my_wcs)
ax.imshow(my_data[5, :, :])
plt.show()
如果我这样做,我有:
...
File "/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py", line 1005, in add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/matplotlib/axes/_subplots.py", line 73, in __init__
self._axes_class.__init__(self, fig, self.figbox, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/core.py", line 49, in __init__
self.patch = self.coords.frame.patch
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 129, in patch
self._update_patch_path()
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 115, in _update_patch_path
self.update_spines()
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 192, in update_spines
self['b'].data = np.array(([xmin, ymin], [xmax, ymin]))
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 40, in data
self._world = self.transform.transform(self._data)
File "/usr/local/lib/python3.4/dist-packages/wcsaxes/transforms.py", line 166, in transform
world = self.wcs.wcs_pix2world(pixel_full, 1)
File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1329, in wcs_pix2world
'output', *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1231, in _array_converter
return _return_single_array(xy, origin)
File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1212, in _return_single_array
"of shape (N, {0})".format(self.naxis))
ValueError: When providing two arguments, the array must be of shape (N, 3)