def template_remove(tr, template, cc_thresh, windowlength,<EOL>interp_len, debug=<NUM_LIT:0>):
data_in = tr.copy()<EOL>_interp_len = int(tr.stats.sampling_rate * interp_len)<EOL>if _interp_len < len(template.data):<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>_interp_len = len(template.data)<EOL><DEDENT>if isinstance(template, Trace):<EOL><INDENT>template = template.data<EOL><DEDENT>with Timer() as t:<EOL><INDENT>cc = normxcorr2(image=tr.data.astype(np.float32),<EOL>template=template.astype(np.float32))<EOL>if debug > <NUM_LIT:3>:<EOL><INDENT>plt.plot(cc.flatten(), '<STR_LIT:k>', label='<STR_LIT>')<EOL>plt.legend()<EOL>plt.show()<EOL><DEDENT>peaks = find_peaks2_short(arr=cc.flatten(), thresh=cc_thresh,<EOL>trig_int=windowlength * tr.stats.<EOL>sampling_rate)<EOL>for peak in peaks:<EOL><INDENT>tr.data = _interp_gap(data=tr.data,<EOL>peak_loc=peak[<NUM_LIT:1>] + int(<NUM_LIT:0.5> * _interp_len),<EOL>interp_len=_interp_len)<EOL><DEDENT><DEDENT>print("<STR_LIT>" % t.secs)<EOL>if debug > <NUM_LIT:2>:<EOL><INDENT>plt.plot(data_in.data, '<STR_LIT:r>', label='<STR_LIT>')<EOL>plt.plot(tr.data, '<STR_LIT:k>', label='<STR_LIT>')<EOL>plt.legend()<EOL>plt.show()<EOL><DEDENT>return tr<EOL>
Looks for instances of template in the trace and removes the matches.

:type tr: obspy.core.trace.Trace
:param tr: Trace to remove spikes from.
:type template: osbpy.core.trace.Trace
:param template: Spike template to look for in data.
:type cc_thresh: float
:param cc_thresh: Cross-correlation threshold (-1 - 1).
:type windowlength: float
:param windowlength: Length of window to look for spikes in in seconds.
:type interp_len: float
:param interp_len: Window length to remove and fill in seconds.
:type debug: int
:param debug: Debug level.

:returns: tr, works in place.
:rtype: :class:`obspy.core.trace.Trace`