10000 printing fits_header attribute of Map object causes ValueError exception if metadata values include comments · Issue #7926 · sunpy/sunpy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

printing fits_header attribute of Map object causes ValueError exception if metadata values include comments #7926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jslavin opened this issue Dec 11, 2024 · 3 comments
Labels
Discussion An issue opened for, or undergoing discussion. map Affects the map submodule

Comments

@jslavin
Copy link
jslavin commented Dec 11, 2024

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

@jslavin
Copy link
Author
jslavin commented Dec 11, 2024

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.

@Cadair
Copy link
Member
Cadair commented Dec 11, 2024

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)

@nabobalis nabobalis added map Affects the map submodule Discussion An issue opened for, or undergoing discussion. labels Dec 11, 2024
@jslavin
Copy link
Author
jslavin commented Dec 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion An issue opened for, or undergoing discussion. map Affects the map submodule
Projects
None yet
Development

No branches or pull requests

3 participants
0