Using IRAF in Swain West 311






About IRAF:


The IRAF software package (Image Reduction and Analysis Facility) was developed at the National Optical Astronomy Observatories for use with astronomical data in the early 1980s, and has become the primary software used by astronomers for handling data. IRAF was adopted by the Space Telescope Science Institute for use with HST data, and is also used for data from several other NASA missions and facilities. It is distributed for free, and runs on Linux, Unix, and OS X platforms, among others.


IRAF contains many routines or tasks designed to do specific data reduction or analysis jobs. The tasks are organized into packages related to specific types of data or functions. Examples of packages include dataio (reading and writing data), ccdred (reducing CCD data), and onedspec (for processing spectra). Specific tasks in the dataio package include rfits (to read fits images), wfits (to write fits images), etc.


Getting Started:


Because IRAF uses interactive graphics, it runs from a particular window called an "xgterm" window. Before starting IRAF, you must open an xgterm window by

typing "xgterm &" in any shell window (or use the icon on the screen). The command xgterm opens the new window and the & returns the prompt to the shell window so you can use that one for other things. To change the default fontsize, hold down the control key and the middle mouse button simultaneously.


If you will be displaying images, also start up the image tool window by typing "ximtool & " or "ds9 &" in the shell or other window


Once the xgterm window is open, you can begin an IRAF session by typing "cl" (command language) in the xgterm window.


To quit an IRAF session, type "logout" in the xgterm window.


Once IRAF is started, you can load the particular packages with the tasks you need by typing the names of the packages. To unload a package, type "bye" in the xgterm window. (You do not need to unload packages before logging out of IRAF.)


To execute a task, simply type the name of the task (e.g. typing "rfits" will execute the task rfits).


Type "help packagename" to find out what tasks a package contains and "help taskname" to find out what a particular task does (and how it works).


Text Box: The delete key: An annoying quirk of IRAF in the xgterm window is that the backspace key does not work.  Use the delete key instead.


The File:


When you start IRAF, the file is used to set the defaults for how IRAF operates. These include the definition of where your IRAF home directory is, where the data pixels are stored, which editor you use, which printer plots are sent to, etc. The file is already present in your home directory on the computer and it has been edited to match our local environment. You may want to look at the file once you are familiar with IRAF and make further changes to match your own style. If you are using large images (10242 or 20482 images, for example), it is helpful to set stdimage=imt1024 or stdimage=imt2048 in the file.


If you are using IRAF on another computer, you will need to execute the command mkiraf to set up the necessary directories and files for IRAF to run from your account. Once you have run mkiraf you will not need to so again. mkiraf will create a file in your directory, and you can edit the file to change the defaults to suit your own needs.




Parameter Files:

Each IRAF task has a parameter file that specifies the values of the parameters needed to run that task. To find out what the parameters (and their values) are for a particular task, type

> lpar taskname


Some parameters are enclosed in parenthesis. The task assumes the values given in the parameter set for these parameters (called "hidden" parameters) whenever the task is run. The values of all other parameters must be specified either on the command line each time a task is executed, or interactively during the execution of a task.


To edit a parameter file, type e.g.

> epar taskname


Use the arrow keys (right side of keyboard) to navigate. Enter the new parameter value and the enter key to change it. To exit the parameter set editor and save the new values, type

> :q (or CNTL-d)


To exit and execute the command with the new parameter values, type

> :go


The parameter values are saved and will be used whenever the task is executed unless you edit the parameter file again, or specify otherwise on the command line. To reset the task parameters to their original, default values, type


> unlearn taskname


Alternatively, you can execute a command without modifying the parameter file by including the parameter settings on the command line. In that case, the parameter file is not changed. Note that there are short and long ways to do this. You need only to type enough characters that the procedure/parameter is uniquely identified:

>imhead imagename long=yes

is equivalent to:

>imhead imagename l+

Image Formats:


Most images used in IRAF are in one of two formats: "FITS" images or "IRAF" images.

Most data begin as FITS images. FITS stands for Flexible Images Transport System, and is a standardized format used by most observatories for astronomical images. While most IRAF tasks work well with either format, some work only with the IRAF image format. The tasks rfits and wfits are used to convert images back and forth between the two formats.


The FITS format is a self-contained file with both the pixel values and the header information. IRAF images separate the header information and the pixel values into two separate files. The large pixel files are usually stored in a separate directory (the imdir directory, defined in the file), and only the headers are kept in your working directory.




Frequently-Used Commands:


To execute an IRAF task, simply type the name of the task followed by any necessary parameters. For example, the command imhead allows you to examine the contents of the image header. Check out the parameter file (via "lpar") and the help file (via "help") to see the different options for running imhead. For example, try the following:

> imhead imagename

> imhead imagename long+


will print the full image header to the screen.

> imhead imagename long+ | page


will break the header into screen-sized portions by "piping" the output of the imhead task into the page task.

Other frequently used commands include:


Copy an image


Delete an image (similar to Linux "rm")


Rename an image (similar to Linux "mv")


Show the image header


Display an image


Examine a displayed image interactively


NOTE: **NEVER EVER EVER** use the Linux commands "rm", "mv" etc. on .imh files; you must manipulate them using IRAF in order to access the .pix files at the same time.




Displaying Images:


The command "display" displays an image.


Try out "display" on one of your images, first using autoscaling:

> display imagename 1


Practice using the mouse to adjust the contrast and learn how to manipulate the display using the SAOImage controls.


The task imexamine allows you to examine the image interactively, and performs such functions as displaying cuts along rows or columns, or surface plots, etc. Useful commands to get you started are:



Plot of a column or average of columns


Plot of a line or average of lines


Gaussian fit to circular aperture


Print cursor location in image coordinates


Statistics of circular aperture at position


Exit imexamine


See the "help imexamine" documentation. You'll use imexamine a lot, so it is worth studying the documentation and then practicing with it to see what it can do for you. To quit imexamine, type q with the cursor on the display.




What do I do if IRAF crashes?


  • First, flush the process cache by typing

> flpr (pronounced "flipper") a couple of times if something aborts or crashes.


  • If an IRAF task is hung and you don't have a cursor in the xgterm window, try typing


> CNTL-c (hold the control key down and type a c at the same time), and then a flpr.

  • If things remain hung, try logging out of IRAF completely and then restarting.


  • If you want to abort a task in the plot window, shift-I usually works.



Linux Commands:


Some Unix commands are identical to IRAF commands, e.g.

> ls *.imh

whereas others are not ("more" for example is "type" within IRAF). Unix commands can be run within the IRAF environment by preceding them with a "!" (pronounced "bang").

> !lpr textfilename



Running a command again:


IRAF stores a history of the commands you type. You can recapture a recent command via one of several methods. Type

> history


To show the recent commands.


> e


will show the most recently executed command and allow you to edit it with the arrow keys.


> ^


will execute the most recent command automatically.




More Information About IRAF


To learn more about IRAF, visit the IRAF website at Many manuals and documents are available to describe the software and data reduction procedures, and the IRAF tutorials can help you become more familiar with IRAF's many packages and tasks.

        IRAF Project Home Page (

        The IRAF tutorials page (

        IRAF Recommended Docs (



This document is derived from one prepared by Martha Haynes at Cornell University, and is used at Indiana University to introduce undergraduate students to IRAF.