[AstroPy] Fwd: Help with encoding error

Perry Greenfield stsci.perry at gmail.com
Wed Oct 2 10:34:11 EDT 2013


On Oct 2, 2013, at 10:19 AM, Leticia Rodriguez wrote:

> Hi,
> 
> I want to use the "ñ" character in a fit header. The verify in astropy is giving me an error.
> 
> WARNING: VerifyWarning:         Card 'OBSERVER' is not FITS standard (invalid value string: 'Maria Rosa Mu�oz ').  Fixed 'OBSERVER' card to meet the FITS standard. [astropy.io.fits.verify]
> ERROR: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 1946: ordinal not in range(128) [astropy.io.fits.header]
> Traceback (most recent call last):
>   File "./fixfitheader.py", line 30, in <module>
>     hdulist.writeto(sys.argv[2]+'/'+filename, output_verify='fix')
>   File "/usr/local/lib/python2.6/dist-packages/astropy/io/fits/hdu/hdulist.py", line 675, in writeto
>     hdu._writeto(hdulist.__file)
>   File "/usr/local/lib/python2.6/dist-packages/astropy/io/fits/hdu/base.py", line 497, in _writeto
>     self._writeheader(fileobj)
>   File "/usr/local/lib/python2.6/dist-packages/astropy/io/fits/hdu/base.py", line 428, in _writeheader
>     self._header.tofile(fileobj)
>   File "/usr/local/lib/python2.6/dist-packages/astropy/io/fits/header.py", line 625, in tofile
>     fileobj.write(blocks.encode('ascii'))
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 1946: ordinal not in range(128)
> 
> Is there a solution for this issue?
> 
Yes, don't use FITS. :-) But seriously, here's what the FITS standard says about headers:

3.2. Individual FITS Structures

The primary HDU and every extension HDU shall consist of one or more 2880-byte header blocks immediately followed by an optional sequence of associated 2880-byte data blocks. The header blocks shall contain only the restricted set of ASCII text characters, decimal 32 through 126 (hexadecimal 20 through 7E). The ASCII control characters with decimal values less than 32 (including the null, tab, carriage return, and line feed characters), and the delete character (decimal 127 or hexadecimal 7F) must not appear anywhere within a header block

So basically, the character you want is illegal in a FITS header. So no, there isn't a simple solution.

Perry




More information about the AstroPy mailing list