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.

fpack also supports the tiled table compression convention for compressing FITS binary tables, which generally provides significantly greater compression than can be achieved by simply compressing the FITS file with gzip.

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.
  • 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.
How to get and use fpack and funpack
See the user's guide for instructions on how to use fpack and funpack most effectively.

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 fpackguide.pdf 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, fpack and funpack are automatically built when using CMAKE to build the CFITSIO library. See the README.win file that is distributed with CFITSIO for details.