我有一些问题,我找不到任何问题的答案。
我正在尝试在python中创建一个datacube,其中三个轴是(RA,DEC,z)
,即2个天空位置和红色移位。我认为我生成多维数据集的代码有效,我将多维数据集定义为:
cube = np.zeros([int(size_x),int(size_y),int(Nchannel)])
其中x
和y
是像素坐标,红移在通道中切片。拥有这个立方体我正在填充一些线条的强度。最后我定义了我的.fits标题如下:
hdr = fits.Header()
hdr['EQUINOX'] = 2000
hdr['CRPIX1'] = round(size_ra*3600./pix_size/2.)
hdr['CRPIX2'] = round(size_dec*3600./pix_size/2.)
hdr['CRPIX3'] = 0
hdr['CRVAL1'] = ra0
hdr['CRVAL2'] = dec0
hdr['CRVAL3'] = z_min
hdr['CD1_1'] = pix_size/3600.
hdr['CD1_2'] = 0.
hdr['CD2_1'] = 0.
hdr['CD2_2'] = pix_size/3600.
hdr['CTYPE1'] = "RA---TAN"
hdr['CTYPE2'] = "DEC--TAN"
hdr['CTYPE3'] = "Z"
hdr['BUNIT'] = "Jy/pixel"
fits.writeto('cube.fits',cube,hdr,overwrite=True)
这就是问题,我的cube.fits处于“坏”方向。当我使用ds9打开它时,z轴不是红移z ...我怀疑是一个错误的标题,但我在哪里可以在匹配标题中指定轴?干杯
轴确实是反转的,FITS使用Fortran约定(列主要顺序),而Python / Numpy使用C约定(行主要顺序)。 http://docs.astropy.org/en/latest/io/fits/appendix/faq.html#what-convention-does-astropy-use-for-indexing-such-as-of-image-coordinates
因此,对于您的立方体,您需要将轴定义为(z, y, x)
:
In [1]: import numpy as np
In [2]: from astropy.io import fits
In [3]: fits.ImageHDU(data=np.zeros((5,4,3))).header
Out[3]:
XTENSION= 'IMAGE ' / Image extension
BITPIX = -64 / array data type
NAXIS = 3 / number of array dimensions
NAXIS1 = 3
NAXIS2 = 4
NAXIS3 = 5
PCOUNT = 0 / number of parameters
GCOUNT = 1 / number of groups