Skip to content

4.0.5 / 4.2.1 : Long card images must have CONTINUE cards after the first card #11486

Closed

Description

@ahnitz

Description

An error is reported when saving an hdulist to a fits file that only occurs with version 4.2.1 and 4.0.5 of astropy. I've tracked the specific patch that is the determining factor to #11108.

See related issue here
https://git.ligo.org/lscsoft/ligo.skymap/-/issues/26

Expected behavior

There should be no output and a fits file should be generated.

Actual behavior

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    data.writeto('test.fits')
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/utils/decorators.py", line 535, in wrapper
    return function(*args, **kwargs)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py", line 919, in writeto
    self.verify(option=output_verify)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/verify.py", line 73, in verify
    errs = self._verify(opt)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py", line 1245, in _verify
    result = hdu._verify(option)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/hdu/table.py", line 535, in _verify
    errs = super()._verify(option=option)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py", line 1587, in _verify
    errs = super()._verify(option=option)
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py", line 1074, in _verify
    errs.append(card._verify(option))
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/card.py", line 1118, in _verify
    keyword, valuecomment = self._split()
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/card.py", line 815, in _split
    for card in self._itersubcards():
  File "/home/ahnitz/projects/env3/lib/python3.8/site-packages/astropy/io/fits/card.py", line 1170, in _itersubcards
    raise VerifyError(
astropy.io.fits.verify.VerifyError: Long card images must have CONTINUE cards after the first card.

Steps to Reproduce

To reproduce you'll need the specific data that was trying to be written. I've pickled the hdulist to make this possible (file attached and put into save.zip). With that file, one should be able to reproduce with the following.

save.zip

import pickle
data = pickle.load(open('save.pkl', 'rb'))
data.writeto('test.fits')

The data was created by the ligo.skymap library at this line.
https://git.ligo.org/lscsoft/ligo.skymap/-/blob/master/ligo/skymap/io/fits.py#L384

System Details

(env3) [ahnitz@hnb697 live]$ python d.py
Linux-5.11.8-200.fc33.x86_64-x86_64-with-glibc2.2.5
Python 3.8.8 (default, Feb 20 2021, 00:00:00)
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
Numpy 1.20.2
astropy 4.2.1
Scipy 1.6.0
Matplotlib 3.4.1

Activity

  1. github-actions commented on Apr 6, 2021

    @github-actions
    Contributor

    Welcome to Astropy 👋 and thank you for your first issue!

    A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

    If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

  2. ahnitz commented on Apr 6, 2021

    @ahnitz
    Author

    Note, I'm not very familiar with what PR #11486 was doing, nor the specific implementation in the downstream code.

    It may be that the error is in fact correct and working before was in some sense accidental. @lpsinger is the developer of the downstream code and can hopefully verify.

  3. embray commented on Apr 6, 2021

    @embray
    Member

    Thanks for the report and the sample data. I'll look at it.

  4. titodalcanton commented on Apr 6, 2021

    @titodalcanton
    Contributor

    Here is a shorter test case that reproduces the same error for me:

    import numpy as np
    from astropy.table import Table
    from astropy.io import fits
    
    
    history = ['a.very.loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong.string']
    
    m = Table(np.ones(16, dtype=float), copy=False)
    m.meta.update({'history': history})
    hdu = fits.table_to_hdu(m)
    hdulist = fits.HDUList([fits.PrimaryHDU(), hdu])
    hdulist.writeto('test2.fits', overwrite=True)
  5. added a commit that references this issue on Apr 6, 2021
    057c086
  6. embray commented on Apr 6, 2021

    @embray
    Member

    Workaround in #11487.

  7. added a commit that references this issue on Apr 6, 2021
  8. added a commit that references this issue on Apr 26, 2021
    4be6374
  9. added a commit that references this issue on May 3, 2021
    5210f67
  10. added a commit that references this issue on Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions