aplpy画连续谱图

import aplpy
from astropy.io import fits
import matplotlib.pyplot as plt
import numpy as np
import os

inputfits=['sim1_full.fits','sim1_910k.fits','sim2_full.fits','sim2_910k.fits','sim3_full.fits','sim3_910k.fits']
outputfits=['sim1_full_aplpy.fits','sim1_910_aplpy.fits','sim2_full_aplpy.fits','sim2_910_aplpy.fits','sim3_full_aplpy.fits','sim3_910k_aplpy.fits']

##casa 生成的fits文件无法直接被aplpy读取绘图,需要对头文件进行修改。
##主要修改方法就是删除头文件中的第三和第四轴的头文件信息,只保留前两个轴的信息。
def make_new_fits(i):
    #change header:
    f = fits.open(inputfits[i])
    hdr = f[0].header
    hdr.set('NAXIS',2)
    hdr.remove('NAXIS3')                                             
    hdr.remove('NAXIS4')                                                                          
    hdr.remove('PC1_1')                                             
    hdr.remove('PC2_1')                                             
    hdr.remove('PC3_1')                                             
    hdr.remove('PC4_1')                                             
    hdr.remove('PC1_2')                                             
    hdr.remove('PC2_2')                                             
    hdr.remove('PC3_2')                                             
    hdr.remove('PC4_2')                                             
    hdr.remove('PC1_3')                                             
    hdr.remove('PC2_3')                                             
    hdr.remove('PC3_3')                                             
    hdr.remove('PC4_3')                                             
    hdr.remove('PC1_4')                                             
    hdr.remove('PC2_4')                                             
    hdr.remove('PC3_4')                                             
    hdr.remove('PC4_4')                                                                                  
    hdr.remove('CTYPE3')                                             
    hdr.remove('CRVAL3')                                             
    hdr.remove('CDELT3')                                             
    hdr.remove('CRPIX3')                                             
    hdr.remove('CUNIT3')                                             
    hdr.remove('CTYPE4')                                             
    hdr.remove('CRVAL4')                                             
    hdr.remove('CDELT4')                                             
    hdr.remove('CRPIX4')                                             
    hdr.remove('CUNIT4')   
    #make new fits:
    hdu = fits.PrimaryHDU(f[0].data[0][0],header=hdr)
    path_exists = os.path.exists(outputfits[i])
    #print(path_exists)
    if path_exists==True:
        os.remove(outputfits[i])
        
    hdu.writeto(outputfits[i])
    
make_new_fits(1)

def subplot():
    fig = plt.figure(figsize=(21,14))
    f1 = aplpy.FITSFigure(outputfits[0],figure=fig,subplot=(2,3,1))
    f1.recenter(290.916875,14.51819444444,radius=0.0002)
    f1.show_colorscale(vmin=0.0,vmax=0.05)
    f1.add_beam()
    f1.add_colorbar()
    f1.show_contour(outputfits[0],colors='White',levels=[0.007,0.01,0.02,0.03,0.04])
    f1.add_label(0.5, 0.90, 'without embedded sources\n full uvrange', relative=True,size=20,color='White')
    
    f2 = aplpy.FITSFigure(outputfits[1],figure=fig,subplot=(2,3,4))
    f2.recenter(290.916875,14.51819444444,radius=0.0002)
    f2.show_colorscale(vmin=0.0,vmax=0.002)
    f2.add_beam()
    f2.add_colorbar()
    f2.show_contour(outputfits[1],colors='White',levels=[0.007,0.01,0.02,0.03,0.04])
    f2.add_label(0.5, 0.9, 'without embedded sources\n uvrange > 910k$\lambda$', relative=True,size=20,color='White')
    
    f3 = aplpy.FITSFigure(outputfits[2],figure=fig,subplot=(2,3,2))
    f3.recenter(290.916875,14.51819444444,radius=0.0002)
    f3.show_colorscale(vmin=0.0,vmax=0.05)
    f3.add_beam()
    f3.add_colorbar()
    f3.tick_labels.hide_y()
    f3.show_contour(outputfits[2],colors='White',levels=[0.007,0.01,0.02,0.03,0.04])
    f3.axis_labels.hide()
    f3.add_label(0.5, 0.90, 'with 3 point sources\n full uvrange', relative=True,size=20,color='White')
    
    f4 = aplpy.FITSFigure(outputfits[3],figure=fig,subplot=(2,3,5))
    f4.recenter(290.916875,14.51819444444,radius=0.0002)
    f4.show_colorscale(vmin=0.0,vmax=0.002)
    f4.add_beam()
    f4.add_colorbar()
    f4.show_contour(outputfits[3],colors='White',levels=[0.0003,0.0005,0.0007])
    f4.axis_labels.hide()
    f4.tick_labels.hide_y()
    f4.add_label(0.5, 0.90, 'with 3 point sources\n uvrange > 910k$\lambda$', relative=True,size=20,color='White')
    
    f5 = aplpy.FITSFigure(outputfits[4],figure=fig,subplot=(2,3,3))
    f5.recenter(290.916875,14.51819444444,radius=0.0002)
    f5.show_colorscale(vmin=0.0,vmax=0.05)
    f5.add_beam()
    f5.add_colorbar()
    f5.axis_labels.hide()
    f5.tick_labels.hide_y()
    f5.show_contour(outputfits[4],colors='White',levels=[0.007,0.01,0.02,0.03,0.04])
    f5.add_label(0.5, 0.9, 'with 3 compact sources\n full uvrange', relative=True,size=20,color='White')
    
    f6 = aplpy.FITSFigure(outputfits[5],figure=fig,subplot=(2,3,6))
    f6.recenter(290.916875,14.51819444444,radius=0.0002)
    f6.show_colorscale(vmin=0.0,vmax=0.002)
    f6.add_beam()
    f6.add_colorbar()
    f6.axis_labels.hide()
    f6.tick_labels.hide_y()
    f6.show_contour(outputfits[5],colors='White',levels=[0.0009,0.0015,0.0021])
    f6.add_label(0.5, 0.9, 'with 3 compact sources\n uvrange > 910k$\lambda$', relative=True,size=20,color='White')
    
    fig.savefig('simulation.pdf')
subplot()

绘制结果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值