[AstroPy] Fixing broken FITS headers

Derek Homeier derek at astro.physik.uni-goettingen.de
Wed Aug 17 06:50:50 EDT 2016


Hi Rick,
> 
> 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….
> 
there are some comments regarding this in io/fits/header.py incl. the suggestion to use `decode_latin`
instead of `decode_ascii` for the unicode conversion; however nothing in that direction seems to have
been implemented yet.
But there is a similar issue on file
https://github.com/astropy/astropy/issues/5093
which indicates that for the time being you might be able to work around the error by using the Python2.7
version, skipping the whole string/unicode conversion.

Greetings from Heidelberg!

				Derek





More information about the AstroPy mailing list