fpack is a utility program for optimally compressing
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
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
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
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.
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).
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),
presented at the October 2009 ADASS meeting in Sapporo, Japan.
ADASS 2010 study of a potential new way to compress FITS binary tables (Poster),
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
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)
Linux 32-bit PC: fpackpc_linux.tar,
Linux 64-bit PC: fpackpc_linux_64bit.tar,
Intel Mac, Darwin 11.x (Lion):
Intel Mac, Darwin 10.x (Snow Leopard):
Windows PCs (Native): fpack.zip,
Windows PCs (under Cygwin): fpackcygwin.tar,
Installation notes: The executable files should be placed in a
suitable directory (e.g. your local /bin directory).
On unix platforms, you may need to set the file executable permission with
"chmod a+x fpack" and "chmod a+x funpack".
See the user's guide for instructions on how
to most effectively use fpack and funpack.
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
On most unix systems, build fpack and funpack
by unpacking the CFITSIO tar file, then entering the following commands:
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
cl /MD fpack.c fpackutil.c cfitsio.lib /link setargv.obj
cl /MD funpack.c fpackutil.c cfitsio.lib /link setargv.obj
- 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.