Fast FITS queries in Python

Nicolas Devillard ndevilla at eso.org
Thu Feb 24 09:28:41 EST 2000


Yet another module to help making keyword queries in FITS headers, either
in C or Python.

'qfits' is an ANSI C module that offers very fast keyword queries in
FITS headers, through the use of the mmap() system call on Unix. 'qfits'
is written in portable ANSI C and should compile on any Unix system that
offers the mmap() call, i.e. any modern Unix :-).

'qfits' has been extracted from the eclipse library to build a stand-alone
module, to make it accessible from Python. A wrapper module called
'qfits_wrap.c' has been generated using SWIG, making qfits.so a callable
shared object from the Python interpreter. If you have SWIG, you can
straightaway build a callable module for Perl or Tcl (see
http://www.swig.org).

A wrapper class called 'Qfits.py' is then offered on top of the shared
object, to make the queries more Python-like. Here is an example of an
interactive session using Qfits:

>>> from Qfits import *
>>> q = Qfits('vltframe.fits')
>>> q.get('naxis')
'2'
>>> q.get('MJD-OBS')
'51275.33002418'
>>> q.get('DET.DIT')
'20.0'
>>> q.get('HIERARCH ESO DPR CATG')
"'SCIENCE '"
>>> q.get('dpr.catg', pretty=1)
'SCIENCE'
>>> q.get('simple', 'naxis', 'naxis1', 'naxis2', 'bscale', 'bzero')
('T', '2', '1024', '1024', None, None)

'qfits' is a good solution if you only want to retrieve known keywords
from a FITS header in a Python script, and you want to do it fast, without
need for a complete FITS library with bells and whistles (the distribution
tar file for 'qfits' is 12 kbytes).

'qfits' can be downloaded from the (bottom of the) following page:
http://www.eso.org/~ndevilla/saft/

-- 
Nicolas




More information about the AstroPy mailing list