IRAF Newsletter -- Number 14 -- April 1998

[ Previous ] [ Next ] [ Table of Contents ] [ Search this issue ]


Hints on Reading and Writing FITS Files

IRAF V2.11 includes the new FITS image kernel, as mentioned in other articles in this Newsletter. The dataio tasks rfits and wfits have been enhanced in V2.11 to support reading and writing multi-extension FITS files (FITS files containing more than one image). The focus of this article is to alert the IRAF user to differences between V2.11 and earlier versions of IRAF in handling single-image FITS files, in particular, and image files in general. A general rule to keep in mind is that IRAF V2.11 requires that all image files have some type of file name extension to define which type of image they are, be they native IRAF images, FITS images, ST GEIS-format images, and so on (the one exception to this rule is rfits , which will read FITS format disk files that do not have any extensions).

The syntax for reading single-image FITS files from tape has not changed. In the following example we've set the "oldiraf" parameter to "yes" to attempt to restore the original IRAF names:

But what if you would like to read these same files onto disk, not as IRAF images, but as FITS files? You will then need to tell IRAF that you wish to generate FITS images on disk; this can be done by setting the "imtype" environment variable to an appropriate value (see more on imtype and the new environment variable "imextn" elsewhere in this Newsletter).

For single image tape files, this will create images "image0001.fits", "image0002.fits", etc. It should be noted, however, that these images have been processed by the FITS kernel and that their image headers will thus be modified slightly in the process. Using rfits in this way should be fine for most single image files, but multi-extension FITS files would be split apart by this command. When a direct copy of FITS files (multi-extension or not) from tape to disk is desired, the reblock or t2d tasks may be used:

This creates FITS files "image0001", "image0002", and "image0003" on disk. If these disk files are to be used by any IRAF applications (other than rfits ) extensions must be added to these filenames. This can be done with the rename task:

Now the images will be called "image0001.fits", and so on.

If you have FITS files on a tar tape (written prior to IRAF V2.11), then when these FITS files are restored to disk they will probably not have any file name extensions associated with them. If you plan to use these files directly with IRAF applications you will need to use rename , as above, to add the ".fits" extensions to these files before IRAF applications will recognize them as image files.

Restoring single-image FITS files on disk to IRAF images is done with rfits as before. But many users may find that their favorite rfits command will no longer work as expected. To read FITS files on disk to IRAF images use a command similar to

Note the use of "0" for the "File/extensions list" parameter. If you are used to using "1" for this parameter value, you will need to change your ways. Now that rfits recognizes multi-extension FITS files, "0" refers to the primary (first) FITS unit and "1" refers to the first FITS extension in a multi-extension FITS file. For a classic FITS image with no extensions, the image data is in the first FITS unit, number 0.

Writing IRAF images to a FITS-formatted tape is done with wfits as in previous IRAF versions. Note however that if you use wfits to generate FITS files on disk that, by default, these FITS images will have a ".fits" extension. See the parameter file for wfits .

If you are writing single or multi-extension FITS files from disk to tape then there are several considerations.

To directly write disk FITS images to tape, reblock may again be used.

Here we have specified that we are writing to a blank tape, and have set the output block size to 28800 bytes (ten 2880 FITS logical records per block).

The wfits task could also be used to copy files from disk to tape. By default each disk image would become one tape file

Or one may also use wfits to combine individual disk images into a multi-extension FITS file on tape, with or without a global FITS header:

In this example, no global header would be created, and so the first file on disk would become the zeroth extension in the tape FITS file.

Dave Bell

[ Previous ] [Next ] [ Table of Contents ] [ Search this issue ]

IRAF Group, National Optical Astronomy Observatories, P.O. Box 26732, Tucson, AZ 85726, Phone: (520) 318-8160, FAX: (520) 318-8360, Email iraf@noao.edu

Posted: 07May1998