当前位置: 首页 > 工具软件 > Alma > 使用案例 >

python3基于spectral_cube.py抽取ALMA数据的分子谱线供XCLASS使用

董和风
2023-12-01
from astropy.io import fits
from spectral_cube import SpectralCube as spec
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.table import Table
import astropy.units as u
import math

names = ['I14498_spw25',
         'I14498_spw27',
         'I14498_spw29',
         'I14498_spw31']

files = 'I14498_core.txt'
core_info = np.loadtxt(files,usecols=(0,3,4),unpack=True)

for i in range(len(names)):
    for j in range(len(core_info[0])):
        extra_spec(i,core_info[0,j],core_info[1,j],core_info[2,j])

def extra_spec(n,core,x,y):
    ra_pix = math.floor(x)
    dec_pix = math.floor(y)
    cube = spec.read(names[n]+'.cube.image.pbcor.fits')  
    data_temp = cube[:,dec_pix:dec_pix+1,ra_pix:ra_pix+1]
    hdr = data_temp.hdu.header
    Tb_K = data_temp.to(u.K).hdu.data[:,0,0]
    freq_MHz = []
    for i in range(len(Tb_K)):
        freq_temp = (hdr['CRVAL3'] + i * hdr['CDELT3'])/1e6
        freq_MHz.append(freq_temp)
    np.savetxt(names[n]+'_'+str(core)+'.txt',np.column_stack((freq_MHz,Tb_K)),fmt='%.6f')
I14498_core.txt内容如下:
1	    14:53:43.6245	-059.08.43.9825	164.47 	321.26
2	    14:53:44.0436	-059.08.48.9909 139.67  282.73
3	    14:53:43.5404	-059.08.48.8999	169.45 	283.43
4	    14:53:42.4332	-059.08.46.3865	234.97 	302.76
5	    14:53:43.1734	-059.08.54.0886	191.16 	243.52
6	    14:53:42.7100	-059.08.52.8408	218.59 	253.12
7	    14:53:42.7841	-059.08.57.6358	214.20 	216.23 
8	    14:53:42.1879	-059.08.57.1660	249.48 	219.85
9	    14:53:42.9431	-059.09.00.6710	204.79 	192.88
10      14:53:41.5840	-059.09.00.0270	285.20 	197.80
 类似资料: