« M8 - the Lagoon nebula | Main | NGC 6960 - The Veil Nebula »

FITS files in Python

[Pyfits] is a really useful python module that allows you to read in and write out [FITS] files. Since most astronomical data comes in FITS file format its darn important that you can read them in. Here are some basic instructions on how todo this:

Firstly ensure you have the most useful pre-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

To read a specific item from the header:

h3 = float(hdulist[0].header['CDELT3'])

To update a specific header item:

hdulist[0].header.update('BUNIT','PI')

To output the FITS file, overwritting if necessary and converting to 32bit floats:

pyfits.writeto("output.fits",float32(img_data),img_header,clobber=True)

TrackBack

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

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 April 17, 2011 12:45 AM.

The previous post in this blog was M8 - the Lagoon nebula.

The next post in this blog is NGC 6960 - The Veil Nebula.

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