def write_correlations(event_list, wavbase, extract_len, pre_pick, shift_len,<EOL>lowcut=<NUM_LIT:1.0>, highcut=<NUM_LIT>, max_sep=<NUM_LIT:8>, min_link=<NUM_LIT:8>,<EOL>cc_thresh=<NUM_LIT:0.0>, plotvar=False, debug=<NUM_LIT:0>):
warnings.filterwarnings(action="<STR_LIT:ignore>",<EOL>message="<STR_LIT>" +<EOL>"<STR_LIT>")<EOL>corr_list = []<EOL>f = open('<STR_LIT>', '<STR_LIT:w>')<EOL>f2 = open('<STR_LIT>', '<STR_LIT:w>')<EOL>k_events = len(list(event_list))<EOL>for i, master in enumerate(event_list):<EOL><INDENT>master_sfile = master[<NUM_LIT:1>]<EOL>if debug > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' % master_sfile)<EOL><DEDENT>master_event_id = master[<NUM_LIT:0>]<EOL>master_event = read_nordic(master_sfile)[<NUM_LIT:0>]<EOL>master_picks = master_event.picks<EOL>master_ori_time = master_event.origins[<NUM_LIT:0>].time<EOL>master_location = (master_event.origins[<NUM_LIT:0>].latitude,<EOL>master_event.origins[<NUM_LIT:0>].longitude,<EOL>master_event.origins[<NUM_LIT:0>].depth / <NUM_LIT>)<EOL>master_wavefiles = readwavename(master_sfile)<EOL>masterpath = glob.glob(wavbase + os.sep + master_wavefiles[<NUM_LIT:0>])<EOL>if masterpath:<EOL><INDENT>masterstream = read(masterpath[<NUM_LIT:0>])<EOL><DEDENT>if len(master_wavefiles) > <NUM_LIT:1>:<EOL><INDENT>for wavefile in master_wavefiles:<EOL><INDENT>try:<EOL><INDENT>masterstream += read(os.join(wavbase, wavefile))<EOL><DEDENT>except:<EOL><INDENT>raise IOError("<STR_LIT>")<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>for j in range(i + <NUM_LIT:1>, k_events):<EOL><INDENT>slave_sfile = event_list[j][<NUM_LIT:1>]<EOL>if debug > <NUM_LIT:2>:<EOL><INDENT>print('<STR_LIT>' % slave_sfile)<EOL><DEDENT>slave_event_id = event_list[j][<NUM_LIT:0>]<EOL>slave_wavefiles = readwavename(slave_sfile)<EOL>try:<EOL><INDENT>slavestream = read(wavbase + os.sep + slave_wavefiles[<NUM_LIT:0>])<EOL><DEDENT>except:<EOL><INDENT>raise IOError('<STR_LIT>' + slave_wavefiles[<NUM_LIT:0>] +<EOL>'<STR_LIT:U+0020>' + slave_sfile)<EOL><DEDENT>if len(slave_wavefiles) > <NUM_LIT:1>:<EOL><INDENT>for wavefile in slave_wavefiles:<EOL><INDENT>try:<EOL><INDENT>slavestream += read(wavbase + os.sep + wavefile)<EOL><DEDENT>except IOError:<EOL><INDENT>print('<STR_LIT>' %<EOL>(wavbase + os.sep + wavefile))<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>event_text = '<STR_LIT:#>' + str(master_event_id).rjust(<NUM_LIT:10>) +str(slave_event_id).rjust(<NUM_LIT:10>) + '<STR_LIT>'<EOL>event_text2 = '<STR_LIT:#>' + str(master_event_id).rjust(<NUM_LIT:10>) +str(slave_event_id).rjust(<NUM_LIT:10>) + '<STR_LIT>'<EOL>slave_event = read_nordic(slave_sfile)[<NUM_LIT:0>]<EOL>slave_picks = slave_event.picks<EOL>slave_ori_time = slave_event.origins[<NUM_LIT:0>].time<EOL>slave_location = (slave_event.origins[<NUM_LIT:0>].latitude,<EOL>slave_event.origins[<NUM_LIT:0>].longitude,<EOL>slave_event.origins[<NUM_LIT:0>].depth / <NUM_LIT>)<EOL>if dist_calc(master_location, slave_location) > max_sep:<EOL><INDENT>if debug > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' %<EOL>(dist_calc(master_location, slave_location)))<EOL><DEDENT>continue<EOL><DEDENT>links = <NUM_LIT:0><EOL>phases = <NUM_LIT:0><EOL>for pick in master_picks:<EOL><INDENT>if not hasattr(pick, '<STR_LIT>') orlen(pick.phase_hint) == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>print(pick)<EOL>continue<EOL><DEDENT>if pick.phase_hint[<NUM_LIT:0>].upper() not in ['<STR_LIT:P>', '<STR_LIT:S>']:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>print(pick)<EOL>continue<EOL><DEDENT>slave_matches = [p for p in slave_picks<EOL>if hasattr(p, '<STR_LIT>') and<EOL>p.phase_hint == pick.phase_hint and<EOL>p.waveform_id.station_code ==<EOL>pick.waveform_id.station_code]<EOL>if masterstream.select(station=pick.waveform_id.station_code,<EOL>channel='<STR_LIT:*>' +<EOL>pick.waveform_id.channel_code[-<NUM_LIT:1>]):<EOL><INDENT>mastertr = masterstream.select(station=pick.waveform_id.station_code,<EOL>channel='<STR_LIT:*>' +<EOL>pick.waveform_id.channel_code[-<NUM_LIT:1>])[<NUM_LIT:0>]<EOL><DEDENT>elif debug > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' +<EOL>pick.waveform_id.station_code + '<STR_LIT:.>' +<EOL>pick.waveform_id.channel_code)<EOL>print(pick.waveform_id.station_code +<EOL>'<STR_LIT:.>' + pick.waveform_id.channel_code +<EOL>'<STR_LIT:U+0020>' + slave_sfile + '<STR_LIT:U+0020>' + master_sfile)<EOL>break<EOL><DEDENT>for slave_pick in slave_matches:<EOL><INDENT>if slavestream.select(station=slave_pick.waveform_id.<EOL>station_code,<EOL>channel='<STR_LIT:*>' + slave_pick.waveform_id.<EOL>channel_code[-<NUM_LIT:1>]):<EOL><INDENT>slavetr = slavestream.select(station=slave_pick.waveform_id.station_code,<EOL>channel='<STR_LIT:*>' + slave_pick.waveform_id.<EOL>channel_code[-<NUM_LIT:1>])[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' +<EOL>slave_pick.waveform_id.station_code + '<STR_LIT:.>' +<EOL>slave_pick.waveform_id.channel_code)<EOL>print(pick.waveform_id.station_code +<EOL>'<STR_LIT:.>' + pick.waveform_id.channel_code +<EOL>'<STR_LIT:U+0020>' + slave_sfile + '<STR_LIT:U+0020>' + master_sfile)<EOL>break<EOL><DEDENT>try:<EOL><INDENT>correction, cc =xcorr_pick_correction(<EOL>pick.time, mastertr, slave_pick.time,<EOL>slavetr, pre_pick, extract_len - pre_pick,<EOL>shift_len, filter="<STR_LIT>",<EOL>filter_options={'<STR_LIT>': lowcut,<EOL>'<STR_LIT>': highcut},<EOL>plot=plotvar)<EOL>if abs(correction) > shift_len:<EOL><INDENT>warnings.warn('<STR_LIT>' +<EOL>'<STR_LIT>')<EOL>continue<EOL><DEDENT>correction = (pick.time - master_ori_time) -(slave_pick.time + correction - slave_ori_time)<EOL>links += <NUM_LIT:1><EOL>if cc >= cc_thresh:<EOL><INDENT>weight = cc<EOL>phases += <NUM_LIT:1><EOL>event_text += pick.waveform_id.station_code.ljust(<NUM_LIT:5>) + _cc_round(correction, <NUM_LIT:3>).rjust(<NUM_LIT:11>) + _cc_round(weight, <NUM_LIT:3>).rjust(<NUM_LIT:8>) +'<STR_LIT:U+0020>' + pick.phase_hint + '<STR_LIT:\n>'<EOL>event_text2 += pick.waveform_id.station_code.ljust(<NUM_LIT:5>) + _cc_round(correction, <NUM_LIT:3>).rjust(<NUM_LIT:11>) +_cc_round(weight * weight, <NUM_LIT:3>).rjust(<NUM_LIT:8>) +'<STR_LIT:U+0020>' + pick.phase_hint + '<STR_LIT:\n>'<EOL>if debug > <NUM_LIT:3>:<EOL><INDENT>print(event_text)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' % cc)<EOL><DEDENT>corr_list.append(cc * cc)<EOL><DEDENT>except:<EOL><INDENT>msg = "<STR_LIT>"<EOL>warnings.warn(msg)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>if links >= min_link and phases > <NUM_LIT:0>:<EOL><INDENT>f.write(event_text)<EOL>f2.write(event_text2)<EOL><DEDENT><DEDENT><DEDENT>if plotvar:<EOL><INDENT>plt.hist(corr_list, <NUM_LIT>)<EOL>plt.show()<EOL><DEDENT>f.close()<EOL>f2.close()<EOL>return<EOL>
Write a dt.cc file for hypoDD input for a given list of events.

