printing fits_header attribute of Map object causes ValueError exception if metadata values include comments · Issue #7926 · sunpy/sunpy · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to add values with comments to the metadata of a Sunpy map. I can create the map with the metadata with comments, e.g. mdata['value'] = (42, 'meaning of life'). And if I print them it looks right, roughly, printing as ('value', (42, 'meaning of life')). However if I try to do mmap.fits_header, I get an error:
ValueError: Illegal value: (42, 'meaning of life')
which is actually raised by astropy/io/fits/card.py (which is called in sunpy/io/_fits.py
It appears that Map metadata doesn't support comments. If I create a map object from data and a fits header object that has comments for some of its keywords, the comments just get dropped in the map metadata.
This is just a quick drive-by from my phone, but I am pretty sure sunpy meta doesn't support the = (value, comment) syntax like astropy. I think you need to edit the key comments dict (I can't remember exactly where that is)
Yes, I found a way to add comments to the metadata. You have to add items to the 'keycomments' dictionary:
mmap = sunpy.map.Map(fits_file)
mdata = mmap.meta
mdata["value"] = 42
mdata['keycomments"]["value"] = "meaning of life"
Whether doing that could/should be made simpler is something that could be discussed.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I've been trying to add values with comments to the metadata of a Sunpy map. I can create the map with the metadata with comments, e.g. mdata['value'] = (42, 'meaning of life'). And if I print them it looks right, roughly, printing as ('value', (42, 'meaning of life')). However if I try to do mmap.fits_header, I get an error:
ValueError: Illegal value: (42, 'meaning of life')
which is actually raised by astropy/io/fits/card.py (which is called in sunpy/io/_fits.py
To Reproduce
import sunpy
mmap = sunpy.map.Map(fits_file)
mdata = mmap.meta
mdata['value'] = (42, 'meaning of life')
mmap2 = sunpy.map.Map(mmap.data, mdata)
mmap2.fits_header
The text was updated successfully, but these errors were encountered: