question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

astropy.io.fits; ValueError: The header keyword 'description' with its value is too long

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
keflavichcommented, Aug 5, 2019

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.

1reaction
bsipoczcommented, Aug 5, 2019

This has bitten me in the past, too, but I don’t think the way forward is to patch astroquery. It returns a perfectly valid Table, 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 be fits 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found