astropy.io.fits; ValueError: The header keyword 'description' with its value is too long
See original GitHub issueI am using astropy with anaconda on a Mac with Python 3.6.
astroquery.version: 0.3.9 astropy.version: 3.2.1
I have used astroquery to download a table from Vizier but when I try to write out the table I get the error:
File "/Users/rgm/anaconda2/envs/py36/lib/python3.6/site-packages/astropy/io/fits/card.py", line 990, in _format_image
'too long'.format(self.keyword))
ValueError: The header keyword 'description' with its value is too long
This looks like a problem with the description of one of the columns. I have investigated the description lengths and trimmed the longest one. This did not help.
I then tried to replac the descriptions with an empty string and this did not help either.
result.columns[icol].description = ‘’"
If I knew which column was causing the problem, I could remove it.
See example code below
# python 3 future proofing;see Python 2 to 3 cheatsheet
from __future__ import print_function, division
from builtins import input
try:
input = raw_input
except NameError:
pass
import numpy as np
from astropy.table import Table
import astropy.units as u
import astropy.coordinates as coord
import astroquery
print('astroquery.__version__:', astroquery.__version__)
import astropy
print('astropy.__version__:', astropy.__version__)
from astroquery.vizier import Vizier
from astropy.config import get_config
from astropy.config import get_config_dir
from astropy.utils.data import conf
print(get_config('conf'))
print('get_config_dir(): ', get_config_dir())
config_vizier = get_config('astroquery.vizier')
for key,value in config_vizier.items():
print(key, value)
Vizier.TIMEOUT = 300
Vizier.ROW_LIMIT = -1
catalog = 'II/317/cfhtls_w'
ra = 35.665
dec = -4.795
radec = coord.SkyCoord(ra=ra, dec=dec,
unit=(u.deg, u.deg),
frame='icrs')
print(radec)
vizier = Vizier(columns=['**'])
vizier.ROW_LIMIT = -1
width = 0.1
height = 0.1
result = vizier.query_region(radec,
width=width*u.deg, height=height*u.deg,
catalog=catalog)
print('Number of rows returned', len(result))
# result is a TableList; since one catalogue use [0]
result = result[0]
print('Number of rows returned', len(result))
print()
result.info()
trimAll = True
print()
for icol, column in enumerate(result.itercols()):
print(icol,':', column.description,
';', len(column.description))
if len(column.description) >= 40:
print()
print(icol)
print(result.columns[icol].unit)
print(result.columns[icol].description)
print()
result.columns[icol].description = \
result.columns[icol].description[0:38]
print(icol,':', column.description,
';', len(column.description))
result.columns[icol].description = ''
if trimAll:
result.columns[icol].description = ''
result.info()
result.write('tmp.fits')
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Save FITS table: The keyword description with its value is too ...
The problem is that table.meta['description'] is longer than allowed for the header of the fits file you're trying to save.
Read more >Headers — Astropy v5.2
This class exposes both a dict-like interface and a list-like interface to FITS headers. The header may be indexed by keyword and, like...
Read more >FITS Headers — Astropy v5.2
A user can use any header and any data to construct a new HDU. astropy will strip any keywords that describe the data...
Read more >Source code for astropy.io.fits.column
ASCIITNULL = 0 # The default placeholder to use for NULL values in ASCII ... with keywords in the FITS header and describe...
Read more >Source code for astropy.io.fits.header
When the header contains cards with duplicate keywords, only the value of the ... to a full card length as long as it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, this seems to be simply a writer issue. Not all tables can be written by all writers; for example, most votables can’t be written as ascii.ipac files because of forbidden characters in the column names. It would be nice if we had some “automatic fixing” options (e.g., allowing description truncation in this case), but that’s low on the wishlist. I’m in favor of improving the error message and/or documentation around the error message, but leaving the code untouched.
This has bitten me in the past, too, but I don’t think the way forward is to patch
astroquery
. It returns a perfectly validTable
, and after that it’s the users decision of what they do with it, what format they write it out, etc. Thus we shouldn’t make assumptions it would befits
rather than some other format that would happily round trip with the description in meta. @keflavich - what is your take on this?So I think it’s indeed the first writer here that should return a more useful error message, pointing out the problem less cryptically.