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.

FITS header verification change from astropy version 4.2 to 4.3

See original GitHub issue

Description

I am using astropy.io.fits to work with fits files from GOES/SUVI. Those fits files have an issue with the CONTINUE convention, which is implemented incorrectly. Until astropy version 4.2, I was able to use the .tostring() method to convert the corrupt fits header to a string, fix it, and convert it back to a corrected fits header. Starting with astropy version 4.2.1, this is no longer possible: the .tostring() method now seems to do a fits header validity check and will not allow me to access the header. Setting verify to “ignore” does not help, but maybe I am using it wrong.

Is this the desired behaviour? For me this means I am no longer able to fix the corrupt fits header. I believe that if it is known that a fits header is not compliant with the fits standard, there should at least be an option to ignore the validity check so it is still accessible and can be fixed.

Expected behavior

Behaviour with Astropy 4.2 in a one-liner on the command line (test files can be found here):

python -c "import astropy; from astropy.io import fits; hdu = fits.open('OR_SUVI-L1b-Fe171_G16_s20193490001210_e20193490001220_c20193490001462.fits'); print('Astropy version:', astropy.__version__); hdu.verify('ignore'); hdu[0].header.tostring()"
Astropy version: 4.2

Actual behavior

Behaviour with Astropy 4.2.1 in a one-liner on the command line:

python -c "import astropy; from astropy.io import fits; hdu = fits.open('OR_SUVI-L1b-Fe171_G16_s20193490001210_e20193490001220_c20193490001462.fits'); print('Astropy version:', astropy.__version__); hdu.verify('ignore'); hdu[0].header.tostring()"
Astropy version: 4.2.1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/header.py", line 689, in tostring
    s = str(card)
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 206, in __str__
    return self.image
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 501, in image
    self.verify('fix+warn')
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/verify.py", line 73, in verify
    errs = self._verify(opt)
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 1100, in _verify
    keyword = self._split()[0]
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 815, in _split
    for card in self._itersubcards():
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 1174, in _itersubcards
    if not isinstance(card.value, str):
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 286, in value
    value = self._value = self._parse_value()
  File "/Users/chris/opt/anaconda3/envs/astropy_test/lib/python3.8/site-packages/astropy/io/fits/card.py", line 733, in _parse_value
    raise VerifyError("Unparsable card ({}), fix it first with "
astropy.io.fits.verify.VerifyError: Unparsable card (CONTINUE), fix it first with .verify('fix').

Steps to Reproduce

See above.

System Details

Darwin-20.5.0-x86_64-i386-64bit Python 3.7.10 (default, Feb 26 2021, 10:16:00) [Clang 10.0.0 ] Numpy 1.19.2 astropy 4.2 and astropy 4.2.1 Scipy 1.6.0 Matplotlib 3.3.4

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
saimncommented, Aug 11, 2021

I should have read again the original issue 😬. So this must be a side effect of #11108, maybe @embray will have an idea to fix it.

0reactions
nabobaliscommented, Apr 30, 2022

Hi everyone!

What would be a good outcome for this issue?

Allowing a person to get a non-standard fits header through .getheader() and allowing that to be exported to a string via .tostring() to be fixed later on? Fixing the lack of spaces after CONTINUE in the fits header through verify?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Edit a FITS header — Astropy v5.2
This example describes how to edit a value in a FITS header using astropy. io. fits .
Read more >
error creating a new FITS image with data & header #1559
I'm using Python 2.7 and astropy version 0.2.4 on my Macbook Pro, which is running Mountain Lion 10.8.5. import numpy as np import...
Read more >
2.4 Headers and Keywords - HST User Documentation - HDox
The example below shows how these tasks are used to print the value for the SCI extension header keyword CRVAL1 with Python. ?...
Read more >
TOPCAT - Tool for OPerations on Catalogues And Tables
FITS, VOTable, ECSV, CDF, PDS4, feather, Parquet and GBIN files are recognised automatically; if your data is in another format such as ASCII...
Read more >
Astropy Documentation - Read the Docs
1.5 Inspecting FITS headers from the command line ... You can check for the list of available versions with conda search astropy.
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