FITS headers don't update immediately?
See original GitHub issueThis is an issue noted on https://github.com/astropy/astropy/issues/5396, but is independent of that issue.
In short, given a FITS header with an invalid entry (e.g., a newline within the 'ORIGIN'
value), the following will happen:
fh = fits.open(fn)
fh[0].header.tostring() # produces exception
fh[0].header.tostring() # does not produce exception
>>> h = fits.open('test1n.fits')
>>> h[0].header['origin'] = 'goodval'
>>> w = wcs.WCS(h[0].header) # <- crashes
# a repeat attempt here would (probably) not crash
see: https://github.com/astropy/astropy/issues/5396#issuecomment-252687514, https://github.com/astropy/astropy/issues/5396#issuecomment-252699025, https://github.com/astropy/astropy/issues/5396#issuecomment-252700815, https://github.com/astropy/astropy/issues/5396#issuecomment-252701891
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Headers — Astropy v5.2
Write the header as text to a file or a file-like object. Update the Header with new keyword values, updating the values of...
Read more >Batch edit fits headers | PixInsight Forum
I have a bunch of darks that mistakenly have the OBJECT keyword as M1. Is there a way to batch edit the keyword...
Read more >Headers — Astropy v1.0.4
A string representing a FITS header. Update the Header with new keyword values, updating the values of existing keywords and appending new keywords...
Read more >How to conserve header when saving an edited .fits file with ...
First of all don't do this: im = fits.getdata('myfile.fits') header = fits.getheader('myfile.fits'). As explained in the warning here, ...
Read more >Editing the FITS Header - Mirametrics
The header of a FITS Format Image contains a lot of image documentation. Most Mira commands update and change it as necessary to...
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 Free
Top 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
Just to confirm that there is clearly an issue :
It looks like the private
Card._image
is not updated when setting a new value, and this attribute is used at least when verifying the card which brings back the old value ! 😨That is indeed the fix. I had several hundred images with newline characters in the header, fixed them with this snippet (your workaround is in the last few lines):