eqcorrscan.core.template_gen.template_gen¶
-
eqcorrscan.core.template_gen.
template_gen
(method, lowcut, highcut, samp_rate, filt_order, length, prepick, swin='all', process_len=86400, all_horiz=False, delayed=True, plot=False, plotdir=None, return_event=False, min_snr=None, parallel=False, num_cores=False, save_progress=False, skip_short_chans=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) – Length of template waveform 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.
plotdir (str) – The path to save plots to. If plotdir=None (default) then the figure will be shown on screen.
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.
num_cores (int) – Number of cores to try and use, if False and parallel=True, will use either all your cores, or as many traces as in the data (whichever is smaller).
save_progress (bool) – Whether to save the resulting templates at every data step or not. Useful for long-running processes.
skip_short_chans (bool) – Whether to ignore channels that have insufficient length data or not. Useful when the quality of data is not known, e.g. when downloading old, possibly triggered data from a datacentre
- Returns
List of
obspy.core.stream.Stream
Templates- Return type
list
Note
By convention templates are generated with P-phases on the vertical channel and S-phases on the horizontal channels, normal seismograph naming conventions are assumed, where Z denotes vertical and N, E, R, T, 1 and 2 denote horizontal channels, either oriented or not. To this end we will only use Z channels if they have a P-pick, and will use one or other horizontal channels only if there is an S-pick on it.
Warning
If there is no phase_hint included in picks, and swin=all, all channels with picks will be used.
Note
If swin=all, then all picks will be used, not just phase-picks (e.g. it will use amplitude picks). If you do not want this then we suggest that you remove any picks you do not want to use in your templates before using the event.
Note
Method specific arguments:
- from_client requires:
- param str client_id
string passable by obspy to generate Client, or any object with a get_waveforms method, including a Client instance.
- 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.
Note
See eqcorrscan.utils.sac_util.sactoevent for details on how pick information is collected.
- from_meta_file requires:
- param str meta_file
Path to obspy-readable event file, or an obspy Catalog
- 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))
Example
>>> from obspy import read >>> from eqcorrscan.core.template_gen import template_gen >>> # Get the path to the test data >>> import eqcorrscan >>> import os >>> TEST_PATH = os.path.dirname(eqcorrscan.__file__) + '/tests/test_data' >>> st = read(TEST_PATH + '/WAV/TEST_/' + ... '2013-09-01-0410-35.DFDPC_024_00') >>> quakeml = TEST_PATH + '/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(TEST_PATH + '/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