Monday, March 8, 2010

Select fits files based on header keyword

The task of selecting a list of fits files based on some header keyword value is much easier to do with the IRAF task hselect. Although this example is very useful for understanding how to use pyfits and the sys module for passing parameters via command line (like bash our Perl's @ARGV).

import sys
import pyfits
import re

for file in sys.argv[1:]: #exclude the first element of sys.argv
hdulist = #open fits
key = hdulist[1].header['OBJECT'] #reads a keyword from the fits header
if ('standard',key)): #search the keyword value for some string
print file

To execute just run on the command line:

# python file1 file2 ...


# chmod +x
# ./ file1 file2 ...

All bash's wildcards (*, ?, etc) are accepted.

No comments:

Post a Comment

Locations of visitors to this page