def decluster(self, trig_int, timing='<STR_LIT>', metric='<STR_LIT>'):
all_detections = []<EOL>for fam in self.families:<EOL><INDENT>all_detections.extend(fam.detections)<EOL><DEDENT>if timing == '<STR_LIT>':<EOL><INDENT>if metric == '<STR_LIT>':<EOL><INDENT>detect_info = [(d.detect_time, d.detect_val / d.no_chans)<EOL>for d in all_detections]<EOL><DEDENT>elif metric == '<STR_LIT>':<EOL><INDENT>detect_info = [(d.detect_time, d.detect_val)<EOL>for d in all_detections]<EOL><DEDENT>else:<EOL><INDENT>raise MatchFilterError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif timing == '<STR_LIT>':<EOL><INDENT>if metric == '<STR_LIT>':<EOL><INDENT>detect_info = [(_get_origin(d.event).time,<EOL>d.detect_val / d.no_chans)<EOL>for d in all_detections]<EOL><DEDENT>elif metric == '<STR_LIT>':<EOL><INDENT>detect_info = [(_get_origin(d.event).time, d.detect_val)<EOL>for d in all_detections]<EOL><DEDENT>else:<EOL><INDENT>raise MatchFilterError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise MatchFilterError('<STR_LIT>')<EOL><DEDENT>min_det = sorted([d[<NUM_LIT:0>] for d in detect_info])[<NUM_LIT:0>]<EOL>detect_vals = np.array([d[<NUM_LIT:1>] for d in detect_info])<EOL>detect_times = np.array([<EOL>_total_microsec(d[<NUM_LIT:0>].datetime, min_det.datetime)<EOL>for d in detect_info])<EOL>peaks_out = decluster(<EOL>peaks=detect_vals, index=detect_times, trig_int=trig_int * <NUM_LIT:10> ** <NUM_LIT:6>)<EOL>declustered_detections = []<EOL>for ind in peaks_out:<EOL><INDENT>matching_time_indeces = np.where(detect_times == ind[-<NUM_LIT:1>])[<NUM_LIT:0>]<EOL>matches = matching_time_indeces[<EOL>np.where(detect_vals[matching_time_indeces] == ind[<NUM_LIT:0>])[<NUM_LIT:0>][<NUM_LIT:0>]]<EOL>declustered_detections.append(all_detections[matches])<EOL><DEDENT>template_names = list(set([d.template_name<EOL>for d in declustered_detections]))<EOL>new_families = []<EOL>for template_name in template_names:<EOL><INDENT>template = [fam.template for fam in self.families<EOL>if fam.template.name == template_name][<NUM_LIT:0>]<EOL>new_families.append(Family(<EOL>template=template,<EOL>detections=[d for d in declustered_detections<EOL>if d.template_name == template_name]))<EOL><DEDENT>self.families = new_families<EOL>return self<EOL>
De-cluster a Party of detections by enforcing a detection separation.

De-clustering occurs between events detected by different (or the same)
templates. If multiple detections occur within trig_int then the
preferred detection will be determined by the metric argument. This
can be either the average single-station correlation coefficient which
is calculated as Detection.detect_val / Detection.no_chans, or the
raw cross channel correlation sum which is simply Detection.detect_val.

:type trig_int: float
:param trig_int: Minimum detection separation in seconds.
:type metric: str
:param metric: What metric to sort peaks by. Either 'avg_cor' which
    takes the single station average correlation or 'cor_sum' which
    takes the total correlation sum across all channels.
:type timing: str
:param timing:
    Either 'detect' or 'origin' to decluster based on either the
    detection time or the origin time.

.. Warning::
    Works in place on object, if you need to keep the original safe
    then run this on a copy of the object!

.. rubric:: Example

>>> party = Party().read()
>>> len(party)
4
>>> declustered = party.decluster(20)
>>> len(party)
3