The data of the primary HDU, and of an IMAGE extension, is an
n-dimensional array of numbers. Its type and shape come from the
header keywords BITPIX,
NAXIS and NAXISn. Tables are on the
extensions page.
BITPIX
| BITPIX | Bytes per value | Data type |
|---|---|---|
8 | 1 | Character or unsigned binary integer, 0 to 255 |
16 | 2 | 16-bit two’s complement integer |
32 | 4 | 32-bit two’s complement integer |
64 | 8 | 64-bit two’s complement integer |
-32 | 4 | IEEE 754 single-precision floating point |
-64 | 8 | IEEE 754 double-precision floating point |
Every multi-byte value is big-endian: the most significant byte first. Floats may be any IEEE value, including infinities and NaN.
Size and order
The array holds |BITPIX| × NAXIS1 × NAXIS2 × … × NAXISm bits. If
NAXIS is 0, or any NAXISn is 0, there is no data.
- The first axis varies fastest: values run along
NAXIS1(a row of an image), then each step inNAXIS2starts a new row, and so on. - Pixel indices start at 1. Images are usually shown with pixel (1, 1) at the bottom left, but the direction of each axis is given by the world coordinate keywords, not by the array itself.
- The data is padded to a whole number of 2880-byte blocks with zero bytes.
Scaling
The value a reader should use is
physical value = BZERO + BSCALE × stored value
with BSCALE defaulting to 1.0 and BZERO to 0.0. The units of
the physical value are in BUNIT. For float arrays the standard does not
recommend scaling.
Unsigned integers and signed bytes
FITS has no unsigned 16, 32 or 64-bit type and no signed byte. They are stored as the
other signedness with a fixed BZERO and BSCALE = 1.0:
| BITPIX | Stored as | Physical type | BZERO |
|---|---|---|---|
8 | Unsigned | Signed byte | -128 (−27) |
16 | Signed | Unsigned 16-bit | 32768 (215) |
32 | Signed | Unsigned 32-bit | 2147483648 (231) |
64 | Signed | Unsigned 64-bit | 9223372036854775808 (263) |
Adding BZERO to the stored value is the same as flipping its top bit, so
a reader can convert without arithmetic overflow.
Undefined values
- Integer arrays: the
BLANKkeyword gives the stored value that marks an undefined pixel. It is compared with the stored value, before scaling. - Float arrays: undefined pixels are IEEE NaN.
BLANKmust not be used withBITPIX-32 or -64. DATAMINandDATAMAXgive the range of valid physical values, leaving out undefined ones.
Random groups
Random groups is an older layout for the primary HDU, made for radio interferometry. The standard deprecates it for any other use. Its header is:
| Keyword | Value |
|---|---|
SIMPLE | T |
BITPIX | Type of every parameter and array value, as above |
NAXIS | 1 to 999 |
NAXIS1 | 0, the sign of random groups |
NAXIS2 … NAXISn | The axes of each group’s array |
GROUPS | T |
PCOUNT | Number of parameters before each array |
GCOUNT | Number of groups |
PTYPEn | Name of parameter n; parameters with the same name are added together |
PSCALn | Scale of parameter n, default 1.0 |
PZEROn | Offset of parameter n, default 0.0 |
The data is GCOUNT groups, each made of PCOUNT parameter
values followed by an array of NAXIS2 × … × NAXISn values, all of the
BITPIX type. The size is
|BITPIX| × GCOUNT × (PCOUNT + NAXIS2 × … × NAXISn) bits. A parameter’s
physical value is PZEROn + PSCALn × stored value; the array values use
BSCALE and BZERO.
A small image
A 2 by 2 image of unsigned 16-bit values (BITPIX = 16,
BZERO = 32768) holding 0, 1, 32768 and 65535. The stored values are
−32768, −32767, 0 and 32767:
00000B40 80 00 80 01 00 00 7F FF 00 00 00 00 00 00 00 00
B40): row 1, then row 2, then zeros to the end of the block