Takes an input list of events and computes pick refinements by correlation.
Outputs two files, dt.cc and dt.cc2, each provides a different weight,
dt.cc uses weights of the cross-correlation, and dt.cc2 provides weights
as the square of the cross-correlation.

:type event_list: list
:param event_list: List of tuples of event_id (int) and sfile (String)
:type wavbase: str
:param wavbase: Path to the seisan wave directory that the wavefiles in the
                S-files are stored
:type extract_len: float
:param extract_len: Length in seconds to extract around the pick
:type pre_pick: float
:param pre_pick: Time before the pick to start the correlation window
:type shift_len: float
:param shift_len: Time to allow pick to vary
:type lowcut: float
:param lowcut: Lowcut in Hz - default=1.0
:type highcut: float
:param highcut: Highcut in Hz - default=10.0
:type max_sep: float
:param max_sep: Maximum separation between event pairs in km
:type min_link: int
:param min_link: Minimum links for an event to be paired
:type cc_thresh: float
:param cc_thresh: Threshold to include cross-correlation results.
:type plotvar: bool
:param plotvar: To show the pick-correction plots, defualts to False.
:type debug: int
:param debug: Variable debug levels from 0-5, higher=more output.

.. warning:: This is not a fast routine!

.. warning::
    In contrast to seisan's corr routine, but in accordance with the
    hypoDD manual, this outputs corrected differential time.

.. note::
    Currently we have not implemented a method for taking
    unassociated event objects and wavefiles.  As such if you have events \
    with associated wavefiles you are advised to generate Sfiles for each \
    event using the sfile_util module prior to this step.

.. note::
    There is no provision to taper waveforms within these functions, if you
    desire this functionality, you should apply the taper before calling
    this.  Note the :func:`obspy.Trace.taper` functions.