FITS header verification change from astropy version 4.2 to 4.3
See original GitHub issueDescription
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:
- Created 2 years ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
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.
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 afterCONTINUE
in the fits header through verify?