leda FITS format site

| HyperLeda home | Documentation | Search by name | Search near a position | Define a sample | SQL Search |

This short introduction to the FITS format is written for the astronomers not accustomed to use FITS files. Its goal is to convince that many types of datasets (in particular spectra) deserve to be distributed in FITS rather than in an ad-hoc format (typically plain ASCII files).

What is FITS?

FITS, for Flexible Image Transport System, is a very general format used by astronomers to encode their data. In this section we describe the structure of a FITS file, but we do not advice astronomer to try to read/write FITS file using Fortran statements of C functions in their programs. Good libraries and tools are available for this; see next section.

At its origin, in the late 70's, it was mostly designed to store images (generally 2-dimensional) on magnetic tapes. It was soon adopted by the large observatories and therefore became the standard for "porting" data between different systems. Its major quality in this respect was that the data are stored in a binary representation independent of the internal coding of the machine where the processing is done. In the 80's, FITS was extended to describe any sort of tabular data.

A FITS file is composed by one or several Header Data Unit (HDU), each being an independent data structure: image or table. (Often, a FITS file is a single HDU). FITS is structured in records of 2880 bytes.

Each HDU contains two parts: (1) the header and (2) the data.

The header contains a series of keywords written as pairs (name, value). Each keyword is 80 bytes long (not terminated with a new-line), and consists in three fields: The name (maximum 8 characters), the value (starting at the 10th character), and optional a comment given after the value (separated by a "/") up the the 80th character. The number of keywords is unlimited, their names are largely free and the end of the header is delimited by the mandatory keyword "END". The beginning of the header must contains the following keywords: SIMPLE to tell it is a FITS file (or XTENSION if it is not the first HDU) BITPIX to give the format of the data (eg. 16 for short integer, or -32 for floating point values). NAXIS The number of axes NAXIS1 The length (number of pixels) on the first axis NAXIS2 (if NAXIS >1) Length of second axis ...

The original description of the FITS format (Wells et al. 1981) does not put much constraint on the other keywords (only 15 keywords where defined). This allows to describe almost any dataset. The most important (optional) information in the header is the coordinate system which has be re-defined very recently. This system based on several specific keywords allow to associate a pixel with "physical" coordinates, for example a position on the sky, a wavelength ...

The data section starts at the beginning of the next 2880-byte block after the END keyword. The (binary) format of the data is described in the content of the BITPIX keyword and the length data section is determined from the BITPIX, NAXIS and NAXISn keywords.

The next HDU starts at the first 2880-byte block following the current HDU...

How to handle FITS stream?

If you read the previous section, you may feel that it is quite complicated and that for your present need you would prefer to have a plain ASCII file. Fortunately, you will generally not have to care about the details of FITS to use FITS...

If you load a FITS file in your text editor, you will be able to read the header (though it may be uncomfortable if your window's width is not 80 characters, because the is no "newline" separating the keywords). You can generally not read the data.

All astronomical data-processing systems read FITS files (eg. IRAF, MIDAS ...), you can therefore easily display an image, plot tabular data and of course project data as an ASCII table. Many non-astronomical programs (eg. XVIEW) provide basic display functions, but sometimes assume that the data are images (2D, they are not suited for handling tabular data or spectra) and the support for multiple HDU is absent or limited.

If you like to access (read or create) FITS from your programs (Fortran or C) you should use an existing library. For example, the Midas environment gives interfaces for FITS files. I recommend to use fitsio, a high quality library that may be called for C or Fortran. It is robust and easy to install (and free), there is a detailed manual.

Where to find more information?

You can easily find documentation on the WEB (use your favorite search engine). There are also some papers in the astronomical literature:
  • A brief introduction
  • sci.astro.fits

  • HyperLeda Questions: leda@univ-lyon1.fr