Skip to content

fits.Z cannot be opened using automatic decompression #10714

Description

@astrom-tom

Description

When trying to open a fits.Z (ESO download format) the file does can be read (link to file https://drive.google.com/file/d/1PoQhABH90aQwwgUSmzRqrj-yPvGWLvXW/view?usp=sharing )

Expected behavior

I expect the header to be read normally. Important to note that it works with the fitsio library.

Actual behavior

---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in _readfrom_internal(cls, data, header, checksum, ignore_missing_end, **kwargs)
    405                     # that are needed to build the HDU object.
--> 406                     header_str, header = _BasicHeader.fromfile(data)
    407                 except Exception:

~/.local/lib/python3.8/site-packages/astropy/io/fits/header.py in fromfile(cls, fileobj)
   2076         try:
-> 2077             header_str, cards = parse_header(fileobj)
   2078             _check_padding(header_str, BLOCK_SIZE, False)

astropy/io/fits/_utils.pyx in astropy.io.fits._utils.parse_header()

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9d in position 1: ordinal not in range(128)

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-2-0fb814c35786> in <module>
----> 1 fits.getheader('VISIR.2017-01-05T09:04:11.258.fits.Z')

~/.local/lib/python3.8/site-packages/astropy/io/fits/convenience.py in getheader(filename, *args, **kwargs)
    103 
    104     mode, closed = _get_file_mode(filename)
--> 105     hdulist, extidx = _getext(filename, mode, *args, **kwargs)
    106     try:
    107         hdu = hdulist[extidx]

~/.local/lib/python3.8/site-packages/astropy/io/fits/convenience.py in _getext(filename, mode, ext, extname, extver, *args, **kwargs)
   1047         raise TypeError('extver alone cannot specify an extension.')
   1048 
-> 1049     hdulist = fitsopen(filename, mode=mode, **kwargs)
   1050 
   1051     return hdulist, ext

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in fitsopen(name, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
    162         raise ValueError(f'Empty filename: {name!r}')
    163 
--> 164     return HDUList.fromfile(name, mode, memmap, save_backup, cache,
    165                             lazy_load_hdus, **kwargs)
    166 

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in fromfile(cls, fileobj, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
    401         """
    402 
--> 403         return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap,
    404                              save_backup=save_backup, cache=cache,
    405                              lazy_load_hdus=lazy_load_hdus, **kwargs)

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in _readfrom(cls, fileobj, data, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
   1077 
   1078         # Make sure at least the PRIMARY HDU can be read
-> 1079         read_one = hdulist._read_next_hdu()
   1080 
   1081         # If we're trying to read only and no header units were found,

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in _read_next_hdu(self)
   1152                                 fileobj.seek(offset, os.SEEK_SET)
   1153 
-> 1154                         hdu = _BaseHDU.readfrom(fileobj, **kwargs)
   1155                     except EOFError:
   1156                         self._read_all = True

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in readfrom(cls, fileobj, checksum, ignore_missing_end, **kwargs)
    323             fileobj = _File(fileobj)
    324 
--> 325         hdu = cls._readfrom_internal(fileobj, checksum=checksum,
    326                                      ignore_missing_end=ignore_missing_end,
    327                                      **kwargs)

~/.local/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in _readfrom_internal(cls, data, header, checksum, ignore_missing_end, **kwargs)
    411                     # in the wild.
    412                     data.seek(header_offset)
--> 413                     header = Header.fromfile(data,
    414                                              endcard=not ignore_missing_end)
    415             hdu_fileobj = data

~/.local/lib/python3.8/site-packages/astropy/io/fits/header.py in fromfile(cls, fileobj, sep, endcard, padding)
    511                         break
    512 
--> 513             return cls._from_blocks(block_iter, is_binary, sep, endcard,
    514                                     padding)[1]
    515         finally:

~/.local/lib/python3.8/site-packages/astropy/io/fits/header.py in _from_blocks(cls, block_iter, is_binary, sep, endcard, padding)
    594             # TODO: Pass this error to validation framework as an ERROR,
    595             # rather than raising an exception
--> 596             raise OSError('Header missing END card.')
    597 
    598         header_str = ''.join(read_blocks)

OSError: Header missing END card.

Steps to Reproduce

from astropy.io import fits
fits.getheader('VISIR.2017-01-05T09:04:11.258.fits.Z')

System Details

import platform; print(platform.platform())
-->Linux-5.4.60-1-lts-x86_64-with-glibc2.2.5
import sys; print("Python", sys.version) 

-->Python 3.8.5 (default, Jul 27 2020, 08:42:51) 
[GCC 10.1.0]

import numpy; print("Numpy", numpy.__version__)
-->Numpy 1.17.4

import astropy; print("astropy", astropy.__version__)
-->astropy 4.0.1.post1

import scipy; print("Scipy", scipy.__version__)
Scipy 1.3.3

import matplotlib; print("Matplotlib", matplotlib.__version__)
Matplotlib 3.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions