[AstroPy] Fixing broken FITS headers

Frederic V. Hessman hessman at astro.physik.uni-goettingen.de
Wed Aug 17 06:30:05 EDT 2016


I'm stuck with some FITS files with headers where non-ascii characters have been used (German umlauts).  If I try to read them using astropy.io.fits, I of course get an input error, since the ascii codec balks :

WARNING: VerifyWarning: Error validating header for HDU #0 (note: Astropy uses zero-based indexing).
    'ascii' codec can't decode byte 0xf6 in position 896: ordinal not in range(128)
There may be extra bytes after the last HDU or the file is corrupted. [astropy.io.fits.hdu.hdulist]
Traceback (most recent call last):
  File "/Users/hessman/Library/python/fitsfix.py", line 23, in <module>
    hdus = fits.open(thing)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/io/fits/hdu/hdulist.py", line 138, in fitsopen
    return HDUList.fromfile(name, mode, memmap, save_backup, cache, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/io/fits/hdu/hdulist.py", line 280, in fromfile
    save_backup=save_backup, cache=cache, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/io/fits/hdu/hdulist.py", line 870, in _readfrom
    raise IOError('Empty or corrupt FITS file')
OSError: Empty or corrupt FITS file

Is there some easy way of forcing acceptance (so that I can repair the header) or replacing the codec?  Don’t see anything obvious in the API….

The write() method has an output_verify option (e.g. ‘fix+warn’) : would be very nice to have an input_verify option as well.

Rick




More information about the AstroPy mailing list