fpack & funpack
FITS image compression programs


fpack is a utility program for optimally compressing FITS format images. The companion funpack program restores the compressed file back to its original state. These programs may be run from the host operating system command line and are analogous to the gzip and gunzip utility programs, except that they are specifically optimized for FITS format images and offer a wider choice of compression options.

fpack uses the tiled image compression convention for storing the compressed images. This convention can in principle support any number of of different compression algorithms; currently GZIP, Rice, Hcompress, and the IRAF pixel list compression algorithms have been implemented.

The main advantages of fpack compared to the commonly used technique of externally compressing the whole FITS file with gzip are:

  • It is generally faster and offers better compression than gzip.
  • The FITS header keywords remain uncompressed for fast access.
  • Each HDU of a multi-extension FITS file is compressed separately, so it is not necessary to uncompress the entire file to read a single image in a multi-extension file.
  • Dividing the image into tiles before compression enables faster access to small subsections of the image.
  • The compressed image is itself a valid FITS file and can be manipulated by other general FITS utility software.
  • Lossy compression can be used for much higher compression in cases where it is not necessary to exactly preserve the original pixel values.
  • The CHECKSUM keywords are automatically updated to help verify the integrity of the files.
  • Software that supports the tiled image compression technique can directly read and write the FITS images in their compressed form.
  • New feature (starting with v1.6.0): - can also compress FITS binary tables using a newly proposed FITS convention. This is intended for experimental feasibility studies, not for general use.

Integer format images are usually losslessly compressed using the Rice compression algorithm. As shown in the figure, the compression ratio depends on the Rice vs. GZIP image compression amount of noise in the pixel values. Rice typically gives 30% better compression than GZIP. Rice also has about 3 times faster compression speed and about the same uncompression speed as GZIP. See Paper I for more details.

Floating-point format images are usually compressed with a lossy algorithm that discards some of the noise in the image by quantizing the pixel values. A technique called "subtractive dithering" is used to minimize any statistical bias in the quantized values without introducing any additional noise in the image. See Paper II for more details. As shown in the table, the amount of image compression, and the amount of precision that is preserved, depend on the selected q quantization parameter (where q = 4 is the default value used by fpack).

q Compression Precision
8 5.3X 0.06%
4 6.4X 0.26%
2 8.0X 1.03%
1 10.0X 4.08%

More Detailed Documentation

  • User's Guide for fpack and funpack (PDF format, 10 pages)
  • Paper I on lossless compression of integer FITS images by Pence, Seaman, and White.
  • Paper II on optimal compression of floating-point FITS images by Pence, White, and Seaman.
  • ADASS 2006 paper by Seaman et al. which describes the FITS Tile Compression Convention and importance of data compression in astronomy.
  • ADASS 2009 floating-point image compression study (Poster), (Paper) presented at the October 2009 ADASS meeting in Sapporo, Japan.
  • ADASS 2010 study of a potential new way to compress FITS binary tables (Poster), (Paper) presented at the November 2010 ADASS meeting in Boston.
  • BZIP2 Feasibility Study: studies the performance of BZIP2 compared to Rice, Hcompress, and GZIP. Concludes that BZIP2 offers no unique advantages that would justify supporting it in the tiled image compression convention.

Origins

The fpack and funpack utilities were originally designed and written by Rob Seaman (NOAO). William Pence (NASA/GSFC) added further enhancements to the utilities and to the image compression algorithms in the underlying CFITSIO library. Rick White (STScI) wrote the code for the Rice and Hcompress algorithms.
Download fpack and funpack
Binary Executables - v1.6.0, Feb 2011
(linked with CFITSIO v3.300)

Source code: The fpack C source code is distributed with the CFITSIO library in the files fpack.c funpack.c, fpackutil.c, & fpack.h (as well as the fpack user's guide).

On most unix systems, build fpack and funpack by unpacking the CFITSIO tar file, then entering the following commands:

  • ./configure
  • make
  • make fpack
  • make funpack
On Windows PCs, build fpack and funpack using the Visual C++ compiler with the following command lines (after first building the CFITSIO library following the instructions in the README.win32 file that is distributed with CFITSIO):
  • cl /MD fpack.c fpackutil.c cfitsio.lib /link setargv.obj
  • cl /MD funpack.c fpackutil.c cfitsio.lib /link setargv.obj

    Notes:

    • The "/link setargv.obj" argument is optional and enables support for the "*" and "?" wildcard characters when specifying the names of the input files on the command line.
    • The "/MD" (or "/MT") argument may not be required depending on the particular OS and compiler versions.