astrodendro

import aplpy
from astropy.io import fits
import matplotlib.pyplot as plt
import numpy as np
import os
from astrodendro import Dendrogram
from astrodendro.analysis import PPStatistic
from astrodendro import Dendrogram, pp_catalog
from astropy import units as u
import numpy as np
from matplotlib.patches import Ellipse

inputfits='1.3mm_910klambda_subfits.fits'
outputfits='1.3mm_910klambda_subfits_aplpy.fits'
hdu = fits.open(inputfits)
hdr = hdu[0].header
hdr

def make_new_fits():
    #change header:
    f = fits.open(inputfits)
    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)
    #print(path_exists)
    if path_exists==True:
        os.remove(outputfits)
        
    hdu.writeto(outputfits)
    
make_new_fits()

hdu = fits.open(outputfits)[0]
d = Dendrogram.compute(hdu.data, min_value=0.0009,min_delta = 0.00013,min_npix=15)
p = d.plotter()

fig = plt.figure(figsize=(60,20))
ax = fig.add_subplot(1,1,1)
ax.imshow(hdu.data,origin = 'lower',interpolation='nearest',cmap=plt.cm.jet,vmax=0.02)
for leaf in d.leaves:
    p.plot_contour(ax,astructure=leaf,lw=2,colors='red')

    s = PPStatistic(leaf)
    ellipse = s.to_mpl_ellipse(edgecolor = 'black',facecolor='none')

    ax.add_patch(ellipse)
plt.savefig('test.pdf')

d.leaves
metadata = {}
metadata['data_unit'] = u.Jy / u.beam
metadata['spatial_scale'] =  0.005 * u.arcsec
metadata['beam_major'] =  0.027 * u.arcsec
metadata['beam_minor'] =  0.022 * u.arcsec

cat = pp_catalog(d.leaves, metadata)
cat.pprint(show_unit=True, show_name=True, max_lines=70)
cat.write('table.csv', format='ascii.csv')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值