'Update the table header (`_header`) to the compressed
image format and to match the input data (if any).  Create
the image header (`_image_header`) from the input image
header (if any) and ensure it matches the input
data. Create the initially-empty table data array to hold
the compressed data.
This method is mainly called internally, but a user may wish to
call this method after assigning new data to the `CompImageHDU`
object that is of a different type.
Parameters
image_header : Header instance
header to be associated with the image
name : str, optional
the ``EXTNAME`` value; if this value is `None`, then the name from
the input image header will be used; if there is no name in the
input image header then the default name \'COMPRESSED_IMAGE\' is used
compression_type : str, optional
compression algorithm \'RICE_1\', \'PLIO_1\', \'GZIP_1\', \'HCOMPRESS_1\';
if this value is `None`, use value already in the header; if no
value already in the header, use \'RICE_1\'
tile_size : sequence of int, optional
compression tile sizes as a list; if this value is `None`, use
value already in the header; if no value already in the header,
treat each row of image as a tile
hcomp_scale : float, optional
HCOMPRESS scale parameter; if this value is `None`, use the value
already in the header; if no value already in the header, use 1
hcomp_smooth : float, optional
HCOMPRESS smooth parameter; if this value is `None`, use the value
already in the header; if no value already in the header, use 0
quantize_level : float, optional
floating point quantization level; if this value is `None`, use the
value already in the header; if no value already in header, use 16
quantize_method : int, optional
floating point quantization dithering method; can be either
NO_DITHER (-1), SUBTRACTIVE_DITHER_1 (1; default), or
SUBTRACTIVE_DITHER_2 (2)
dither_seed : int, optional
random seed to use for dithering; can be either an integer in the
range 1 to 1000 (inclusive), DITHER_SEED_CLOCK (0; default), or
DITHER_SEED_CHECKSUM (-1)'

