由于ALMA数据是4维的,不能直接用aplpy去读。
把下面的脚本放在数据所在目录下,调用一下就能用aplpy画ALMA的图了
#主要用于连续谱图,不要用输出的hdu覆盖原本的fitsfile,会丢失header里的重要信息
from astropy.io import fits
from astropy.wcs import WCS
def Get2DHDU(fitsfile):
fits_file = fits.open(fitsfile)
data = fits_file[0].data
hdr = fits_file[0].header
if hdr['NAXIS']>2:
a = hdr['NAXIS']-2
for i in range(a):
data = data[0]
hdr = BuildWCShdr(hdr)
hdu = fits.PrimaryHDU(data = data, header=hdr)
return(hdu)
def BuildWCShdr(hdr):
w = WCS(naxis=2)
w.wcs.crval = [hdr['CRVAL1'],hdr['CRVAL2']]
w.wcs.crpix = [hdr['CRPIX1'],hdr['CRPIX2']]
w.wcs.cdelt = [hdr['CDELT1'],hdr['CDELT2']]
w.wcs.ctype = [hdr['CTYPE1'],hdr['CTYPE2']]
hdr_1 = w.to_header()
if 'BSCALE' and 'BZERO' and 'BMIN' and 'BMAJ' and 'BPA' and 'BTYPE' and 'OBJECT' and 'BUNIT' in hdr.tostring():
hdr_1.append(hdr.cards['BSCALE'])
hdr_1.append(hdr.cards['BZERO'])
hdr_1.append(hdr.cards['BMIN'])
hdr_1.append(hdr.cards['BMAJ'])
hdr_1.append(hdr.cards['BPA'])
hdr_1.append(hdr.cards['BTYPE'])
hdr_1.append(hdr.cards['OBJECT'])
hdr_1.append(hdr.cards['BUNIT'])
return(hdr_1)
调用的话,直接
from upper_code import *
fitsfile = 'yourALMAfitsfile'
hdu = Get2DHDU(fitsfile)
注:不能用于3D data cube