数据立方体的切换轴(适合文件)

switch axis for a data cube (fits file)

我遇到了一些问题,但找不到任何问题的答案。

我正在尝试在 python 中创建一个数据立方体,其中三个轴是 (RA,DEC,z),即 2 个天空位置和红移。 我认为我生成立方体的代码有效,我将立方体定义为:

cube     = np.zeros([int(size_x),int(size_y),int(Nchannel)])

其中 xy 是像素坐标,红移在通道中被分割。有了这个立方体,我用一些线条的强度填充它。最后,我将 .fits header 定义如下:

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是在"bad"方向。当我使用 ds9 打开它时,z-axis 不是 redshift z... 我怀疑 header 不好,但是我可以在哪里指定适合的轴 header? 干杯

轴确实是倒置的,FITS 使用 Fortran 约定(column-major 顺序)而 Python/Numpy 使用 C 约定(row-major 顺序)。 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