def _channel_loop(detection, template, min_cc, detection_id, interpolate, i,<EOL>pre_lag_ccsum=None, detect_chans=<NUM_LIT:0>,<EOL>horizontal_chans=['<STR_LIT:E>', '<STR_LIT:N>', '<STR_LIT:1>', '<STR_LIT:2>'], vertical_chans=['<STR_LIT>'],<EOL>debug=<NUM_LIT:0>):
from eqcorrscan.core.match_filter import normxcorr2<EOL>import math<EOL>event = Event()<EOL>s_stachans = {}<EOL>cccsum = <NUM_LIT:0><EOL>checksum = <NUM_LIT:0><EOL>used_chans = <NUM_LIT:0><EOL>for tr in template:<EOL><INDENT>temp_net = tr.stats.network<EOL>temp_sta = tr.stats.station<EOL>temp_chan = tr.stats.channel<EOL>debug_print('<STR_LIT>' % (temp_net, temp_sta, temp_chan),<EOL><NUM_LIT:3>, debug)<EOL>image = detection.select(station=temp_sta, channel=temp_chan)<EOL>if len(image) == <NUM_LIT:0> or sum(image[<NUM_LIT:0>].data) == <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>')<EOL>continue<EOL><DEDENT>if interpolate:<EOL><INDENT>try:<EOL><INDENT>ccc = normxcorr2(tr.data, image[<NUM_LIT:0>].data)<EOL><DEDENT>except Exception:<EOL><INDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>' % len(image[<NUM_LIT:0>].data))<EOL>print('<STR_LIT>' % len(tr.data))<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>shift, cc_max = _xcorr_interp(ccc=ccc, dt=image[<NUM_LIT:0>].stats.delta)<EOL><DEDENT>except IndexError:<EOL><INDENT>print('<STR_LIT>')<EOL>ccc = normxcorr2(tr.data, image[<NUM_LIT:0>].data)<EOL>cc_max = np.amax(ccc)<EOL>shift = np.argmax(ccc) * image[<NUM_LIT:0>].stats.delta<EOL><DEDENT>if math.isnan(cc_max):<EOL><INDENT>print('<STR_LIT>')<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>picktime = image[<NUM_LIT:0>].stats.starttime + shift<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>ccc = normxcorr2(tr.data, image[<NUM_LIT:0>].data)<EOL><DEDENT>except Exception:<EOL><INDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>' % len(image[<NUM_LIT:0>].data))<EOL>print('<STR_LIT>' % len(tr.data))<EOL>continue<EOL><DEDENT>cc_max = np.amax(ccc)<EOL>if math.isnan(cc_max):<EOL><INDENT>print('<STR_LIT>')<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>picktime = image[<NUM_LIT:0>].stats.starttime + (<EOL>np.argmax(ccc) * image[<NUM_LIT:0>].stats.delta)<EOL><DEDENT><DEDENT>debug_print('<STR_LIT>' % cc_max, <NUM_LIT:3>, debug)<EOL>checksum += cc_max<EOL>used_chans += <NUM_LIT:1><EOL>if cc_max < min_cc:<EOL><INDENT>debug_print('<STR_LIT>', <NUM_LIT:3>, debug)<EOL>continue<EOL><DEDENT>cccsum += cc_max<EOL>if temp_chan[-<NUM_LIT:1>] in vertical_chans:<EOL><INDENT>phase = '<STR_LIT:P>'<EOL><DEDENT>elif temp_chan[-<NUM_LIT:1>] in horizontal_chans:<EOL><INDENT>phase = '<STR_LIT:S>'<EOL>debug_print('<STR_LIT>' %<EOL>(temp_net, temp_sta, temp_chan), <NUM_LIT:4>, debug)<EOL>if temp_sta not in s_stachans.keys():<EOL><INDENT>s_stachans[temp_sta] = ((temp_chan, np.amax(ccc),<EOL>picktime))<EOL><DEDENT>elif temp_sta in s_stachans.keys():<EOL><INDENT>if np.amax(ccc) > s_stachans[temp_sta][<NUM_LIT:1>]:<EOL><INDENT>picktime = picktime<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>phase = None<EOL><DEDENT>_waveform_id = WaveformStreamID(<EOL>network_code=temp_net, station_code=temp_sta,<EOL>channel_code=temp_chan)<EOL>event.picks.append(Pick(<EOL>waveform_id=_waveform_id, time=picktime,<EOL>method_id=ResourceIdentifier('<STR_LIT>'), phase_hint=phase,<EOL>creation_info='<STR_LIT>',<EOL>evaluation_mode='<STR_LIT>',<EOL>comments=[Comment(text='<STR_LIT>' % cc_max)]))<EOL>event.resource_id = detection_id<EOL><DEDENT>ccc_str = ("<STR_LIT>" % cccsum)<EOL>event.comments.append(Comment(text=ccc_str))<EOL>if used_chans == detect_chans:<EOL><INDENT>if pre_lag_ccsum is not None andchecksum - pre_lag_ccsum < -(<NUM_LIT> * pre_lag_ccsum):<EOL><INDENT>msg = ('<STR_LIT>'<EOL>% (pre_lag_ccsum, checksum))<EOL>raise LagCalcError(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>% (detect_chans, used_chans))<EOL><DEDENT>return i, event<EOL>
Inner loop for correlating and assigning picks.

Utility function to take a stream of data for the detected event and write
maximum correlation to absolute time as picks in an obspy.core.event.Event
object.
Only outputs picks for picks above min_cc.

:type detection: obspy.core.stream.Stream
:param detection:
    Stream of data for the slave event detected using template.
:type template: obspy.core.stream.Stream
:param template: Stream of data as the template for the detection.
:type min_cc: float
:param min_cc: Minimum cross-correlation value to allow a pick to be made.
:type detection_id: str
:param detection_id: Detection ID to associate the event with.
:type interpolate: bool
:param interpolate:
    Interpolate the correlation function to achieve sub-sample precision.
:type i: int
:param i:
    Used to track which process has occurred when running in parallel.
:type pre_lag_ccsum: float
:param pre_lag_ccsum:
    Cross-correlation sum before lag-calc, will check that the
    cross-correlation sum is increased by lag-calc (using all channels,
    ignoring min_cc)
:type detect_chans: int
:param detect_chans:
    Number of channels originally used in detections, must match the number
    used here to allow for cccsum checking.
:type horizontal_chans: list
:param horizontal_chans:
    List of channel endings for horizontal-channels, on which S-picks will
    be made.
:type vertical_chans: list
:param vertical_chans:
    List of channel endings for vertical-channels, on which P-picks will
    be made.
:type debug: int
:param debug: Debug output level 0-5.

:returns:
    Event object containing network, station, channel and pick information.
:rtype: :class:`obspy.core.event.Event`