mapsequence_coalign_by_match_template#
- 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 thatMapSequence
.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 coalignedMapSequence
, 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 tr_get_disp.pro. In this implementation, the template matching is handled via
skimage.feature.match_template
.- Parameters:
mc (
sunpy.map.MapSequence
) – AMapSequence
of shape(ny, nx, nt)
, wherent
is the number of layers in theMapSequence
.template ({None | sunpy.map.Map |
numpy.ndarray
}, optional) – The template used in the matching. If annumpy.ndarray
is passed, thenumpy.ndarray
has to have two dimensions.layer_index (
int
, optional) – The template is assumed to refer to the map in theMapSequence
indexed by the value oflayer_index
. Displacements of all maps in theMapSequence
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 anQuantity
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 inputMapSequence
. The number of elements in each array must be the same as the number of maps in theMapSequence
. If a shift is passed in to the function, that shift is applied to the inputMapSequence
and the template matching algorithm is not used.
Notes
The remaining keyword arguments are sent to
apply_shifts
.- Returns:
sunpy.map.MapSequence
– AMapSequence
that has co-aligned by matching the template.
Examples
>>> 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)
References
J.P. Lewis, Fast Template Matching, Vision Interface 95, Canadian Image Processing and Pattern Recognition Society, Quebec City, Canada, May 15-19, 1995, p. 120-123 http://www.scribblethink.org/Work/nvisionInterface/vi95_lewis.pdf.