obspy.signal.cross_correlation.correlate_template
- correlate_template(data, template, mode='valid', normalize='full', demean=True, method='auto')[source]
Normalized cross-correlation of two signals with specified mode.
If you are interested only in a part of the cross-correlation function around zero shift consider using function
correlate()
which allows to explicetly specify the maximum shift.- Parameters:
template (
ndarray
,Trace
) – second signal to correlate with first signal. Its length must be smaller or equal to the length ofdata
.mode (str) – correlation mode to use. It is passed to the used correlation function. See
scipy.signal.correlate()
for possible options. The parameter determines the length of the correlation function.normalize – One of
'naive'
,'full'
orNone
.'full'
normalizes every correlation properly, whereas'naive'
normalizes by the overall standard deviations.None
does not normalize.demean – Demean data beforehand. For
normalize='full'
data is demeaned in different windows for each correlation value.method (str) – Method to use to calculate the correlation.
'direct'
: The correlation is determined directly from sums, the definition of correlation.'fft'
The Fast Fourier Transform is used to perform the correlation more quickly.'auto'
Automatically chooses direct or Fourier method based on an estimate of which is faster. (Only availlable for SciPy versions >= 0.19. For older Scipy version method defaults to'fft'
.)
- Returns:
cross-correlation function.
Note
Calling the function with
demean=True, normalize='full'
(default) returns the zero-normalized cross-correlation function. Calling the function withdemean=False, normalize='full'
returns the normalized cross-correlation function.Example
>>> from obspy import read >>> data = read()[0] >>> template = data[450:550] >>> cc = correlate_template(data, template) >>> index = np.argmax(cc) >>> index 450 >>> round(cc[index], 9) 1.0