AstroPy: PySpec - a simple PyFITS application

W.T. Bridgman wtbridgman at radix.net
Mon Apr 5 22:46:51 EDT 1999


#!/usr/bin/env python1.5
#
# Program:     PySpec v0.001?
# Author:      W.T. Bridgman
# Date:        April 5, 1999
# Language:    Python v1.5.1
# Platform/OS: Macintosh, MacOS 8.5.1
#
# Should be reasonably platform independent
# Let me know!
# Not the most elegant Python, but it does work!
# Basic sample of doing a simple task with PyFITS
#
#
# Need the mytest.fits file, Konrad Hinson's TkPlotCanvas.py,
# fitsio.py & the recordmodule
# Click the 'DRAW' button when the window appears
#
# FYI: The mytest.fits file contains a simulated x-ray
#      spectrum of an accretion disk.  The reflected component
#      reveals an iron flourescence line.
#
###################################################
#  quick sample using PyFITS with TkPlotCanvas
#
import TkPlotCanvas
import Numeric
from fitsio import *
from Tkinter import *

# extract some FITS information first
fin = Ffile('mytest.fits')
fhdu=[]
fhdu.append(fin.read())

# now examine SPECTRA extension
fhdu.append(fin.read())
nbytes=fhdu[1].head['NAXIS1']
nrows=fhdu[1].head['NAXIS2']

print "Rows: ",nrows," & bytes/row: ",nbytes

clip=40 # chop off some problem points at the end of the arrays

energy=Numeric.zeros([nrows],Numeric.Float64)
incident=Numeric.zeros([nrows],Numeric.Float64)
transmitted=Numeric.zeros([nrows],Numeric.Float64)
reflected=Numeric.zeros([nrows],Numeric.Float64)

# load the data buffer into numeric arrays
# is there a better way to load the columns into Numeric arrays?
for i in range(nrows):
    energy[i] = fhdu[1].data[i,0]
    incident[i] = fhdu[1].data[i,2]
    transmitted[i] = fhdu[1].data[i,3]
    reflected[i] = fhdu[1].data[i,4]

# convert to format suitable for PolyLine
# also convert for logarithmic scaling
data1=Numeric.zeros([clip,2],Numeric.Float64)
data1[:,0]=Numeric.log10(energy[0:clip])
data1[:,1]=Numeric.log10(incident[0:clip])
line1=TkPlotCanvas.PolyLine(data1,color='green')

# convert to format suitable for PolyLine
# also convert for logarithmic scaling
data2=Numeric.zeros([clip,2],Numeric.Float64)
data2[:,0]=Numeric.log10(energy[0:clip])
data2[:,1]=Numeric.log10(transmitted[0:clip])
line2=TkPlotCanvas.PolyLine(data2,color='red')

# convert to format suitable for PolyLine
# also convert for logarithmic scaling
data3=Numeric.zeros([clip,2],Numeric.Float64)
data3[:,0]=Numeric.log10(energy[0:clip])
data3[:,1]=Numeric.log10(reflected[0:clip])
line3=TkPlotCanvas.PolyLine(data3,color='blue')

window=Frame()
window.pack(fill=BOTH, expand=YES)

# Make the graph object
object=TkPlotCanvas.PlotGraphics([line1,line2,line3])

# now prep the window for plotting
c = TkPlotCanvas.PlotCanvas(window, "200m", "140m", relief=SUNKEN, border=2)
c.pack(side=TOP, fill=BOTH, expand=YES)

# allocate buttons for window
Button(window, text='Draw', command=lambda o=object:
       c.draw(o, 'automatic', 'automatic')).pack(side=LEFT)
Button(window, text='Clear', command=c.clear).pack(side=LEFT)
Button(window, text='Redraw', command=c.redraw).pack(side=LEFT)
Button(window, text='Quit', command=window.quit).pack(side=RIGHT)

# and now enter the command loop
window.mainloop()
fin.close()


__________________________________________________
AstroPy mailing list  -  astropy at athena.gsfc.nasa.gov
http://lheawww.gsfc.nasa.gov/~bridgman/AstroPy/



More information about the AstroPy mailing list