• pyfits例子


    下面是一个读入fits文件,画积分强度图,再把某个星表里的天体画到图上的python程序。
    ======================================================================
    #!/usr/bin/env python

    import pyfits
    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)

    # image[z,y,x]!!!! The first dimension is velocity channel!
    Z = image[0,:,:]
    Z = Z*0.0
    for i in range(0,nz):
      Z = Z+image[i,:,:]

    # set negative value to zero
    Z = (Z+abs(Z))/2.0

    ax = plt.subplot(111)
    im = plt.imshow(Z, cmap=cm.gist_yarg,
                    origin='lower', aspect='equal',
                    extent=[max(x),min(x),min(y),max(y)])
    locs, labels = plt.xticks()
    xtv = locs
    for i in range(0,len(locs)):
        xtv[i] = int((locs[i]-int(locs[i]/15.0)*15.0)/15.0*60.0)
    x_ticks=[str(xtv[0]),str(xtv[1]),str(xtv[2]),str(xtv[3]),
              str(xtv[4]),'04h '+str(xtv[5])+' m' ,'04h '+str(xtv[6])+' m']
    plt.gca().set_xticklabels(x_ticks)

    ra,dec,major,minor,angle = np.loadtxt('catalog.txt',unpack=True,usecols=[16,17,18,19,20])
    xr = ra
    yd = dec
    angle=90.0-angle
    for i in range(len(ra)):
        yd[i] = dec[i]
        xr[i] = (ra[i]-crvalx)*math.cos(dec[i]*3.1415926/180.0)+crvalx

    ells = [Ellipse(xy=[xr[i],yd[i]],width=major[i]*2,height=minor[i]*2,angle=angle[i])
            for i in xrange(len(ra))]

    for e in ells:
        ax.add_artist(e)
        e.set_alpha(1.0)
        e.set_clip_box(ax.bbox)
        e.set_edgecolor([0.0,1.0,0.0])
        e.set_fill(False)
        e.set_linewidth(0.5)

    plt.colorbar(im,orientation='vertical')
    plt.show()
    ==========================================================

  • 相关阅读:
    VS2005入门.Net2.0系列视频教程181级打包下载
    Asp.Net2.0视频教程 之 WebPart概述 [视频]
    MemberShip,角色,WebPart在web.config文件中的参数简述
    vs2005入门 .Net2.0视频教程 之 SQL查询语法基础 [视频]
    关于进期教程发布事宜通告
    从我博客的访客地域分布分析看我国学.net的人
    《Vs2005网站编程》目录雏形
    Asp.Net2.0视频教程 之 WebPart 一 [视频]
    vs2005入门 .Net2.0视频教程 之 浅尝存储过程[视频]
    vs2005视频教程 之 TreeView高级使用 [视频]
  • 原文地址:https://www.cnblogs.com/heshangaichirou/p/5200596.html
Copyright © 2020-2023  润新知