[AstroPy] Updated FITS image library in (pure) Python

Andrew Williams andrew at physics.uwa.edu.au
Fri Feb 2 05:41:45 CST 2001


Something to relieve the silence on this mailing list...

I've put a new version of my Python FITS image library up at

http://www.physics.uwa.edu.au/~andrew

The new version includes support for reading and writing the data
section of FITS images, instead of just the header cards, provided the
Numeric Python high-speed array package is available. (If not, the
library can be used in stand-alone mode to handle just the header
cards, as before).

It's in pure Python, so all you need is a basic Python installation
(1.5.2 and up), plus NumPy if you want to deal with image data. This
makes it trivial to us, and much more portable, although I've only
tested it under Linux. 

Currently, the only documentation is in the form of source code
comments and function docstrings.

Typical use could be:

----------------------------------------------------------------------
import fits

f=fits.FITS('/path/test.fits','r')

et=float(f.headers['EXPTIME'])
print 'Exptime=',et,' and comment was:',f.comments['EXPTIME']
print 'History of ', f.filename,':', f.comments['HISTORY']
print 'Comments:', f.comments['COMMENT']

print "Value at 256,256 was: ",f.data[255,255]  #python arrays start at
0
f.data[255,255]=2000
print "But now = 2000"

g=fits.FITS('/path/test2.fits','r')
f.data=(f.data-g.data)*1000
f.save("/tmp/outfile.fits",fits.Float32)    #Save as 32-bit float:
BITPIX=-32
----------------------------------------------------------------------

The FITS class also defines methods for preprocessing (bias, dark, and
flat) the image, but are tailored for our observing setup and FITS
header structure. They may or may not be useful for anyone else, but
should provide a starting point for reduction code. While probably not
as fast as dedicated C or FORTRAN, the speed is pretty good (I highly
recommend NumPy), and negligible in comparison with the image readout
time, so for basic pre-processing, it's fine. 

A function 'median' is also included that takes a list of FITS objects
and returns the median image. Be warned, it's very memory hungry, as it
loads the whole of every image to do the median. There _are_ ways I
could speed this up and reduce the memory overhead by an order of
magnitude or so, but it's a low-priority job.

I've also put up 'improc.py', which has some more FITS image handler
functions, and xpa.py which communicates with SAOtng or SAOds9 FITS
image viewer, using the X Public Access mechanism (for displaying
images and defining or reading image regions)

This code is part of the user-interface to the CCD camera (an Apogee
AP7 camera lent by Ohio State University) at Perth Observatory on our
24" automated telescope. It's really just a collection of libraries
defining functions like 'exptime', inside the Python interactive
interpeter. You can script the CCD and telescope operation in Python as
you use it - a throwback to the old days of FORTH in astronomy...

Please let me know if anyone uses (or especially, extends) any of this
code.

Andrew Williams
--
Dr Andrew Williams                              andrew at physics.uwa.edu.au
Perth Observatory,                            andrew at ucc.gu.uwa.edu.au
Walnut rd, Bickley, Western Australia.    andrewW at cyllene.uwa.edu.au


_____________________________________________________
AstroPy mailing list  -  astropy at stsci.edu
http://lheawww.gsfc.nasa.gov/~bridgman/AstroPy/



More information about the AstroPy mailing list