def lag_calc(self, stream, pre_processed, shift_len=<NUM_LIT>, min_cc=<NUM_LIT>,<EOL>horizontal_chans=['<STR_LIT:E>', '<STR_LIT:N>', '<STR_LIT:1>', '<STR_LIT:2>'], vertical_chans=['<STR_LIT>'],<EOL>cores=<NUM_LIT:1>, interpolate=False, plot=False, parallel=True,<EOL>overlap='<STR_LIT>', process_cores=None, debug=<NUM_LIT:0>):
catalog = Catalog()<EOL>template_groups = [[]]<EOL>detection_groups = [[]]<EOL>for master in self.families:<EOL><INDENT>master_chans = [(tr.stats.station,<EOL>tr.stats.channel) for tr in master.template.st]<EOL>if len(master_chans) > len(set(master_chans)):<EOL><INDENT>warnings.warn(master.template.name +<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>continue<EOL><DEDENT>for group in template_groups:<EOL><INDENT>if master.template in group:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>new_group = [master.template.copy()]<EOL>new_det_group = copy.deepcopy(master.detections)<EOL>for slave in self.families:<EOL><INDENT>if master.template.same_processing(slave.template) andmaster.template != slave.template:<EOL><INDENT>slave_chans = [<EOL>(tr.stats.station,<EOL>tr.stats.channel) for tr in slave.template.st]<EOL>if len(slave_chans) > len(set(slave_chans)):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>new_group.append(slave.template.copy())<EOL>new_det_group.extend(<EOL>copy.deepcopy(slave.detections))<EOL><DEDENT><DEDENT><DEDENT>template_groups.append(new_group)<EOL>detection_groups.append(new_det_group)<EOL><DEDENT><DEDENT>for group, det_group in zip(template_groups, detection_groups):<EOL><INDENT>if len(group) == <NUM_LIT:0>:<EOL><INDENT>template_groups.remove(group)<EOL>detection_groups.remove(det_group)<EOL><DEDENT><DEDENT>for group, det_group in zip(template_groups, detection_groups):<EOL><INDENT>lap = <NUM_LIT:0.0><EOL>for template in group:<EOL><INDENT>starts = [t.stats.starttime for t in<EOL>template.st.sort(['<STR_LIT>'])]<EOL>if starts[-<NUM_LIT:1>] - starts[<NUM_LIT:0>] > lap:<EOL><INDENT>lap = starts[-<NUM_LIT:1>] - starts[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>if overlap is None:<EOL><INDENT>lap = <NUM_LIT:0.0><EOL><DEDENT>elif isinstance(overlap, float):<EOL><INDENT>lap = overlap<EOL><DEDENT>if not pre_processed:<EOL><INDENT>if process_cores is None:<EOL><INDENT>process_cores = cores<EOL><DEDENT>processed_streams = _group_process(<EOL>template_group=group, cores=process_cores,<EOL>parallel=parallel, stream=stream.copy(), debug=debug,<EOL>daylong=False,  ignore_length=False, overlap=lap)<EOL>processed_stream = Stream()<EOL>for p in processed_streams:<EOL><INDENT>processed_stream += p<EOL><DEDENT>processed_stream.merge(method=<NUM_LIT:1>)<EOL>print(processed_stream)<EOL><DEDENT>else:<EOL><INDENT>processed_stream = stream<EOL><DEDENT>temp_cat = lag_calc(<EOL>detections=det_group, detect_data=processed_stream,<EOL>template_names=[t.name for t in group],<EOL>templates=[t.st for t in group], shift_len=shift_len,<EOL>min_cc=min_cc, horizontal_chans=horizontal_chans,<EOL>vertical_chans=vertical_chans, cores=cores,<EOL>interpolate=interpolate, plot=plot, parallel=parallel,<EOL>debug=debug)<EOL>for event in temp_cat:<EOL><INDENT>det = [d for d in det_group<EOL>if str(d.id) == str(event.resource_id)][<NUM_LIT:0>]<EOL>pre_pick = [t for t in group<EOL>if t.name == det.template_name][<NUM_LIT:0>].prepick<EOL>for pick in event.picks:<EOL><INDENT>pick.time += pre_pick<EOL><DEDENT><DEDENT>catalog += temp_cat<EOL><DEDENT>return catalog<EOL>
Compute picks based on cross-correlation alignment.

:type stream: obspy.core.stream.Stream
:param stream:
    All the data needed to cut from - can be a gappy Stream.
:type pre_processed: bool
:param pre_processed:
    Whether the stream has been pre-processed or not to match the
    templates. See note below.
:type shift_len: float
:param shift_len:
    Shift length allowed for the pick in seconds, will be plus/minus
    this amount - default=0.2
:type min_cc: float
:param min_cc:
    Minimum cross-correlation value to be considered a pick,
    default=0.4.
: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 cores: int
:param cores:
    Number of cores to use in parallel processing, defaults to one.
:type interpolate: bool
:param interpolate:
    Interpolate the correlation function to achieve sub-sample
    precision.
:type plot: bool
:param plot:
    To generate a plot for every detection or not, defaults to False
:type parallel: bool
:param parallel: Turn parallel processing on or off.
:type overlap: float
:param overlap:
    Either None, "calculate" or a float of number of seconds to
    overlap detection streams by.  This is to counter the effects of
    the delay-and-stack in calculating cross-correlation sums. Setting
    overlap = "calculate" will work out the appropriate overlap based
    on the maximum lags within templates.
:type process_cores: int
:param process_cores:
    Number of processes to use for pre-processing (if different to
    `cores`).
:type debug: int
:param debug: Debug output level, 0-5 with 5 being the most output.

:returns:
    Catalog of events with picks.  No origin information is included.
    These events can then be written out via
    :func:`obspy.core.event.Catalog.write`, or to Nordic Sfiles using
    :func:`eqcorrscan.utils.sfile_util.eventtosfile` and located
    externally.
:rtype: obspy.core.event.Catalog

.. Note::
    Note on pre-processing: You can provide a pre-processed stream,
    which may be beneficial for detections over large time periods
    (the stream can have gaps, which reduces memory usage).  However,
    in this case the processing steps are not checked, so you must
    ensure that all the template in the Party have the same sampling
    rate and filtering as the stream.
    If pre-processing has not be done then the data will be processed
    according to the parameters in the templates, in this case
    templates will be grouped by processing parameters and run with
    similarly processed data.  In this case, all templates do not have
    to have the same processing parameters.

.. Note::
    Picks are corrected for the template pre-pick time.