3.2. template_gen — EQcorrscan 0.1.0 documentation

# 3.2. template_gen

Functions to generate template waveforms and information to go with them for the application of cross-correlation of seismic data for the detection of repeating events.

Code written by Calum John Chamberlain & Chet Hopp of Victoria University of Wellington, 2015.

Copyright 2015, 2016 Calum Chamberlain, Chet Hopp.

This file is part of EQcorrscan.

> EQcorrscan is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

> EQcorrscan is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

> You should have received a copy of the GNU General Public License along with EQcorrscan. If not, see <http://www.gnu.org/licenses/>.

`template_gen.` `_template_gen`(picks, st, length, swin=u'all', prepick=0.05, plot=False)

  Function to generate a cut template in the obspy Stream class from a given set of picks and data, also in an obspy stream class. Should be given pre-processed data (downsampled and filtered).

  Parameters: | picks (List of obspy.core.event.Pick) – Picks to extract data around st – Stream to etract templates from length (float) – Length of template in seconds swin (string) – P, S or all, defaults to all prepick (float) – Length in seconds to extract before the pick time default is 0.05 seconds plot (bool) – To plot the template or not, default is True
  Returns: | obspy.Stream Newly cut template.

  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.

`template_gen.` `extract_from_stack`(stack, template, length, pre_pick, pre_pad, Z_include=False, pre_processed=True, samp_rate=False, lowcut=False, highcut=False, filt_order=False)

  Function to extract a new template from a stack of previous detections. Requires the stack, the template used to make the detections for the stack, and we need to know if the stack has been pre-processed.

  Parameters: | stack (:class:obspy.Stream) – Waveform stack from detections. Can be of any length and can have delays already included, or not. template (:class:obspy.Stream) – Template used to make the detections in the stack. Will use the delays of this for the new template. length (float) – Length of new template in seconds pre_pick (float) – Extract additional data before the detection, seconds pre_pad (float) – Pad used in seconds when extracting the data, e.g. the time before the detection extracted. If using clustering.extract_detections this half the length of the extracted waveform. Z_include (bool) – If True will include any Z-channels even if there is no template for this channel, as long as there is a template for this station at a different channel. If this is False and Z channels are included in the template Z channels will be included in the new_template anyway. pre_processed (bool) – Have the data been pre-processed, if True (default) then we will only cut the data here. samp_rate (float) – If pre_processed=False then this is required, desired sampling rate in Hz, defaults to False. lowcut (float) – If pre_processed=False then this is required, lowcut in Hz, defaults to False. highcut (float) – If pre_processed=False then this is required, highcut in Hz, defaults to False filt_order (int) – If pre_processed=False then this is required, filter order, defaults to False
  Returns: | obspy.Stream Newly cut template

`template_gen.` `from_client`(catalog, client_id, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, debug=0, plot=False)

  Function to generate templates from a SeisHub database.Must be given an obspy.Catalog class and the SeisHub url as input. The function returns a list of obspy.Stream classes containting steams for each desired template.

  Parameters: | catalog (obspy.Catalog) – Catalog class containing desired template events url (string) – url of SeisHub database instance lowcut (float) – Low cut (Hz), if set to None will look in templatedefaults file lowcut – High cut (Hz), if set to None will look in templatedefaults file samp_rate (float) – New sampling rate in Hz, if set to None will look intemplate defaults file filt_order (int) – Filter level, if set to None will look intemplate defaults file length (float) – Extract length in seconds, if None will look in templatedefaults file. prepick (float) – Pre-pick time in seconds swin (str) – Either ‘all’, ‘P’ or ‘S’, to select which phases to output. debug (int) – Level of debugging output, higher=more plot (bool) – Plot templates or not.
  Returns: | obspy.Stream Newly cut template

