4.6.5.1.1. eqcorrscan.core.template_gen.template_gen

eqcorrscan.core.template_gen.template_gen(method, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, process_len=86400, all_horiz=False, delayed=True, plot=False, debug=0, return_event=False, min_snr=None, parallel=False, **kwargs)[source]

Generate processed and cut waveforms for use as templates.

Parameters:
  • method (str) – Template generation method, must be one of (‘from_client’, ‘from_seishub’, ‘from_sac’, ‘from_meta_file’). - Each method requires associated arguments, see note below.
  • lowcut (float) – Low cut (Hz), if set to None will not apply a lowcut.
  • highcut (float) – High cut (Hz), if set to None will not apply a highcut.
  • samp_rate (float) – New sampling rate in Hz.
  • filt_order (int) – Filter level (number of corners).
  • length (float) – Extract length in seconds.
  • prepick (float) – Pre-pick time in seconds
  • swin (str) – P, S, P_all, S_all or all, defaults to all: see note in eqcorrscan.core.template_gen.template_gen()
  • process_len (int) – Length of data in seconds to download and process.
  • all_horiz (bool) – To use both horizontal channels even if there is only a pick on one of them. Defaults to False.
  • delayed (bool) – If True, each channel will begin relative to it’s own pick-time, if set to False, each channel will begin at the same time.
  • plot (bool) – Plot templates or not.
  • debug (int) – Level of debugging output, higher=more
  • return_event (bool) – Whether to return the event and process length or not.
  • min_snr (float) – Minimum signal-to-noise ratio for a channel to be included in the template, where signal-to-noise ratio is calculated as the ratio of the maximum amplitude in the template window to the rms amplitude in the whole window given.
  • parallel (bool) – Whether to process data in parallel or not.
Returns:

List of obspy.core.stream.Stream Templates

Return type:

list

Note

Method specific arguments:

  • from_client requires:
    param str client_id:
     string passable by obspy to generate Client
    param obspy.core.event.Catalog catalog:
     Catalog of events to generate template for
    param float data_pad:
     Pad length for data-downloads in seconds
  • from_seishub requires:
    param str url:url to seishub database
    param obspy.core.event.Catalog catalog:
     Catalog of events to generate template for
    param float data_pad:
     Pad length for data-downloads in seconds
  • from_sac requires:
    param list sac_files:
     osbpy.core.stream.Stream of sac waveforms, or list of paths to sac waveforms.
  • from_meta_file requires:
    param str meta_file:
     Path to obspy-readable event file.
    param obspy.core.stream.Stream st:
     Stream containing waveform data for template. Note that this should be the same length of stream as you will use for the continuous detection, e.g. if you detect in day-long files, give this a day-long file!
    param bool process:
     Whether to process the data or not, defaults to True.

Note

process_len should be set to the same length as used when computing detections using match_filter.match_filter, e.g. if you read in day-long data for match_filter, process_len should be 86400.

Example

>>> from obspy.clients.fdsn import Client
>>> from eqcorrscan.core.template_gen import template_gen
>>> client = Client('NCEDC')
>>> catalog = client.get_events(eventid='72572665', includearrivals=True)
>>> # We are only taking two picks for this example to speed up the
>>> # example, note that you don't have to!
>>> catalog[0].picks = catalog[0].picks[0:2]
>>> templates = template_gen(
...    method='from_client', catalog=catalog, client_id='NCEDC',
...    lowcut=2.0, highcut=9.0, samp_rate=20.0, filt_order=4, length=3.0,
...    prepick=0.15, swin='all', process_len=300, all_horiz=True)
>>> templates[0].plot(equal_scale=False, size=(800,600)) 
../../_images/template_gen.from_client.png

Example

>>> from obspy import read
>>> from eqcorrscan.core.template_gen import template_gen
>>> st = read('eqcorrscan/tests/test_data/WAV/TEST_/' +
...           '2013-09-01-0410-35.DFDPC_024_00')
>>> quakeml = 'eqcorrscan/tests/test_data/20130901T041115.xml'
>>> templates = template_gen(
...    method='from_meta_file', meta_file=quakeml, st=st, lowcut=2.0,
...    highcut=9.0, samp_rate=20.0, filt_order=3, length=2, prepick=0.1,
...    swin='S', all_horiz=True)
>>> print(len(templates[0]))
10
>>> templates = template_gen(
...    method='from_meta_file', meta_file=quakeml, st=st, lowcut=2.0,
...    highcut=9.0, samp_rate=20.0, filt_order=3, length=2, prepick=0.1,
...    swin='S_all', all_horiz=True)
>>> print(len(templates[0]))
15

Example

>>> from eqcorrscan.core.template_gen import template_gen
>>> import glob
>>> # Get all the SAC-files associated with one event.
>>> sac_files = glob.glob('eqcorrscan/tests/test_data/SAC/2014p611252/*')
>>> templates = template_gen(
...    method='from_sac', sac_files=sac_files, lowcut=2.0, highcut=10.0,
...    samp_rate=25.0, filt_order=4, length=2.0, swin='all', prepick=0.1,
...    all_horiz=True)
>>> print(templates[0][0].stats.sampling_rate)
25.0
>>> print(len(templates[0]))
15