Fixing incorrect metadata#

There will be times where you will come across a FITS files with either incorrect, missing or unparsable metadata and reading these files into Map will cause an error. Therefore, to load these files into a Map, you will need to correct the metadata beforehand.

In the example below, the units in the FITS header, as controlled by the CUNIT1 and CUNIT2 keywords, are incorrect. Before loading the file into a Map, we will correct these keywords to have the correct units.

>>> from astropy.io import fits

>>> from sunpy.map import Map
>>> import sunpy.data.sample

>>> filepath = sunpy.data.sample.AIA_171_IMAGE  
>>> data, header = fits.getdata(filepath, header=True)  
>>> # Note that it is case insensitive for the keys
>>> header['cunit1'] = 'arcsec'  
>>> header['cunit2'] = 'arcsec'  
>>> updated_map = Map(data, header)  

This applies for any keyword in the FITS standard.