# Licensed under a 3-clause BSD style license - see PYFITS.rst import ctypes import gc import itertools import math import re import time import warnings from contextlib import suppress import numpy as np from .base import DELAYED, ExtensionHDU, BITPIX2DTYPE, DTYPE2BITPIX from .image import ImageHDU from .table import BinTableHDU from astropy.io.fits import conf from astropy.io.fits.card import Card from astropy.io.fits.column import Column, ColDefs, TDEF_RE from astropy.io.fits.column import KEYWORD_NAMES as TABLE_KEYWORD_NAMES from astropy.io.fits.fitsrec import FITS_rec from astropy.io.fits.header import Header from astropy.io.fits.util import (_is_pseudo_integer, _pseudo_zero, _is_int, _get_array_mmap) from astropy.utils import lazyproperty from astropy.utils.exceptions import AstropyUserWarning try: from astropy.io.fits import compression COMPRESSION_SUPPORTED = COMPRESSION_ENABLED = True except ImportError: COMPRESSION_SUPPORTED = COMPRESSION_ENABLED = False # Quantization dithering method constants; these are right out of fitsio.h NO_DITHER = -1 SUBTRACTIVE_DITHER_1 = 1 SUBTRACTIVE_DITHER_2 = 2 QUANTIZE_METHOD_NAMES = { NO_DITHER: 'NO_DITHER', SUBTRACTIVE_DITHER_1: 'SUBTRACTIVE_DITHER_1', SUBTRACTIVE_DITHER_2: 'SUBTRACTIVE_DITHER_2' } DITHER_SEED_CLOCK = 0 DITHER_SEED_CHECKSUM = -1 COMPRESSION_TYPES = ('RICE_1', 'GZIP_1', 'GZIP_2', 'PLIO_1', 'HCOMPRESS_1') # Default compression parameter values DEFAULT_COMPRESSION_TYPE = 'RICE_1' DEFAULT_QUANTIZE_LEVEL = 16. DEFAULT_QUANTIZE_METHOD = NO_DITHER DEFAULT_DITHER_SEED = DITHER_SEED_CLOCK DEFAULT_HCOMP_SCALE = 0 DEFAULT_HCOMP_SMOOTH = 0 DEFAULT_BLOCK_SIZE = 32 DEFAULT_BYTE_PIX = 4 CMTYPE_ALIASES = {'RICE_ONE': 'RICE_1'} COMPRESSION_KEYWORDS = {'ZIMAGE', 'ZCMPTYPE', 'ZBITPIX', 'ZNAXIS', 'ZMASKCMP', 'ZSIMPLE', 'ZTENSION', 'ZEXTEND'} class CompImageHeader(Header): """ Header object for compressed image HDUs designed to keep the compression header and the underlying image header properly synchronized. This essentially wraps the image header, so that all values are read from and written to the image header. However, updates to the image header will also update the table header where appropriate. Note that if no image header is passed in, the code will instantiate a regular `~astropy.io.fits.Header`. """ # TODO: The difficulty of implementing this screams a need to rewrite this # module _keyword_remaps = { 'SIMPLE': 'ZSIMPLE', 'XTENSION': 'ZTENSION', 'BITPIX': 'ZBITPIX', 'NAXIS': 'ZNAXIS', 'EXTEND': 'ZEXTEND', 'BLOCKED': 'ZBLOCKED', 'PCOUNT': 'ZPCOUNT', 'GCOUNT': 'ZGCOUNT', 'CHECKSUM': 'ZHECKSUM', 'DATASUM': 'ZDATASUM' } _zdef_re = re.compile(r'(?P