def coin_trig(peaks, stachans, samp_rate, moveout, min_trig, trig_int):
triggers = []<EOL>for stachan, _peaks in zip(stachans, peaks):<EOL><INDENT>for peak in _peaks:<EOL><INDENT>trigger = (peak[<NUM_LIT:1>], peak[<NUM_LIT:0>], '<STR_LIT:.>'.join(stachan))<EOL>triggers.append(trigger)<EOL><DEDENT><DEDENT>coincidence_triggers = []<EOL>for i, master in enumerate(triggers):<EOL><INDENT>slaves = triggers[i + <NUM_LIT:1>:]<EOL>coincidence = <NUM_LIT:1><EOL>trig_time = master[<NUM_LIT:0>]<EOL>trig_val = master[<NUM_LIT:1>]<EOL>for slave in slaves:<EOL><INDENT>if abs(slave[<NUM_LIT:0>] - master[<NUM_LIT:0>]) <= (moveout * samp_rate) andslave[<NUM_LIT:2>] != master[<NUM_LIT:2>]:<EOL><INDENT>coincidence += <NUM_LIT:1><EOL>if slave[<NUM_LIT:0>] < master[<NUM_LIT:0>]:<EOL><INDENT>trig_time = slave[<NUM_LIT:0>]<EOL><DEDENT>trig_val += slave[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if coincidence >= min_trig:<EOL><INDENT>coincidence_triggers.append((trig_val / coincidence,<EOL>trig_time))<EOL><DEDENT><DEDENT>if coincidence_triggers:<EOL><INDENT>coincidence_triggers.sort(key=lambda tup: tup[<NUM_LIT:0>], reverse=True)<EOL>output = [coincidence_triggers[<NUM_LIT:0>]]<EOL>for coincidence_trigger in coincidence_triggers[<NUM_LIT:1>:]:<EOL><INDENT>add = True<EOL>for peak in output:<EOL><INDENT>if abs(coincidence_trigger[<NUM_LIT:1>] - peak[<NUM_LIT:1>]) < (trig_int *<EOL>samp_rate):<EOL><INDENT>add = False<EOL>break<EOL><DEDENT><DEDENT>if add:<EOL><INDENT>output.append((coincidence_trigger[<NUM_LIT:0>],<EOL>coincidence_trigger[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>output.sort(key=lambda tup: tup[<NUM_LIT:1>])<EOL>return output<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT>
Find network coincidence triggers within peaks of detection statistics.

Useful for finding network detections from sets of detections on individual
stations.

:type peaks: list
:param peaks: List of lists of tuples of (peak, index) for each \
    station-channel.  Index should be in samples.
:type stachans: list
:param stachans: List of tuples of (station, channel) in the order of \
    peaks.
:type samp_rate: float
:param samp_rate: Sampling rate in Hz
:type moveout: float
:param moveout: Allowable network moveout in seconds.
:type min_trig: int
:param min_trig: Minimum station-channels required to declare a trigger.
:type trig_int: float
:param trig_int:
    Minimum allowable time between network triggers in seconds.

:return:
    List of tuples of (peak, index), for the earliest detected station.
:rtype: list

>>> peaks = [[(0.5, 100), (0.3, 800)], [(0.4, 120), (0.7, 850)]]
>>> triggers = coin_trig(peaks, [('a', 'Z'), ('b', 'Z')], 10, 3, 2, 1)
>>> print(triggers)
[(0.45, 100)]