Space Telescope Science Institute
Intro to HST Data Handbooks 8.0 May 2011
help@stsci.edu
Table of Contents Previous Next Index Print


Introduction to the HST Data Handbooks > Chapter 4: IRAF Primer > 4.4 PyRAF Capabilities

4.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. (Note: If you have defined “~/iraf” as your home IRAF directory you can start up PyRAF from any 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 4.7. The PyRAF epar includes features like file browsing and pop-up help, which are not available in the IRAF CL.
Figure 4.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. However, 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”.
This script can be run in two ways:
--> imstat_example.run_imstat(["im1.fits[1]","im2.fits[1]"])
from the Unix shell and if the file “imstat_example.py” is executable:
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/stsci_python_epydoc/

Table of Contents Previous Next Index Print