Converting images to fits files and Map them

72 views
Skip to first unread message

Arpita Roddanavar

unread,
Apr 1, 2023, 12:37:53 PM4/1/23
to SunPy
Hello everyone, 

I am trying to convert an imshow image to a fits file. I could do that, but when I try to Map the fits file, it says that the metadata is missing! Can you please assist me with this!

PS: (I am new to sunpy !!) 

MapMetaValidationError: Image coordinate units for axis 1 not present in metadata. Image coordinate units for axis 2 not present in metadata.

Nabil Freij

unread,
Apr 1, 2023, 12:55:44 PM4/1/23
to SunPy
Hello,

When you save an imshow figure to a FITS file (I am unsure how you would do that through matplotlib), you are just saving the figure data (which I imagine is the data array) and not any of the metadata found in the original file. 
When you try to load this back into sunpy.Map, it will try to load the metadata, find there is no metadata and error. As you have encountered.

If you want to save a Map into a new FITS file, you can use the `.save` method.

Hopefully that helps.

Kind regards,
Nabil

Arpita Roddanavar

unread,
Apr 1, 2023, 1:15:19 PM4/1/23
to SunPy
Hello Nabil, 

Thank you very much for responding. I understand what you said. 
But I have a numpy array of the calculated 'Bz' magnetic field that I want to compare to the corresponding aia image. Could you please advise me on how to proceed without converting the image to a map?

Best,
Arpita

Nabil Freij

unread,
Apr 1, 2023, 4:40:23 PM4/1/23
to SunPy
Hello Arpita,

Without a better understanding of your final goal or the data you are using, all I can suggest either:

1. You plot both both the AIA data array and the Bz data array using matplotlib's imshow and construct the correct projection using the AIA file and using Map. See https://docs.sunpy.org/en/stable/generated/gallery/plotting/wcsaxes_map_example.html#sphx-glr-generated-gallery-plotting-wcsaxes-map-example-py
2. You construct a sunpy Map manually for the Bz data, using either the AIA metadata or a HMI data file or by hand (see https://docs.sunpy.org/en/stable/generated/gallery/map/map_from_numpy_array.html#sphx-glr-generated-gallery-map-map-from-numpy-array-py).

Hopefully one of these are useful.  

Kind regards,
Nabil

Arpita Roddanavar

unread,
Apr 1, 2023, 7:20:40 PM4/1/23
to SunPy
Hello Nabil, 

Thank you very much for your response. I will try both the methods!

Best,
Arpita

Reply all
Reply to author
Forward
0 new messages