scientific format
FITS — astronomy and solar images
Read FITS headers and images, including tile-compressed images.
Format feature card
Read FITS as data.
Typed pixels in FITS order; no resampling and no flip
Input
FITS primary and image HDUs; GZIP tile-compressed images
Output
FITSData with headers and typed pixel arrays
Loader
FITSLoader · @loaders.gl/scientific
Parser
@loaders.gl/scientific/fits
Detailed guide
Format, usage and output reference
Understand the source data, load it through the public entry point, and check the supported subset before integrating it.
What is FITS?
FITS is the standard file format for astronomy and solar images. A file holds one or more header and data units (HDUs). Each HDU has a text header of 80 character cards and an optional data block. Space missions such as NOAA GOES SUVI publish their images as FITS.
Load an image
FITSLoader from @loaders.gl/scientific/fits is metadata only. The async load and parse functions load the parser on demand through preload(). To attach the parser yourself, import FITSLoaderWithParser from @loaders.gl/scientific/fits/parser, or FITSLoader from @loaders.gl/scientific/fits/bundled.
import {load} from '@loaders.gl/core';
import {FITSLoader, getFITSWCS} from '@loaders.gl/scientific/fits';
const fits = await load('image.fits', FITSLoader);
const hdu = fits.hdus.find(candidate => candidate.image);
console.log(hdu.image.shape, hdu.image.data.constructor.name);
console.log(hdu.header.get('DATE-OBS'));
console.log(getFITSWCS(hdu.header));
Output
FITSData holds hdus. Each HDU has index, type, header and image. The image field is null when the HDU holds no image or when you did not select it.
| Field | Meaning |
|---|---|
image.data | Typed pixels, in FITS order |
image.shape | [NAXISn, ..., NAXIS1]; the slowest axis comes first |
image.bitpix | BITPIX of the stored data |
image.compressed | True for a tile-compressed image |
header.cards | All cards in file order, with comments |
header.get(key) | Typed value of a keyword |
Pixel array types
The type of image.data comes from BITPIX, BSCALE and BZERO. Absent BSCALE is 1. Absent BZERO is 0.
| BITPIX | BSCALE and BZERO | image.data |
|---|---|---|
| 8 | absent, or BSCALE 1 and BZERO 0 | Uint8Array |
| 16 | absent, or BSCALE 1 and BZERO 0 | Int16Array |
| 16 | BSCALE 1 and BZERO 32768 | Uint16Array |
| 32 | absent, or BSCALE 1 and BZERO 0 | Int32Array |
| 64 | absent, or BSCALE 1 and BZERO 0 | BigInt64Array |
| -32 | absent, or BSCALE 1 and BZERO 0 | Float32Array |
| -64 | absent, or BSCALE 1 and BZERO 0 | Float64Array |
| 8, 16 or -32 | other values | Float32Array with value x BSCALE + BZERO |
| 32, 64 or -64 | other values | Float64Array with value x BSCALE + BZERO |
| -32 or -64, tile-compressed and quantized | ZSCALE and ZZERO | Float32Array (-32) or Float64Array (-64) |
BLANK applies to integer images only:
- A scaled integer image (
Float32ArrayorFloat64Arrayoutput) has NaN for each BLANK pixel. - An unscaled integer image (
Uint8Array,Int16Array,Uint16Array,Int32ArrayorBigInt64Array) keeps the BLANK value. The loader does not change it to NaN. Readheader.get('BLANK')to find these pixels. For aUint16Array, the BLANK pixels holdBLANK + 32768. - A float image ignores BLANK. NaN is the null value of float pixels.
Pixels keep the FITS order. The first row of data is FITS row 1, which is the bottom of the image. Flip the rows if you draw the image top-down.
Integers above 2^53 in headers lose precision. FITS complex values return as text.
A card without the value indicator = in columns 9 and 10 is a commentary card: COMMENT, HISTORY, a blank keyword, HIERARCH, or a CONTINUE that does not continue a long string. It stays in header.cards with isCommentary: true and its text in value. header.get and header.has skip it.
World coordinates
getFITSWCS(header) returns the linear WCS of a 2D image: ctype, cunit, crpix, crval, cdelt and pc. It returns null when NAXIS is below 2 or CTYPE1 is absent. The loader does not read the orientation of the image from anywhere else. Use the WCS for orientation.
The function reads the matrix in this order: CDi_j, then PCi_j with CDELTi, then CROTA2 or CROTA, then identity.
A missing CDi_j key is 0. A missing or non-numeric CDELTi is 1.
CROTA2 (or CROTA when CROTA2 is absent) uses the legacy definition with the CDELT ratio terms (Calabretta and Greisen 2002, section 6.1). The rotation angle is in degrees.
| Matrix term | Value |
|---|---|
pc[0][0] | cos(CROTA2) |
pc[0][1] | -sin(CROTA2) x CDELT2 / CDELT1 |
pc[1][0] | sin(CROTA2) x CDELT1 / CDELT2 |
pc[1][1] | cos(CROTA2) |
When CDELT1 or CDELT2 is 0, the ratio terms use 1.
Options
| Option | Default | Meaning |
|---|---|---|
fits.hdus | all HDUs | HDU indexes to decode. The loader returns the headers of all HDUs. |
fits.maxPixels | 2 ** 28 | Largest pixel count of one image. Larger images throw before the loader allocates memory. A value that is not a finite number of 0 or more throws an error. |
Tile-compressed images
A BINTABLE HDU with ZIMAGE = T becomes an image HDU. The loader maps ZBITPIX to BITPIX and ZNAXISn to NAXISn, and removes the table and compression keywords from the header.
GZIP_2reverses the byte shuffle of each tile in theCOMPRESSED_DATAcolumn.- When a row of
COMPRESSED_DATAis empty, the loader reads theGZIP_COMPRESSED_DATAcolumn of that row. That column holds the lossless pixel values, gzip-compressed without the byte shuffle, also whenZCMPTYPEisGZIP_2. - An integer image with a
ZBLANKcolumn maps the null value of each tile to one imageBLANK. When the tiles use different null values, the loader picks aBLANKthat no valid sample uses.
Memory
The loader checks every tile length before it allocates the image. The table shows the peak memory of the decode in bytes per image pixel. Add the bytes of the input file and the decoded bytes of one tile (two copies for GZIP_2).
| Image | Peak bytes per pixel |
|---|---|
| Lossless, unscaled (BITPIX 8, 16, 32, 64, -32, -64; also BITPIX 16 with BZERO 32768) | abs(BITPIX) / 8: the loader decodes the tiles into one buffer and returns a view of it |
| Quantized float (BITPIX -32 or -64) | 4 (Float32Array) or 8 (Float64Array): the loader writes each tile straight into the output |
| Lossless integer with BSCALE or BZERO (except BZERO 32768 on BITPIX 16) | abs(BITPIX) / 8 for the decoded tiles, plus 4 (Float32Array, BITPIX 8 and 16) or 8 (Float64Array, BITPIX 32 and 64). For example, 6 bytes for BITPIX 16 and 12 bytes for BITPIX 32 |
For example, a 1280 x 1280 SUVI image (quantized float32, one tile per row) needs about 6.6 MB for the output, plus the input file and less than 15 kB for one tile.
Supported features and limits
| Supported | Not supported |
|---|---|
| Primary and image HDUs; BITPIX 8, 16, 32, 64, -32, -64 | Random groups |
| BZERO and BSCALE | HIERARCH keywords (kept in header.cards, but get and has skip them) |
Tile compression ZCMPTYPE GZIP_1, GZIP_2 and NOCOMPRESS | RICE_1, PLIO_1 and HCOMPRESS_1 |
Quantization none (NONE), NO_DITHER and SUBTRACTIVE_DITHER_1 (ZDITHER0 required) | SUBTRACTIVE_DITHER_2 |
| Headers of ASCII TABLE and BINTABLE HDUs | Data columns of ASCII TABLE and BINTABLE; NULL_PIXEL_MASK; UNCOMPRESSED_DATA column |
The loader throws a clear error for an unsupported feature. It does not write FITS. Gzip uses the native DecompressionStream and adds no dependency. FITSLoader is async only.
Choose NRRD or NumPy NPY for plain arrays without FITS headers.