astrolabsoftware/spark-fits

Handling compressed data

Opened this issue · 0 comments

See the doc at:

https://archive.stsci.edu/fits/fits_standard/node39.html#SECTION00941220000000000000
=> 5.4.1.2 Conforming Extensions

A compressed image is stored in an extension such as:
https://fits.gsfc.nasa.gov/registry/tilecompression/tilecompression2.3.pdf

XTENSION = BINTABLE
TFIELDS = 1
TTYPE1 = 'COMPRESSED_DATA'
EXTNAME = 'COMPRESSED_IMAGE'
ZIMAGE = T

Zfields:

Zxxx fields give the original header fields pour the uncompressed image

datalen (in bits) : |BITPIX| x GCOUNT x (PCOUNT + NAXIS x NAXIS1 x ... x NAXISm )

More understanding...

Reading a FITS ZIMAGE:

  • if "ZIMAGE" in kv and "NAXIS" in kv and "PCOUNT" in kv then this is a compressed image HDU
  • the compressed image data is indeed given with the formula above (datalen)
  • each HDU contains
    • the HEADER with ZIMAGE, NAXIS, PCOUNT
    • the original metadata of the uncompressed image HDU prefixed by Z (Zxxx)
    • immediately a set of [(datalen/BLOCKSIZE) + 1] blocks of compressed data

The algo to uncompress data can be found in the "fits_uncompress_table" function in the "imcompress.c" source file of the cfitsio package.

(to be cont'd)

CA