def _update_header_data(self, image_header, name=None, compression_type=None, tile_size=None, hcomp_scale=None, hcomp_smooth=None, quantize_level=None, quantize_method=None, dither_seed=None):

    image_hdu = ImageHDU(data=self.data, header=self._header)
    self._image_header = CompImageHeader(self._header, image_hdu.header)
    self._axes = image_hdu._axes
    del image_hdu
    if self._has_data:
        huge_hdu = (self.data.nbytes > (2 ** 32))
        if (huge_hdu and (not CFITSIO_SUPPORTS_Q_FORMAT)):
            raise IOError('Astropy    cannot    compress    images    greater    than    4    GB    in    size    ({}    is    {}    bytes)    without    CFITSIO    >=    3.35'.format((self.name, self.ver), self.data.nbytes))
    else:
        huge_hdu = False
    if ((not name) and ('EXTNAME' not in self._header)):
        name = 'COMPRESSED_IMAGE'
    if name:
        self._header.set('EXTNAME', name, 'name    of    this    binary    table    extension', after='TFIELDS')
        self.name = name
    else:
        self.name = self._header['EXTNAME']
    if compression_type:
        if (compression_type not in ['RICE_1', 'GZIP_1', 'PLIO_1', 'HCOMPRESS_1']):
            warnings.warn('Unknown    compression    type    provided.        Default    ({})    compression    used.'.format(DEFAULT_COMPRESSION_TYPE), AstropyUserWarning)
            compression_type = DEFAULT_COMPRESSION_TYPE
        self._header.set('ZCMPTYPE', compression_type, 'compression    algorithm', after='TFIELDS')
    else:
        compression_type = self._header.get('ZCMPTYPE', DEFAULT_COMPRESSION_TYPE)
        compression_type = CMTYPE_ALIASES.get(compression_type, compression_type)
    if image_header:
        bzero = image_header.get('BZERO', 0.0)
        bscale = image_header.get('BSCALE', 1.0)
        after_keyword = 'EXTNAME'
        if (bscale != 1.0):
            self._header.set('BSCALE', bscale, after=after_keyword)
            after_keyword = 'BSCALE'
        if (bzero != 0.0):
            self._header.set('BZERO', bzero, after=after_keyword)
        bitpix_comment = image_header.comments['BITPIX']
        naxis_comment = image_header.comments['NAXIS']
    else:
        bitpix_comment = 'data    type    of    original    image'
        naxis_comment = 'dimension    of    original    image'
    self._header.set('TTYPE1', 'COMPRESSED_DATA', 'label    for    field    1', after='TFIELDS')
    if (compression_type == 'PLIO_1'):
        tform1 = ('1QI' if huge_hdu else '1PI')
    else:
        tform1 = ('1QB' if huge_hdu else '1PB')
    self._header.set('TFORM1', tform1, 'data    format    of    field:    variable    length    array', after='TTYPE1')
    col1 = Column(name=self._header['TTYPE1'], format=tform1)
    zbitpix = self._image_header['BITPIX']
    if ((zbitpix < 0) and (quantize_level != 0.0)):
        ncols = 4
        if CFITSIO_SUPPORTS_GZIPDATA:
            ttype2 = 'GZIP_COMPRESSED_DATA'
            tform2 = ('1QB' if huge_hdu else '1PB')
        else:
            ttype2 = 'UNCOMPRESSED_DATA'
            if (zbitpix == 8):
                tform2 = ('1QB' if huge_hdu else '1PB')
            elif (zbitpix == 16):
                tform2 = ('1QI' if huge_hdu else '1PI')
            elif (zbitpix == 32):
                tform2 = ('1QJ' if huge_hdu else '1PJ')
            elif (zbitpix == (-32)):
                tform2 = ('1QE' if huge_hdu else '1PE')
            else:
                tform2 = ('1QD' if huge_hdu else '1PD')
        self._header.set('TTYPE2', ttype2, 'label    for    field    2', after='TFORM1')
        self._header.set('TFORM2', tform2, 'data    format    of    field:    variable    length    array', after='TTYPE2')
        col2 = Column(name=ttype2, format=tform2)
        self._header.set('TTYPE3', 'ZSCALE', 'label    for    field    3', after='TFORM2')
        self._header.set('TFORM3', '1D', 'data    format    of    field:    8-byte    DOUBLE', after='TTYPE3')
        col3 = Column(name=self._header['TTYPE3'], format=self._header['TFORM3'])
        self._header.set('TTYPE4', 'ZZERO', 'label    for    field    4', after='TFORM3')
        self._header.set('TFORM4', '1D', 'data    format    of    field:    8-byte    DOUBLE', after='TTYPE4')
        after = 'TFORM4'
        col4 = Column(name=self._header['TTYPE4'], format=self._header['TFORM4'])
        cols = ColDefs([col1, col2, col3, col4])
    else:
        ncols = 1
        after = 'TFORM1'
        to_remove = ['TTYPE2', 'TFORM2', 'TTYPE3', 'TFORM3', 'TTYPE4', 'TFORM4']
        for k in to_remove:
            try:
                del self._header[k]
            except KeyError:
                pass
        cols = ColDefs([col1])
    self._header.set('NAXIS1', cols.dtype.itemsize, 'width    of    table    in    bytes')
    self._header.set('TFIELDS', ncols, 'number    of    fields    in    each    row', after='GCOUNT')
    self._header.set('ZIMAGE', True, 'extension    contains    compressed    image', after=after)
    self._header.set('ZBITPIX', zbitpix, bitpix_comment, after='ZIMAGE')
    self._header.set('ZNAXIS', self._image_header['NAXIS'], naxis_comment, after='ZBITPIX')
    idx = 1
    while True:
        try:
            del self._header[('ZNAXIS' + str(idx))]
            del self._header[('ZTILE' + str(idx))]
            idx += 1
        except KeyError:
            break
    naxis = self._image_header['NAXIS']
    if (not tile_size):
        tile_size = []
    elif (len(tile_size) != naxis):
        warnings.warn('Provided    tile    size    not    appropriate    for    the    data.        Default    tile    size    will    be    used.', AstropyUserWarning)
        tile_size = []
    if (compression_type == 'HCOMPRESS_1'):
        if ((self._image_header['NAXIS1'] < 4) or (self._image_header['NAXIS2'] < 4)):
            raise ValueError('Hcompress    minimum    image    dimension    is    4    pixels')
        elif tile_size:
            if ((tile_size[0] < 4) or (tile_size[1] < 4)):
                raise ValueError('Hcompress    minimum    tile    dimension    is    4    pixels')
            major_dims = len([ts for ts in tile_size if (ts > 1)])
            if (major_dims > 2):
                raise ValueError('HCOMPRESS    can    only    support    2-dimensional    tile    sizes.All    but    two    of    the    tile_size    dimensions    must    be    set    to    1.')
        if (tile_size and ((tile_size[0] == 0) and (tile_size[1] == 0))):
            tile_size[0] = self._image_header['NAXIS1']
            tile_size[1] = self._image_header['NAXIS2']
            for i in range(2, naxis):
                tile_size[i] = 1
        elif (not tile_size):
            tile_size.append(self._image_header['NAXIS1'])
            if (self._image_header['NAXIS2'] <= 30):
                tile_size.append(self._image_header['NAXIS1'])
            else:
                naxis2 = self._image_header['NAXIS2']
                for dim in [16, 24, 20, 30, 28, 26, 22, 18, 14]:
                    if (((naxis2 % dim) == 0) or ((naxis2 % dim) > 3)):
                        tile_size.append(dim)
                        break
                else:
                    tile_size.append(17)
            for i in range(2, naxis):
                tile_size.append(1)
        remain = (self._image_header['NAXIS1'] % tile_size[0])
        if ((remain > 0) and (remain < 4)):
            tile_size[0] += 1
            remain = (self._image_header['NAXIS1'] % tile_size[0])
            if ((remain > 0) and (remain < 4)):
                raise ValueError('Last    tile    along    1st    dimension    has    less    than    4    pixels')
        remain = (self._image_header['NAXIS2'] % tile_size[1])
        if ((remain > 0) and (remain < 4)):
            tile_size[1] += 1
            remain = (self._image_header['NAXIS2'] % tile_size[1])
            if ((remain > 0) and (remain < 4)):
                raise ValueError('Last    tile    along    2nd    dimension    has    less    than    4    pixels')
    last_znaxis = 'ZNAXIS'
    if (self._image_header['NAXIS'] > 0):
        after1 = 'ZNAXIS1'
    else:
        after1 = 'ZNAXIS'
    nrows = 0
    for (idx, axis) in enumerate(self._axes):
        naxis = ('NAXIS' + str((idx + 1)))
        znaxis = ('ZNAXIS' + str((idx + 1)))
        ztile = ('ZTILE' + str((idx + 1)))
        if (tile_size and (len(tile_size) >= (idx + 1))):
            ts = tile_size[idx]
        else:
            if (ztile not in self._header):
                if (not idx):
                    ts = self._image_header['NAXIS1']
                else:
                    ts = 1
            else:
                ts = self._header[ztile]
            tile_size.append(ts)
        if (not nrows):
            nrows = (((axis - 1) // ts) + 1)
        else:
            nrows *= (((axis - 1) // ts) + 1)
        if (image_header and (naxis in image_header)):
            self._header.set(znaxis, axis, image_header.comments[naxis], after=last_znaxis)
        else:
            self._header.set(znaxis, axis, 'length    of    original    image    axis', after=last_znaxis)
        self._header.set(ztile, ts, 'size    of    tiles    to    be    compressed', after=after1)
        last_znaxis = znaxis
        after1 = ztile
    self._header.set('NAXIS2', nrows, 'number    of    rows    in    table')
    self.columns = cols
    idx = 1
    while True:
        zname = ('ZNAME' + str(idx))
        if (zname not in self._header):
            break
        zval = ('ZVAL' + str(idx))
        if (self._header[zname] == 'NOISEBIT'):
            if (quantize_level is None):
                quantize_level = self._header[zval]
        if (self._header[zname] == 'SCALE            '):
            if (hcomp_scale is None):
                hcomp_scale = self._header[zval]
        if (self._header[zname] == 'SMOOTH        '):
            if (hcomp_smooth is None):
                hcomp_smooth = self._header[zval]
        idx += 1
    if (quantize_level is None):
        quantize_level = DEFAULT_QUANTIZE_LEVEL
    if (hcomp_scale is None):
        hcomp_scale = DEFAULT_HCOMP_SCALE
    if (hcomp_smooth is None):
        hcomp_smooth = DEFAULT_HCOMP_SCALE
    idx = 1
    while True:
        zname = ('ZNAME' + str(idx))
        if (zname not in self._header):
            break
        zval = ('ZVAL' + str(idx))
        del self._header[zname]
        del self._header[zval]
        idx += 1
    after_keyword = 'ZCMPTYPE'
    idx = 1
    if (compression_type == 'RICE_1'):
        self._header.set('ZNAME1', 'BLOCKSIZE', 'compression    block    size', after=after_keyword)
        self._header.set('ZVAL1', DEFAULT_BLOCK_SIZE, 'pixels    per    block', after='ZNAME1')
        self._header.set('ZNAME2', 'BYTEPIX', 'bytes    per    pixel    (1,    2,    4,    or    8)', after='ZVAL1')
        if (self._header['ZBITPIX'] == 8):
            bytepix = 1
        elif (self._header['ZBITPIX'] == 16):
            bytepix = 2
        else:
            bytepix = DEFAULT_BYTE_PIX
        self._header.set('ZVAL2', bytepix, 'bytes    per    pixel    (1,    2,    4,    or    8)', after='ZNAME2')
        after_keyword = 'ZVAL2'
        idx = 3
    elif (compression_type == 'HCOMPRESS_1'):
        self._header.set('ZNAME1', 'SCALE', 'HCOMPRESS    scale    factor', after=after_keyword)
        self._header.set('ZVAL1', hcomp_scale, 'HCOMPRESS    scale    factor', after='ZNAME1')
        self._header.set('ZNAME2', 'SMOOTH', 'HCOMPRESS    smooth    option', after='ZVAL1')
        self._header.set('ZVAL2', hcomp_smooth, 'HCOMPRESS    smooth    option', after='ZNAME2')
        after_keyword = 'ZVAL2'
        idx = 3
    if (self._image_header['BITPIX'] < 0):
        self._header.set(('ZNAME' + str(idx)), 'NOISEBIT', 'floating    point    quantization    level', after=after_keyword)
        self._header.set(('ZVAL' + str(idx)), quantize_level, 'floating    point    quantization    level', after=('ZNAME' + str(idx)))
        if quantize_method:
            if (quantize_method not in [NO_DITHER, SUBTRACTIVE_DITHER_1, SUBTRACTIVE_DITHER_2]):
                name = QUANTIZE_METHOD_NAMES[DEFAULT_QUANTIZE_METHOD]
                warnings.warn('Unknown    quantization    method    provided.        Default    method    ({})    used.'.format(name))
                quantize_method = DEFAULT_QUANTIZE_METHOD
            if (quantize_method == NO_DITHER):
                zquantiz_comment = 'No    dithering    during    quantization'
            else:
                zquantiz_comment = 'Pixel    Quantization    Algorithm'
            self._header.set('ZQUANTIZ', QUANTIZE_METHOD_NAMES[quantize_method], zquantiz_comment, after=('ZVAL' + str(idx)))
        else:
            quantize_method = self._header.get('ZQUANTIZ', NO_DITHER)
            if isinstance(quantize_method, string_types):
                for (k, v) in iteritems(QUANTIZE_METHOD_NAMES):
                    if (v.upper() == quantize_method):
                        quantize_method = k
                        break
                else:
                    quantize_method = NO_DITHER
        if (quantize_method == NO_DITHER):
            if ('ZDITHER0' in self._header):
                del self._header['ZDITHER0']
        else:
            if dither_seed:
                dither_seed = self._generate_dither_seed(dither_seed)
            elif ('ZDITHER0' in self._header):
                dither_seed = self._header['ZDITHER0']
            else:
                dither_seed = self._generate_dither_seed(DEFAULT_DITHER_SEED)
            self._header.set('ZDITHER0', dither_seed, 'dithering    offset    when    quantizing    floats', after='ZQUANTIZ')
    if image_header:
        if ('SIMPLE' in image_header):
            self._header.set('ZSIMPLE', image_header['SIMPLE'], image_header.comments['SIMPLE'], before='ZBITPIX')
        if ('EXTEND' in image_header):
            self._header.set('ZEXTEND', image_header['EXTEND'], image_header.comments['EXTEND'])
        if ('BLOCKED' in image_header):
            self._header.set('ZBLOCKED', image_header['BLOCKED'], image_header.comments['BLOCKED'])
        if ('XTENSION' in image_header):
            self._header.set('ZTENSION', 'IMAGE', image_header.comments['XTENSION'], before='ZBITPIX')
        if ('PCOUNT' in image_header):
            self._header.set('ZPCOUNT', image_header['PCOUNT'], image_header.comments['PCOUNT'], after=last_znaxis)
        if ('GCOUNT' in image_header):
            self._header.set('ZGCOUNT', image_header['GCOUNT'], image_header.comments['GCOUNT'], after='ZPCOUNT')
        if ('CHECKSUM' in image_header):
            self._header.set('ZHECKSUM', image_header['CHECKSUM'], image_header.comments['CHECKSUM'])
        if ('DATASUM' in image_header):
            self._header.set('ZDATASUM', image_header['DATASUM'], image_header.comments['DATASUM'])
    else:
        if ('XTENSION' in self._image_header):
            self._header.set('ZTENSION', 'IMAGE', self._image_header.comments['XTENSION'], before='ZBITPIX')
        if ('PCOUNT' in self._image_header):
            self._header.set('ZPCOUNT', self._image_header['PCOUNT'], self._image_header.comments['PCOUNT'], after=last_znaxis)
        if ('GCOUNT' in self._image_header):
            self._header.set('ZGCOUNT', self._image_header['GCOUNT'], self._image_header.comments['GCOUNT'], after='ZPCOUNT')
    if ('ZHECKSUM' in self._header):
        required_blanks = image_header._countblanks()
        image_blanks = self._image_header._countblanks()
        table_blanks = self._header._countblanks()
        for _ in range((required_blanks - image_blanks)):
            self._image_header.append()
            table_blanks += 1
        for _ in range((required_blanks - table_blanks)):
            self._header.append()
