Skip to content

Unable to load fits.bz2 file #3881

Closed
Closed

Description

@eddedmondson

Working with for example http://dr12.sdss3.org/sas/dr12/boss/photoObj/frames/301/5314/1/frame-u-005314-1-0136.fits.bz2

>>> from astropy.io import fits
>>> hdu = fits.open('frame-u-005314-1-0136.fits.bz2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 129, in fitsopen
    return HDUList.fromfile(name, mode, memmap, save_backup, cache, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 271, in fromfile
    save_backup=save_backup, cache=cache, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 829, in _readfrom
    hdu = _BaseHDU.readfrom(ffo, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py", line 378, in readfrom
    **kwargs)
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py", line 438, in _readfrom_internal
    header = Header.fromfile(data, endcard=not ignore_missing_end)
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/header.py", line 460, in fromfile
    padding)[1]
  File "/usr/local/lib/python2.7/site-packages/astropy/io/fits/header.py", line 529, in _from_blocks
    raise IOError('Header missing END card.')
IOError: Header missing END card.

After bunzip2

>>> hdu = fits.open('frame-u-005314-1-0136.fits')

works fine.

OS X 10.10.3, Python 2.7.9, Astropy 1.0.3, Numpy 1.9.2.

Activity

  1. embray commented on Jun 24, 2015

    @embray
    Member

    Hi @eddedmondson,

    The version of Astropy you're using does not support transparent reading from bz2 files. This was only added very recently in the development version (#3789) and will be available in Astropy v1.1.0.

  2. embray commented on Jun 24, 2015

    @embray
    Member

    By the way, as a current workaround you can still Python's bz2 library and pass an open bz2 file in to fits.open(), which will generally work with any stream-like object:

    In [1]: import astropy
    
    In [2]: astropy.__version__
    Out[2]: '1.0.3'
    
    In [3]: from astropy.io import fits
    
    In [4]: import bz2
    
    In [5]: f = bz2.open('astropy/io/fits/tests/data/tb.fits.bz2')
    
    In [6]: h = fits.open(f)
    
    In [7]: h.info()
    Filename: <class 'bz2.BZ2File'>
    No.    Name         Type      Cards   Dimensions   Format
    0    PRIMARY     PrimaryHDU      11   ()              
    1                BinTableHDU     24   2R x 4C      [1J, 3A, 1E, 1L]   
    
    In [8]: h[1].data
    Out[8]: 
    FITS_rec([(1, 'abc', 3.7000000715255736, False),
           (2, 'xy', 6.6999997138977054, True)], 
          dtype=[('c1', '>i4'), ('c2', 'S3'), ('c3', '>f4'), ('c4', 'i1')])

    The only difference in the new version is that it can detect bz2 files automatically from the filename and/or contents and do this automatically.

  3. PaulKuin commented on Aug 21, 2015

    @PaulKuin

    I just had a similar problem with an ESO file that had been compressed (.Z) Error reported was "Header missing END card."

  4. embray commented on Aug 21, 2015

    @embray
    Member

    @PaulKuin Regarding "Header missing END card": #3941

  5. PaulKuin commented on Aug 21, 2015

    @PaulKuin

    Hi Erik,

    Ah, but the message was in error! There was an 'end' card (I ran also
    fverify on it and that gave no errors). [I assume you know the ftools]. It
    is an error message that pops up when the file is compressed. Imho I think
    fits.open should read the first few characters to see if this is a
    compressed file. Actually, I'm kind of surprised, since the fits file
    should start with "SIMPLE = T", but apparently that check gets passed (or
    not done perhaps?). Anyway, sorry to add to your burden, but something can
    be improved there with the error trapping.

    Well, over there it must be about time to leave for the weekend, so let me
    wish you a good one!

    Paul

    On Fri, Aug 21, 2015 at 7:33 PM, Erik Bray [email protected] wrote:

    @PaulKuin https://github.com/PaulKuin Regarding "Header missing END
    card": #3941 #3941

    —
    Reply to this email directly or view it on GitHub
    #3881 (comment).

  6. embray commented on Aug 21, 2015

    @embray
    Member

    Right, that's what was discussed in #3941.

  7. embray commented on Aug 21, 2015

    @embray
    Member

    And thanks, you have a good one too!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions