sunkit_image.coalignment.mapsequence_coalign_by_match_template(mc, *, template=None, layer_index=0, func=<function _default_fmap_function>, clip=True, shift=None, **kwargs)[source]#

Co-register the layers in a MapSequence according to a template taken from that MapSequence.

When using this functionality, it is a good idea to check that the shifts that were applied were reasonable and expected. One way of checking this is to animate the original MapSequence, animate the coaligned MapSequence, and compare the differences you see to the calculated shifts.

Currently this module provides image co-alignment by template matching. and is partially inspired by the SSWIDL routine In this implementation, the template matching is handled via skimage.feature.match_template.

  • mc ( – A MapSequence of shape (ny, nx, nt), where nt is the number of layers in the MapSequence.

  • template ({ None , , numpy.ndarray }, optional) – The template used in the matching. If an numpy.ndarray is passed, the numpy.ndarray has to have two dimensions.

  • layer_index (int, optional) – The template is assumed to refer to the map in the MapSequence indexed by the value of layer_index. Displacements of all maps in the MapSequence are assumed to be relative to this layer. The displacements of the template relative to this layer are therefore (0, 0).

  • func (function, optional) – A function which is applied to the data values before the coalignment method is applied. This can be useful in coalignment, because it is sometimes better to co-align on a function of the data rather than the data itself. The calculated shifts are applied to the original data. Examples of useful functions to consider for EUV images are the logarithm or the square root. The function is of the form func = F(data). The default function ensures that the data are floats.

  • clip (bool, optional) – If True, then clip off x, y edges of the maps in the sequence that are potentially affected by edges effects.

  • shift (dict, optional) – A dictionary with two keys, ‘x’ and ‘y’. Key ‘x’ is an astropy quantities array of corresponding to the amount of shift in the x-direction (in arcseconds, assuming the helio-projective Cartesian coordinate system) that is applied to the input MapSequence. Key ‘y’ is an Quantity array corresponding to the amount of shift in the y-direction (in arcseconds, assuming the helio-projective Cartesian coordinate system) that is applied to the input MapSequence. The number of elements in each array must be the same as the number of maps in the MapSequence. If a shift is passed in to the function, that shift is applied to the input MapSequence and the template matching algorithm is not used.


The remaining keyword arguments are sent to apply_shifts.

Returns: – A MapSequence that has co-aligned by matching the template.


>>> from sunkit_image.coalignment import mapsequence_coalign_by_match_template as mc_coalign
>>> coaligned_mc = mc_coalign(mc)  
>>> coaligned_mc = mc_coalign(mc, layer_index=-1)  
>>> coaligned_mc = mc_coalign(mc, clip=False)  
>>> coaligned_mc = mc_coalign(mc, template=sunpy_map)  
>>> coaligned_mc = mc_coalign(mc, template=two_dimensional_ndarray)  
>>> coaligned_mc = mc_coalign(mc, func=np.log)