5.4.1.9. eqcorrscan.utils.clustering.extract_detections

eqcorrscan.utils.clustering.extract_detections(detections, templates, archive, arc_type, extract_len=90.0, outdir=None, extract_Z=True, additional_stations=[])[source]

Extract waveforms associated with detections

Takes a list of detections for the template, template. Waveforms will be returned as a list of obspy.Streams containing segments of extract_len. They will also be saved if outdir is set. The default is unset. The default extract_len is 90 seconds per channel.

Parameters:
  • detections (list) List of eqcorrscan.core.match_filter.DETECTION objects.
  • templates (list) A list of tuples of the template name and the template Stream used to detect detections.
  • archive (str) Either name of archive or path to continuous data, see eqcorrscan.utils.archive_read for details
  • arc_type (str) Type of archive, either seishub, FDSN, day_vols
  • extract_len (float) Length to extract around the detection (will be equally cut around the detection time) in seconds. Default is 90.0.
  • outdir (str) Default is None, with None set, no files will be saved, if set each detection will be saved into this directory with files named according to the detection time, NOT than the waveform start time. Detections will be saved into template subdirectories.
  • extract_Z (bool) Set to True to also extract Z channels for detections delays will be the same as horizontal channels, only applies if only horizontal channels were used in the template.
  • additional_stations (list) List of tuples of (station, channel, network) to also extract data for using an average delay.
Returns:

list of streams

Return type:

obspy.core.stream.Stream

>>> from eqcorrscan.utils.clustering import extract_detections
>>> from eqcorrscan.core.match_filter import DETECTION
>>> from obspy import read, UTCDateTime
>>> import os
>>> # Use some dummy detections, you would use real one
>>> detections = [DETECTION('temp1', UTCDateTime(2012, 3, 26, 9, 15), 2,
...                         ['WHYM', 'EORO'], 2, 1.2, 'corr'),
...               DETECTION('temp2',UTCDateTime(2012, 3, 26, 18, 5), 2,
...                         ['WHYM', 'EORO'], 2, 1.2, 'corr')]
>>> path_to_templates = os.path.join('eqcorrscan', 'tests', 'test_data')
>>> archive = os.path.join(path_to_templates, 'day_vols')
>>> template_files = [os.path.join(path_to_templates, 'temp1.ms'),
...                   os.path.join(path_to_templates, 'temp2.ms')]
>>> templates = [('temp' + str(i), read(filename))
...              for i, filename in enumerate(template_files)]
>>> extracted = extract_detections(detections, templates,
...                                archive=archive, arc_type='day_vols')
Working on detections for day: 2012-03-26T00:00:00.000000Z
Cutting for detections at: 2012/03/26 09:15:00
Cutting for detections at: 2012/03/26 18:05:00
>>> print(extracted[0].sort())
2 Trace(s) in Stream:
AF.EORO..SHZ | 2012-03-26T09:14:15.000000Z - 2012-03-26T09:15:45.000000Z | 1.0 Hz, 91 samples
AF.WHYM..SHZ | 2012-03-26T09:14:15.000000Z - 2012-03-26T09:15:45.000000Z | 1.0 Hz, 91 samples
>>> print(extracted[1].sort())
2 Trace(s) in Stream:
AF.EORO..SHZ | 2012-03-26T18:04:15.000000Z - 2012-03-26T18:05:45.000000Z | 1.0 Hz, 91 samples
AF.WHYM..SHZ | 2012-03-26T18:04:15.000000Z - 2012-03-26T18:05:45.000000Z | 1.0 Hz, 91 samples