获取aplpy可直接读取画图的2Dhdu

由于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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值