STScI Logo
STScI Logo
HST
Banner
STScI

HST Data Handbook

TOC PREV NEXT INDEX PDF

A.4 PyRAF Capabilities


PyRAF is a Python package that runs IRAF tasks from Python. All the features of Python are available when you run PyRAF. In addition, you can run IRAF tasks using the same syntax that you would use in the IRAF CL.

To start a PyRAF session:

  1. Move to your IRAF home directory.
  2. Type "pyraf" at the command line.

Like IRAF, several lines of introductory text will be displayed, and a prompt will appear at the bottom of the screen.

To quit a PyRAF session:

Type ".exit".

Setting parameters with eparam in PyRAF

In PyRAF, the epar editor uses a graphical user interface (GUI), as shown in Figure A.7. The PyRAF epar includes features like file browsing and pop-up help, which are not available in the IRAF CL.

Figure A.7: Editing parameters with epar in PyRAF.


 

Advantages of using PyRAF

There are many advantages of PyRAF over the IRAF CL. The error handling of PyRAF is superior. When using CL scripts and encountering an error, PyRAF reports the line number in the CL script where the error occurred. Python has excellent string handling capabilities and other features. Scripts can be written in Python, although you can still write and use CL scripts.

PyFITS can be used to read a FITS image or table to an in-memory array (a numpy array). Arithmetic manipulation can be performed with numpy arrays and results written to FITS images or tables. Although, there are certainly cases where it would be difficult to duplicate the features of an IRAF task using simple in-memory array arithmetic, tasks such as imcombine.

IRAF tasks are easily run from PyRAF. Interactively, there is no noticeable difference from the IRAF CL, but in a Python script you would preface the name of any IRAF task with "iraf." (including the period). For example: "iraf.phot".

The following Python script runs the IRAF task imstatistics. It is saved in a file called "imstat_example.py".

 #! /usr/bin/env python
 
 import sys
 from pyraf import iraf
 
 def run_imstat(input):
        iraf.images()
        for image in input:
              iraf.imstat(image)
 
 if __name__ == "__main__":
       run_imstat(sys.argv[1:])

This script can be run in two ways:

  • from Python or PyRAF:
     --> import imstat_example
     --> imstat_example.run_imstat(["im1.fits[1]","im2.fits[1]"])
    

  • from the Unix shell and if the file "imstat_example.py" is executable:
     %> imstat_example.py im1ex1.fits im2ex1.fits
    

In the first example, the argument to the script is a list of two different images, each specifying the first extension of each FITS file. In the second example, each of the files passed as a parameter to the script contains the first extension of the FITS images used in the first example. For further information, see the PyRAF Programmer's Guide, which can be downloaded from:

 http://stsdas.stsci.edu/pyraf/stscidocs/index.html

Space Telescope Science Institute
http://www.stsci.edu
Voice: (410) 338-1082
help@stsci.edu
TOC PREV NEXT INDEX PDF

Copyright  | Help  | Printable Page