SunPy map


One of core classes in SunPy is a Map. A SunPy Map object is simply a spatially-aware data array, often an image. In order to make it easy to work with image data in SunPy, the Map object provides a number of methods for commonly performed operations.

2D map objects are subclasses of and all Map objects are created using the Map factory

Creating Map Objects

SunPy Map objects are constructed using the special factory class Map:

>>> x ='file.fits')

The result of a call to Map will be either a mapbase.GenericMap object, or a subclass of mapbase.GenericMap which either deals with a specific type of data, e.g. AIAMap or LASCOMap, or if no instrument matches, a 2D map mapbase.GenericMap.

Map Classes

There are a series of base map classes which are specalised for each instrument. These subclass GenericMap and then register with the Map factory class, which will direct instatiation of an instrument class if the correct parameters are met.


CompositeMap(map1 [,map2,..]) A Composite Map class :Parameters: args : [ | string] One or more map of filepaths ..
GenericMap(data, header, **kwargs) A Generic spatially-aware 2D data array :Parameters: data : numpy.ndarray, list A 2d list or ndarray containing the map data header : dict A dictionary of the original image header tags ..
MapCube(input) A series of spatially aligned Maps.
MapMeta(adict, *args) A class to hold meta data associated with a Map derivative.

Class Inheritance Diagram

Inheritance diagram of,,,

Writing a new Map Class

Map classes can be registered with the Map factory, even if the new class is not officially part of SunPy. This is good for prototyping new instruments. For example, to add a Map type for a future instrument, consider the code skeleton

import sunpy

class FutureMap(sunpy.GenericMap):

    def __init__(self, data, header, **kwargs):

        GenericMap.__init__(self, data, header, **kwargs)

        # Any Future Instrument specific keyword manipulation

   # Specify a classmethod that determines if the data-header pair matches
   # the new instrument
   def is_datasource_for(cls, data, header, **kwargs):
        """Determines if header corresponds to an AIA image"""
        return header.get('instrume', '').startswith('FUTURESCOPE')

Then, to be able to instantiate a FutureMap using the Map() factory, one must register the FutureMap type with the factory, FutureMap.is_datasource_for)

If this line is placed correctly, for example in your subpackages, it can be guaranteed that the FutureMap is always accessible when your package is imported.