4.5. mag_calc — EQcorrscan 0.1.0 documentation

# 4.5. mag_calc

Functions to simulate Wood Anderson traces, pick maximum peak-to-peak amplitudes write these amplitudes and periods to SEISAN s-files and to calculate magnitudes from this and the informaiton within SEISAN s-files.

Written as part of the EQcorrscan package by Calum Chamberlain - first written to impliment magnitudes for the 2015 Wanaka aftershock sequence, written up by Warren-Smith [2014/15].

Copyright 2015 Calum Chamberlain

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/>.

`mag_calc.` `Amp_pick_sfile`(sfile, datapath, respdir, chans=[u'Z'], var_wintype=True, winlen=0.9, pre_pick=0.2, pre_filt=True, lowcut=1.0, highcut=20.0, corners=4)

  Function to read information from a SEISAN s-file, load the data and the picks, cut the data for the channels given around the S-window, simulate a Wood Anderson seismometer, then pick the maximum peak-to-trough amplitude.

  Output will be put into a mag_calc.out file which will be in full S-file format and can be copied to a REA database.

  Parameters: | datapath (string) – Path to the waveform files - usually the path to the WAV directory respdir (string) – Path to the response information directory chans (List of strings) – List of the channels to pick on, defaults to [‘Z’] - should just be the orientations, e.g. Z,1,2,N,E var_wintype (bool) – If True, the winlen will be multiplied by the P-S time if both P and S picks are available, otherwise it will be multiplied by the hypocentral distance*0.34 - dervided using a p-s ratio of 1.68 and S-velocity of 1.5km/s to give a large window, defaults to True winlen (float) – Length of window, see above parameter, if var_wintype is False then this will be in seconds, otherwise it is the multiplier to the p-s time, defaults to 0.5. pre_pick (float) – Time before the s-pick to start the cut window, defaults to 0.2 pre_filt (bool) – To apply a pre-filter or not, defaults to True lowcut (float) – Lowcut in Hz for the pre-filter, defaults to 1.0 highcut (float) – Highcut in Hz for the pre-filter, defaults to 20.0 corners (int) – Number of corners to use in the pre-filter

`mag_calc.` `SVD_moments`(U, s, V, stachans, event_list, n_SVs=4)

  Function to convert basis vectors calculated by singular value decomposition (see the SVD functions in clustering) into relative magnitudes.

  Parameters: | U (List of np.ndarray) – List of the input basis vectors from the SVD, one array for each channel used. s (List of nd.array) – List of the singular values, one array for each channel V (List of np.ndarry) – List of output basis vectors from SVD, one array per channel. stachans (List of string) – List of station.channel input event_list (List of list) – List of events for which you have data, such that event_list[i] corresponds to stachans[i], U[i] etc. and event_list[i][j] corresponds to event j in U[i]

  type n_SVs: int :param n_SVs: Number of singular values to use, defaults to 4.

  Returns: | M, np.array of relative moments

`mag_calc.` `_GSE2_PAZ_read`(GSEfile)

  Function to read the instrument response information from a GSE Poles and Zeros file as generated by the SEISAN program RESP.

  Format must be CAL2, not coded for any other format at the moment, contact the authors to add others in.

  Parameters: | GSEfile (string) – Path to GSE file
  Returns: | Dict of poles, zeros, gain and sensitivity

`mag_calc.` `_find_resp`(station, channel, network, time, delta, directory)

  Helper function to find the response information for a given station and channel at a given time and return a dictionary of poles and zeros, gain and sensitivity.

  Parameters: | station (str) – Station name (as in the response files) channel (str) – Channel name (as in the response files) network (str) – Network to scan for, can be a wildcard time (datetime.datetime) – Date-time to look for repsonse information delta (float) – Sample interval in seconds directory (str) – Directory to scan for response information
  Returns: | dict, response information

`mag_calc.` `_max_p2t`(data, delta)

  Function to find the maximum peak-to-trough amplitude and period of this amplitude. Originally designed to be used to calculate magnitudes (by taking half of the peak-to-trough amplitude as the peak amplitude).

  Parameters: | data (ndarray) – waveform trace to find the peak-to-trough in. delta (float) – Sampling interval in seconds
  Returns: | tuple of (amplitude, period, time) with amplitude in the same scale as given in the input data, and period in seconds, and time in seconds from the start of the data window.

`mag_calc.` `_pairwise`(iterable)

  Wrapper on itertools for SVD_magnitude.

`mag_calc.` `_sim_WA`(trace, PAZ, seedresp, water_level)

  Function to remove the insturment response from a trace and return a de-meaned, de-trended, Wood Anderson simulated trace in it’s place.

  Works in-place on data and will destroy your original data, copy the trace before giving it to this function!

  Parameters: | trace (obspy.Trace) – A standard obspy trace, generally should be given without pre-filtering, if given with pre-filtering for use with amplitude determiniation for magnitudes you will need to worry about how you cope with the response of this filter yourself. PAZ (dict) – Dictionary containing lists of poles and zeros, the gain and the sensitivity. water_level (int) – Water level for the simulation.
  Returns: | obspy.Trace

`mag_calc.` `dist_calc`(loc1, loc2)

  Function to calcualte the distance in km between two points, uses the flat Earth approximation.

  Parameters: | loc1 (tuple) – Tuple of lat, lon, depth (in decimal degrees and km) loc2 (tuple) – Tuple of lat, lon, depth (in decimal degrees and km)
  Returns: | float, Distance between points.

`mag_calc.` `pick_db`(indir, outdir, calpath, startdate, enddate, wavepath=None)

  Wrapper to loop through a SEISAN database and make a lot of magnitude picks.

  Parameters: | indir (str) – Path to the seisan REA directory (not including yyyy/mm) outdir (str) – Path to output seisan REA directory (not including yyyy/mm) calpath (str) – Path to the directory containing the response files startdate (datetime.datetime) – Date to start looking for S-files enddate (datetime.datetime) – Date to stop looking for S-files wavepath (str) – Path to the seisan WAV directory (not including yyyy/mm)