« Christmas Tree Cluster | Main | CASA leap seconds issue »

Spectral Extraction in Python

I've wrote about how to read in FITS files in Python before, but I thought I'd readdress as I've been writing lots about fitting and wanted to build up to fitting properly calibrated data. So in this example I will add how to extract a spectra too. For this example I'm going to use a calibration lamp taken at the University of Birmingham Observatory. Both the script described here and the data will be given below. The output looks like:

Spectral Plotting

So let's start with reading in a FITS file. Firstly ensure you have the most useful per-requisites ([Pyfits], [numpy], [scipy]) and import them:

import pyfits, numpy, scipy

Now read in the file:

input_file = "A.fits"
hdulist = pyfits.open(input_file)

Get the data:

img_data = hdulist[0].data

Get the header:

img_header = hdulist[0].header

(more on FITS)

Now lets use some calibration data (which can be downloaded):

import pyfits, numpy, scipy, pylab
from scipy import *
from pylab import *
input_file = "Neon.fits"
hdulist = pyfits.open(input_file)
img_data = hdulist[0].data

We know that the spectra, by looking at the FITS file with DS9 has data in a small aperture. For now we will ignore any averaging. Lets take line 144 as we know there is data.

data_use = img_data[144]

Plot the spectra:

fig = figure(figsize=(9, 9)) #make a plot
ax1 = fig.add_subplot(111)
ax1.plot(img_data[144]) #spectrum
setp(gca(), ylabel="Un-normalised power", xlabel="Pixel Position")
pylab.savefig("plot_spectra.png")


We have now extracted the data for a spectral column. I will follow this post up in the not to distant future with how to now identify the lines and run spectral calibration. Once you have this you can apply to a target spectra. Of course I've so far also ignored dark/bias counts but these can be easily dealt with.

The above can be downloaded as extract_spectra.py and the data Neon.fits (this is zipped, use gunzip).

TrackBack

TrackBack URL for this entry:
http://krioma.net/cgi-bin/MT-3.38/mt-tb.cgi/590

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on December 10, 2011 4:24 PM.

The previous post in this blog was Christmas Tree Cluster.

The next post in this blog is CASA leap seconds issue.

Many more can be found on the main index page or by looking through the archives.

Get Firefox! Valid XHTML 1.0! Valid CSS! RSS Feed BlogUniverse - listed Powered by Apache Creative Commons License ringsofsaturnrock's Most Interesting Photos on Flickriver

Powered by
Movable Type 3.38