How to create a sunpy Map#

One of the primary goals of the Map interface is to make it as easy as possible to create a Map. As such, you can pass many different kinds of inputs to Map. These are listed below.

File name#

If you have a FITS file, this is the easiest and recommended way to create a Map. This can be either a string or a Path.

>>> import pathlib

>>> import sunpy.map
>>> import sunpy.data.sample

>>> my_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)  
>>> my_map = sunpy.map.Map('file.fits')  
>>> my_map = sunpy.map.Map(pathlib.Path('file.fits'))  
>>> sub_dir = pathlib.Path('local_dir/sub_dir')
>>> my_map = sunpy.map.Map(sub_dir / 'another_file.fits')   

Directory containing FITS files#

If there is more than one FITS file in the directory, this will return a list of Map objects.

>>> my_maps = sunpy.map.Map('local_dir/sub_dir')   
>>> my_maps = sunpy.map.Map(sub_dir)   

Array and astropy.io.fits.Header#

If needed, this way can be used to modify the header before passing it to Map.

>>> import astropy.io.fits

>>> with astropy.io.fits.open(sunpy.data.sample.AIA_171_IMAGE) as hdul:
...     data = hdul[1].data
...     header = hdul[1].header  
>>> my_map = sunpy.map.Map(data, header)  

These data header pairs can also be passed as a tuple,

>>> my_map = sunpy.map.Map((data, header))  

Data array and a MetaDict object#

This includes any base class of MetaDict, including dict or collections.OrderedDict.

>>> import sunpy.util.metadata

>>> meta = sunpy.util.metadata.MetaDict(header)  
>>> my_map = sunpy.map.Map(data, meta)   

Data array and an astropy.wcs.WCS object#

>>> import astropy.wcs

>>> wcs = astropy.wcs.WCS(header=header)  
>>> my_map = sunpy.map.Map(data, wcs)  

Glob patterns#

If the glob pattern matches more than one FITS file, this will return a list of Map objects.

>>> my_map = sunpy.map.Map('eit_*.fits')   

URL#

>>> sample_data_url = 'http://data.sunpy.org/sunpy/v1/AIA20110607_063302_0171_lowres.fits'
>>> my_map = sunpy.map.Map(sample_data_url)  

Combinations of any of the above#

These can either be in a list or as separate arguments. As with the case of a directory or glob pattern, this will return multiple Map objects.

>>> my_map = sunpy.map.Map(['file1.fits', 'file2.fits', 'file3.fits', 'directory1/'])  
>>> my_map = sunpy.map.Map((data, header), data, meta, 'file1.fits', sample_data_url, 'eit_*.fits')