`template_gen.` `from_contbase`(sfile, contbase_list, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, debug=0, plot=False)

  Function to read in picks from sfile then generate the template from the picks within this and the wavefiles from the continous database of day-long files. Included is a section to sanity check that the files are daylong and that they start at the start of the day. You should ensure this is the case otherwise this may alter your data if your data are daylong but the headers are incorrectly set.

  Parameters: | sfile (string) – sfilename must be the path to a seisan nordic type s-file containing waveform and pick information, all other arguments can be numbers save for swin which must be either P, S or all (case-sensitive). contbase_list (List of tuple of string) – List of tuples of the form [‘path’, ‘type’, ‘network’]. Where path is the path to the continuous database, type is the directory structure, which can be either Yyyyy/Rjjj.01, which is the standard IRIS Year, julian day structure, or, yyyymmdd which is a single directory for every day. lowcut (float) – Low cut (Hz), if set to None will look in template defaults file lowcut – High cut (Hz), if set to None will look in template defaults file samp_rate (float) – New sampling rate in Hz, if set to None will look in template defaults file filt_order (int) – Filter level, if set to None will look in template defaults file length (float) – Extract length in seconds, if None will look in template defaults file. prepick (float) – Pre-pick time in seconds swin (str) – Either ‘all’, ‘P’ or ‘S’, to select which phases to output. debug (int) – Level of debugging output, higher=more plot (bool) – Turns template plotting on or off.
  Returns: | obspy.Stream Newly cut template

`template_gen.` `from_quakeml`(quakeml, st, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, debug=0, plot=False)

  Function to generate a template from a local quakeml file and an obspy.Stream object.

  Parameters: | quakeml (string) – QuakeML file containing pick information, can contain multiple events. st (class: obspy.Stream) – Stream containing waveform data for template (hopefully) lowcut (float) – Low cut (Hz), if set to None will look in template defaults file lowcut – High cut (Hz), if set to None will look in template defaults file samp_rate (float) – New sampling rate in Hz, if set to None will look in template defaults file filt_order (int) – Filter level, if set to None will look in template defaults file length (float) – Extract length in seconds, if None will look in template defaults file. prepick (float) – Pre-pick time in seconds swin (str) – Either ‘all’, ‘P’ or ‘S’, to select which phases to output. debug (int) – Level of debugging output, higher=more plot (bool) – Display template plots or not
  Returns: | list of obspy.Stream Newly cut templates

`template_gen.` `from_seishub`(catalog, url, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, debug=0, plot=False)

  Function to generate templates from a SeisHub database.Must be given an obspy.Catalog class and the SeisHub url as input. The function returns a list of obspy.Stream classes containting steams for each desired template.

  Parameters: | catalog (obspy.Catalog) – Catalog class containing desired template events url (string) – url of SeisHub database instance lowcut (float) – Low cut (Hz), if set to None will look in template defaults file lowcut – High cut (Hz), if set to None will look in template defaults file samp_rate (float) – New sampling rate in Hz, if set to None will look in template defaults file filt_order (int) – Filter level, if set to None will look in template defaults file length (float) – Extract length in seconds, if None will look in template defaults file. prepick (float) – Pre-pick time in seconds swin (str) – Either ‘all’, ‘P’ or ‘S’, to select which phases to output. debug (int) – Level of debugging output, higher=more plot (bool) – Plot templates or not.
  Returns: | obspy.Stream Newly cut template

`template_gen.` `from_sfile`(sfile, lowcut, highcut, samp_rate, filt_order, length, swin, debug=0, plot=False)

  Function to read in picks from sfile then generate the template from the picks within this and the wavefile found in the pick file.

  Parameters: | sfile (string) – sfilename must be the path to a seisan nordic type s-file containing waveform and pick information. lowcut (float) – Low cut (Hz), if set to None will look in template defaults file highcut (float) – High cut (Hz), if set to None will look in template defaults file samp_rate (float) – New sampling rate in Hz, if set to None will look in template defaults file filt_order (int) – Filter level, if set to None will look in template defaults file swin (str) – Either ‘all’, ‘P’ or ‘S’, to select which phases to output. length (float) – Extract length in seconds, if None will look in template defaults file. debug (int) – Debug level, higher number=more output. plot (bool) – Turns template plotting on or off.
  Returns: | obspy.Stream Newly cut template