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.
Like IRAF, several lines of introductory text will be displayed, and a prompt will appear at the bottom of the screen.
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.
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”.
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: