FITS - the Flexible Image Transport System

  • Click here to find out how to read FITS files

    FITS was developed at NRAO in the late 1970's to facilitate transport and interchange of astronomical data (in particular, radio astronomy images) on magnetic tape in a manner that was easily readable in a machine-independent way on a variety of operating systems. The original system is defined by Wells & Greisen, 1979, in "Image Processing in Astronomy", eds Sedmak, Capacciolo, & Allen (Trieste Conference), 445. The system was recommended as a standard format by the International Astronomical Union in 1982. Since its conception as a simple format for handling data arrays, it has been modified and updated to permit the storage of tables of data. References include:

    All the information you are likely to need, and more, can be found at the FITS Support Office web page

    A FITS file (on tape or disk) consists of a set of header records followed by a set of data records. All fits records are 2880 bytes in length (equal to 36 80-byte cards), but taped data may use block sizes which are an integral multiple of this to increase storage efficiency. A block size of 10 (28,800 byte records) is common. All data are written as 8 bit words (360 words per record).

    The header is a sequence of 80 character ASCII card images. Each line of the header consists of a keyword and a value; the header ends with the keyword END. A FITS header must contain certain keywords in order for the data to be interpretable. These are:

    Click here to see an annotated sample FITS header.

    The data section of the file always begins on a new record boundary. FITS supports the following types of data:

    Older floating point data were often converted to scaled integers (BITPIX=16). This is the case if the keywords BZERO and BSCALE are present, and not equal to 0 and 1, respectively. The true data are recoverable as (data+BZERO)*BSCALE. It may be necessary to swap bytes to make the data intelligable to your machine; FITS readers are generally smart enough to do this because the format of the stored data is well-defined. IEEE is big-endian.

    FITS files may include extensions. One often finds a single FITS file is used to store a number of data tables or images. In this case, the header must include the line

     EXTEND  =                    T / FITS dataset may contain extensions
    
    Each extension is a separate FITS file, with its own header and data section. Some FITS readers (like that in IRAF) cannot handle extensions.

    Reading your FITS images

    IRAF

    The IRAF task rfits reads FITS files and writes them into native IRAF format. IRAF does not handle FITS extensions (at least through version 2.10).

    IDL

    Use the function READFITS. The syntax is
    D=READFITS(FILE, H, EXT=n)
    where FILE is the name of the FITS file. H and D are the output header and data arrays, respectively. Use the IDL keyword EXT=n to read FITS extension #n. Leave out the EXT keyword (or set to 0) to read the main data.

    Note that the main FITS file does not know how many extensions follow. Even if FITS keyword EXTEND = T, there need not be any extensions. If you try to read an extension that is not there, you will get a warning message.

    The IDL astronomy user's library has a number of routines that permit one to read and extract values from the FITS headers. The main routine you will need is SXPAR, which extracts values from a header array. In the example above, the header variable H is a string array. You can print it (print,H). To extract the value of a keyword into a variable V you would type V=sxpar(H,keyword), where keyword, a string, is the name of the keyword. In the example FITS header, you would print the number of coadds in the final image by typing print,sxpar(H,'NCOADDS'); you could extract the value into a variable with the line ncoadds=sxpar(H,'NCOADDS').