人生的意义就是思考其意义分享 http://blog.sciencenet.cn/u/qianlivan 天体物理工作者,家乡云南昆明。

博文

python数据处理笔记(三)通道积分图

已有 7877 次阅读 2012-5-25 10:41 |个人分类:知识|系统分类:科研笔记| Python, 通道积分

      通道积分是除了p-v图外又一件分析分子云气体运动的利器。在不同的通道查看,可以看到一些速度不同寻常的气体,这些气体就是恒星形成研究中十分感兴趣的高速气体。这些高速气体对于分子云中的能量平衡以及恒星的形成过程可能起着关键的作用。
      下面是一个将每3个通道积分,画出积分强度的小程序。这个程序其实和画积分强度的程序如出一辙,只是为了方便和专用,另写一个。

============================================================
#!/usr/bin/env python

import pyfits
from pylab import *
import sys

import math
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import mpl_toolkits
from matplotlib.patches import Ellipse

hdulist = pyfits.open('xxx.fits')
image = hdulist[0].data
nx = hdulist[0].header['naxis1']
ny = hdulist[0].header['naxis2']
nz = hdulist[0].header['naxis3']
crvalx = hdulist[0].header['crval1']
cdeltax = hdulist[0].header['cdelt1']
crpixx = hdulist[0].header['crpix1']
crvaly = hdulist[0].header['crval2']
cdeltay = hdulist[0].header['cdelt2']
crpixy = hdulist[0].header['crpix2']
crvalz = hdulist[0].header['crval3']
cdeltaz = hdulist[0].header['cdelt3']
crpixz = hdulist[0].header['crpix3']

x = np.arange(-crpixx*cdeltax+crvalx,(nx-1-crpixx)*cdeltax+crvalx,cdeltax)
y = np.arange(-crpixy*cdeltay+crvaly,(ny-1-crpixy)*cdeltay+crvaly,cdeltay)
z = np.arange(-crpixz*cdeltaz+crvalz,(nz-1-crpixz)*cdeltaz+crvalz,cdeltaz)
z = z/1000.0
#X, Y = np.meshgrid(x, y)

# image[z,y,x]!!!! The first dimension is velocity channel!


print 'input'
print 'centerx,centery,xscale,yscale'
line = sys.stdin.readline()
[centerx,centery,xscale,yscale] = line.rstrip().split(',')
centerx=int(centerx)
centery=int(centery)
xscale=int(xscale)
yscale=int(yscale)

for i in range(25):
   Z=image[i*3,(centery-yscale):(centery+yscale+1),
               (centerx-xscale):(centerx+xscale+1)]
   for j in range(2):
       Z=Z+image[i*3+j+1,(centery-yscale):(centery+yscale+1),
                         (centerx-xscale):(centerx+xscale+1)]

       ax = plt.subplot(5,5,i+1)
       im = plt.imshow(Z, cmap=cm.spectral,
                      origin='lower', aspect='equal')

plt.show()
============================================================

channel1.0.py

channel2.0.py

channel3.0.py

channel4.0.py





https://blog.sciencenet.cn/blog-117333-574767.html

上一篇:python数据处理笔记(二)p-v图
下一篇:旧时光(一)看《黑炮事件》
收藏 IP: 159.226.169.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-14 16:45

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部