This is an archival dump of old wiki content --- see for current material

Exercise 1:

 [in file]
 '''function to use regular expression matching on header keyword names
 and print all those that match

 import re
 import pyfits

 def findkeywords(filename, pattern):
     rekey = re.compile(pattern, flags=re.IGNORECASE)
     fo =
     extn = 0
     for ext in fo:
         hdrcards = ext.header.ascardlist()
         for card in hdrcards:
             mo = rekey.match(card.key)
             if mo and mo.end()==len(card.key): # to ensure match of entire key 
                 print 'ext=%d'% extn, card
         extn += 1

Exercise 2:

 [in file]
 from pyraf import iraf
 import refits

 parfile = iraf.osfn('home$scripts/findkey.par')
 t = iraf.IrafTaskFactory(taskname='findkey', value=parfile,   function=refits.findkeywords)

 [in file home$scripts/findkey.par]
 filename,s,a,"",,,"FITS file to search for keywords"
 searchstring,s,a,"",,,"Regular expression pattern"

 Then doing (in pyraf)
 --> pyexecute('')
 --> lpar findkey
      filename =               FITS file to search for keywords
  searchstring =               Regular expression pattern
         (mode = al)
 --> findkey pix.fits naxis.*
 ext=0 NAXIS   =                    2 / Number of axes
 ext=0 NAXIS1  =                  512 / Axis length
 ext=0 NAXIS2  =                  512 / Axis length   

SciPy: NumarrayTutorialSolutionSet4 (last edited 2015-10-24 17:48:23 by anonymous)