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=['Z'], var_wintype=True, winlen=0.9, pre_pick=0.2, pre_filt=True, lowcut=1.0, highcut=20.0, corners=4)[source]

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)[source]

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)[source]

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 author to add others in.

Parameters:GSEfile (Str) – Path to GSE file
Returns:Dict of poles, zeros, gain and sensitivity
mag_calc._find_resp(station, channel, network, time, delta, directory)[source]

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 (String) – Station name (as in the response files)
  • channel (String) – Channel name (as in the response files)
  • network (String) – 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 (String) – Directory to scan for response information
Returns:

Dictionary

mag_calc._max_p2t(data, delta)[source]

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)[source]

Wrapper on itertools for SVD_magnitude

mag_calc._sim_WA(trace, PAZ, seedresp, water_level)[source]

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)[source]

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)