[reformat] code reformatting with PyCharm
This commit is contained in:
@@ -11,14 +11,14 @@ function conglomerate utils.
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from pylot.core.io.data import Data
|
||||
from pylot.core.io.inputs import PylotParameter
|
||||
from pylot.core.pick.picker import AICPicker, PragPicker
|
||||
from pylot.core.pick.charfuns import CharacteristicFunction
|
||||
from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf
|
||||
from pylot.core.pick.picker import AICPicker, PragPicker
|
||||
from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \
|
||||
getSNR, fmpicker, checkPonsets, wadaticheck
|
||||
from pylot.core.util.utils import getPatternLine, gen_Pool
|
||||
from pylot.core.io.data import Data
|
||||
|
||||
|
||||
def autopickevent(data, param, iplot=0, fig_dict=None):
|
||||
@@ -43,10 +43,10 @@ def autopickevent(data, param, iplot=0, fig_dict=None):
|
||||
|
||||
if not iplot:
|
||||
input_tuples.append((topick, param, apverbose))
|
||||
if iplot>0:
|
||||
if iplot > 0:
|
||||
all_onsets[station] = autopickstation(topick, param, verbose=apverbose, iplot=iplot, fig_dict=fig_dict)
|
||||
|
||||
if iplot>0:
|
||||
if iplot > 0:
|
||||
print('iPlot Flag active: NO MULTIPROCESSING possible.')
|
||||
return all_onsets
|
||||
|
||||
@@ -70,7 +70,7 @@ def autopickevent(data, param, iplot=0, fig_dict=None):
|
||||
|
||||
def call_autopickstation(input_tuple):
|
||||
wfstream, pickparam, verbose = input_tuple
|
||||
#multiprocessing not possible with interactive plotting
|
||||
# multiprocessing not possible with interactive plotting
|
||||
return autopickstation(wfstream, pickparam, verbose, iplot=0)
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
|
||||
# special parameters for P picking
|
||||
iplot = iplot
|
||||
|
||||
|
||||
algoP = pickparam.get('algoP')
|
||||
pstart = pickparam.get('pstart')
|
||||
pstop = pickparam.get('pstop')
|
||||
@@ -291,7 +291,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
'Skipping control function checkZ4S.'
|
||||
if verbose: print(msg)
|
||||
else:
|
||||
if iplot>1:
|
||||
if iplot > 1:
|
||||
if fig_dict:
|
||||
fig = fig_dict['checkZ4s']
|
||||
else:
|
||||
@@ -364,7 +364,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
mpickP, iplot, fig=fig)
|
||||
else:
|
||||
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
|
||||
mpickP, iplot)
|
||||
mpickP, iplot)
|
||||
|
||||
# get SNR
|
||||
[SNRP, SNRPdB, Pnoiselevel] = getSNR(z_copy, tsnrz, mpickP)
|
||||
@@ -392,7 +392,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
fig = None
|
||||
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig)
|
||||
else:
|
||||
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
|
||||
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
|
||||
else:
|
||||
FM = 'N'
|
||||
|
||||
@@ -567,15 +567,15 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
fig = fig_dict['el_S1pick']
|
||||
else:
|
||||
fig = None
|
||||
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot,
|
||||
fig=fig)
|
||||
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot,
|
||||
fig=fig)
|
||||
else:
|
||||
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot)
|
||||
|
||||
|
||||
h_copy[0].data = trH2_filt.data
|
||||
if iplot:
|
||||
if fig_dict:
|
||||
@@ -706,7 +706,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
ax1.plot([aicpick.getpick() - 0.5, aicpick.getpick() + 0.5],
|
||||
[-1, -1], 'r')
|
||||
ax1.plot([refPpick.getpick(), refPpick.getpick()],
|
||||
[-1.3, 1.3], 'r', linewidth=2, label='Final P Pick')
|
||||
[-1.3, 1.3], 'r', linewidth=2, label='Final P Pick')
|
||||
ax1.plot([refPpick.getpick() - 0.5, refPpick.getpick() + 0.5],
|
||||
[1.3, 1.3], 'r', linewidth=2)
|
||||
ax1.plot([refPpick.getpick() - 0.5, refPpick.getpick() + 0.5],
|
||||
@@ -714,28 +714,28 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
ax1.plot([lpickP, lpickP], [-1.1, 1.1], 'r--', label='lpp')
|
||||
ax1.plot([epickP, epickP], [-1.1, 1.1], 'r--', label='epp')
|
||||
ax1.set_title('%s, %s, P Weight=%d, SNR=%7.2f, SNR[dB]=%7.2f '
|
||||
'Polarity: %s' % (tr_filt.stats.station,
|
||||
tr_filt.stats.channel,
|
||||
Pweight,
|
||||
SNRP,
|
||||
SNRPdB,
|
||||
FM))
|
||||
'Polarity: %s' % (tr_filt.stats.station,
|
||||
tr_filt.stats.channel,
|
||||
Pweight,
|
||||
SNRP,
|
||||
SNRPdB,
|
||||
FM))
|
||||
else:
|
||||
ax1.set_title('%s, P Weight=%d, SNR=None, '
|
||||
'SNRdB=None' % (tr_filt.stats.channel, Pweight))
|
||||
'SNRdB=None' % (tr_filt.stats.channel, Pweight))
|
||||
else:
|
||||
ax1.set_title('%s, %s, P Weight=%d' % (tr_filt.stats.station,
|
||||
tr_filt.stats.channel,
|
||||
Pweight))
|
||||
tr_filt.stats.channel,
|
||||
Pweight))
|
||||
ax1.legend()
|
||||
ax1.set_yticks([])
|
||||
ax1.set_ylim([-1.5, 1.5])
|
||||
ax1.set_ylabel('Normalized Counts')
|
||||
#fig.suptitle(tr_filt.stats.starttime)
|
||||
# fig.suptitle(tr_filt.stats.starttime)
|
||||
|
||||
if len(edat[0]) > 1 and len(ndat[0]) > 1 and Sflag == 1:
|
||||
# plot horizontal traces
|
||||
ax2 = fig.add_subplot(3,1,2,sharex=ax1)
|
||||
ax2 = fig.add_subplot(3, 1, 2, sharex=ax1)
|
||||
th1data = np.arange(0,
|
||||
trH1_filt.stats.npts /
|
||||
trH1_filt.stats.sampling_rate,
|
||||
@@ -750,7 +750,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
arhcf1.getCF() / max(arhcf1.getCF()), 'b', label='CF1')
|
||||
if aicSflag == 1:
|
||||
ax2.plot(arhcf2.getTimeArray(),
|
||||
arhcf2.getCF() / max(arhcf2.getCF()), 'm', label='CF2')
|
||||
arhcf2.getCF() / max(arhcf2.getCF()), 'm', label='CF2')
|
||||
ax2.plot(
|
||||
[aicarhpick.getpick(), aicarhpick.getpick()],
|
||||
[-1, 1], 'g', label='Initial S Onset')
|
||||
@@ -782,9 +782,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
ax2.set_yticks([])
|
||||
ax2.set_ylim([-1.5, 1.5])
|
||||
ax2.set_ylabel('Normalized Counts')
|
||||
#fig.suptitle(trH1_filt.stats.starttime)
|
||||
# fig.suptitle(trH1_filt.stats.starttime)
|
||||
|
||||
ax3 = fig.add_subplot(3,1,3, sharex=ax1)
|
||||
ax3 = fig.add_subplot(3, 1, 3, sharex=ax1)
|
||||
th2data = np.arange(0,
|
||||
trH2_filt.stats.npts /
|
||||
trH2_filt.stats.sampling_rate,
|
||||
|
||||
@@ -17,7 +17,6 @@ autoregressive prediction: application ot local and regional distances, Geophys.
|
||||
:author: MAGS2 EP3 working group
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from obspy.core import Stream
|
||||
|
||||
@@ -466,7 +465,7 @@ class ARHcf(CharacteristicFunction):
|
||||
# prediction error = CF
|
||||
cf[i + lpred] = np.sqrt(np.sum(np.power(self.xpred[0][i:i + lpred] - xnp[0][i:i + lpred], 2) \
|
||||
+ np.power(self.xpred[1][i:i + lpred] - xnp[1][i:i + lpred], 2)) / (
|
||||
2 * lpred))
|
||||
2 * lpred))
|
||||
nn = np.isnan(cf)
|
||||
if len(nn) > 1:
|
||||
cf[nn] = 0
|
||||
@@ -608,7 +607,7 @@ class AR3Ccf(CharacteristicFunction):
|
||||
cf[i + lpred] = np.sqrt(np.sum(np.power(self.xpred[0][i:i + lpred] - xnp[0][i:i + lpred], 2) \
|
||||
+ np.power(self.xpred[1][i:i + lpred] - xnp[1][i:i + lpred], 2) \
|
||||
+ np.power(self.xpred[2][i:i + lpred] - xnp[2][i:i + lpred], 2)) / (
|
||||
3 * lpred))
|
||||
3 * lpred))
|
||||
nn = np.isnan(cf)
|
||||
if len(nn) > 1:
|
||||
cf[nn] = 0
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
import copy
|
||||
import operator
|
||||
import os
|
||||
import numpy as np
|
||||
import glob
|
||||
import matplotlib.pyplot as plt
|
||||
from obspy import read_events
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from obspy import read_events
|
||||
from pylot.core.io.phases import picksdict_from_picks
|
||||
from pylot.core.util.pdf import ProbabilityDensityFunction
|
||||
from pylot.core.util.utils import find_in_list
|
||||
@@ -334,7 +333,7 @@ class PDFDictionary(object):
|
||||
axarr[l].set_title(phase)
|
||||
if l is 0:
|
||||
axann = axarr[l].annotate(station, xy=(.05, .5),
|
||||
xycoords='axes fraction')
|
||||
xycoords='axes fraction')
|
||||
bbox_props = dict(boxstyle='round', facecolor='lightgrey',
|
||||
alpha=.7)
|
||||
axann.set_bbox(bbox_props)
|
||||
@@ -352,7 +351,6 @@ class PDFstatistics(object):
|
||||
Takes a path as argument.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, directory):
|
||||
"""Initiates some values needed when dealing with pdfs later"""
|
||||
self._rootdir = directory
|
||||
@@ -449,7 +447,7 @@ class PDFstatistics(object):
|
||||
else:
|
||||
raise ValueError("for call to method {0} value has to be "
|
||||
"defined but is 'None' ".format(method_options[
|
||||
property.upper()]))
|
||||
property.upper()]))
|
||||
|
||||
for pdf_dict in self:
|
||||
# create worklist
|
||||
@@ -459,7 +457,7 @@ class PDFstatistics(object):
|
||||
|
||||
return rlist
|
||||
|
||||
def writeThetaToFile(self,array,out_dir):
|
||||
def writeThetaToFile(self, array, out_dir):
|
||||
"""
|
||||
Method to write array like data to file. Useful since acquiring can take
|
||||
serious amount of time when dealing with large databases.
|
||||
@@ -471,12 +469,12 @@ class PDFstatistics(object):
|
||||
"""
|
||||
fid = open(os.path.join(out_dir), 'w')
|
||||
for val in array:
|
||||
fid.write(str(val)+'\n')
|
||||
fid.write(str(val) + '\n')
|
||||
fid.close()
|
||||
|
||||
|
||||
def main():
|
||||
root_dir ='/home/sebastianp/Codetesting/xmls/'
|
||||
root_dir = '/home/sebastianp/Codetesting/xmls/'
|
||||
Insheim = PDFstatistics(root_dir)
|
||||
Insheim.curphase = 'p'
|
||||
qdlist = Insheim.get('qdf', 0.2)
|
||||
|
||||
@@ -19,12 +19,13 @@ calculated after Diehl & Kissling (2009).
|
||||
:author: MAGS2 EP3 working group / Ludger Kueperkoch
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from pylot.core.pick.utils import getnoisewin, getsignalwin
|
||||
from pylot.core.pick.charfuns import CharacteristicFunction
|
||||
import warnings
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from pylot.core.pick.charfuns import CharacteristicFunction
|
||||
from pylot.core.pick.utils import getnoisewin, getsignalwin
|
||||
|
||||
|
||||
class AutoPicker(object):
|
||||
'''
|
||||
@@ -212,14 +213,14 @@ class AICPicker(AutoPicker):
|
||||
self.Data[0].data = self.Data[0].data * 1000000
|
||||
# get signal window
|
||||
isignal = getsignalwin(self.Tcf, self.Pick, self.TSNR[2])
|
||||
ii = min([isignal[len(isignal)-1], len(self.Tcf)])
|
||||
ii = min([isignal[len(isignal) - 1], len(self.Tcf)])
|
||||
isignal = isignal[0:ii]
|
||||
try:
|
||||
aic[isignal]
|
||||
aic[isignal]
|
||||
except IndexError as e:
|
||||
msg = "Time series out of bounds! {}".format(e)
|
||||
print(msg)
|
||||
return
|
||||
msg = "Time series out of bounds! {}".format(e)
|
||||
print(msg)
|
||||
return
|
||||
# calculate SNR from CF
|
||||
self.SNR = max(abs(aic[isignal] - np.mean(aic[isignal]))) / \
|
||||
max(abs(aic[inoise] - np.mean(aic[inoise])))
|
||||
@@ -242,7 +243,7 @@ class AICPicker(AutoPicker):
|
||||
print("Choose longer slope determination window!")
|
||||
if self.iplot > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure() #self.iplot) ### WHY? MP MP
|
||||
fig = plt.figure() # self.iplot) ### WHY? MP MP
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
@@ -271,7 +272,7 @@ class AICPicker(AutoPicker):
|
||||
|
||||
if self.iplot > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure()#self.iplot)
|
||||
fig = plt.figure() # self.iplot)
|
||||
else:
|
||||
fig = self.fig
|
||||
ax1 = fig.add_subplot(211)
|
||||
@@ -283,21 +284,25 @@ class AICPicker(AutoPicker):
|
||||
ax1.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
|
||||
ax1.set_yticks([])
|
||||
ax1.legend()
|
||||
|
||||
|
||||
if self.Pick is not None:
|
||||
ax2 = fig.add_subplot(2,1,2, sharex=ax1)
|
||||
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
|
||||
ax2.plot(self.Tcf, x, 'k', label='Data')
|
||||
ax1.axvspan(self.Tcf[inoise[0]],self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax1.axvspan(self.Tcf[isignal[0]],self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
|
||||
ax1.axvspan(self.Tcf[iislope[0]],self.Tcf[iislope[-1]], color='g', alpha=0.2, lw=0, label='Slope Window')
|
||||
|
||||
ax2.axvspan(self.Tcf[inoise[0]],self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax2.axvspan(self.Tcf[isignal[0]],self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
|
||||
ax2.axvspan(self.Tcf[iislope[0]],self.Tcf[iislope[-1]], color='g', alpha=0.2, lw=0, label='Slope Window')
|
||||
ax1.axvspan(self.Tcf[inoise[0]], self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax1.axvspan(self.Tcf[isignal[0]], self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0,
|
||||
label='Signal Window')
|
||||
ax1.axvspan(self.Tcf[iislope[0]], self.Tcf[iislope[-1]], color='g', alpha=0.2, lw=0,
|
||||
label='Slope Window')
|
||||
|
||||
ax2.axvspan(self.Tcf[inoise[0]], self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax2.axvspan(self.Tcf[isignal[0]], self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0,
|
||||
label='Signal Window')
|
||||
ax2.axvspan(self.Tcf[iislope[0]], self.Tcf[iislope[-1]], color='g', alpha=0.2, lw=0,
|
||||
label='Slope Window')
|
||||
ax2.plot(self.Tcf[iislope], datafit, 'g', linewidth=2, label='Slope')
|
||||
|
||||
|
||||
ax1.set_title('Station %s, SNR=%7.2f, Slope= %12.2f counts/s' % (self.Data[0].stats.station,
|
||||
self.SNR, self.slope))
|
||||
self.SNR, self.slope))
|
||||
ax2.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
|
||||
ax2.set_ylabel('Counts')
|
||||
ax2.set_yticks([])
|
||||
@@ -307,7 +312,7 @@ class AICPicker(AutoPicker):
|
||||
|
||||
if self.Pick == None:
|
||||
print('AICPicker: Could not find minimum, picking window too short?')
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -317,7 +322,7 @@ class PragPicker(AutoPicker):
|
||||
'''
|
||||
|
||||
def calcPick(self):
|
||||
|
||||
|
||||
if self.getpick1() is not None:
|
||||
print('PragPicker: Get most likely pick from HOS- or AR-CF using pragmatic picking algorithm ...')
|
||||
|
||||
@@ -402,7 +407,7 @@ class PragPicker(AutoPicker):
|
||||
|
||||
if self.getiplot() > 1:
|
||||
if not self.fig:
|
||||
fig = plt.figure()#self.getiplot())
|
||||
fig = plt.figure() # self.getiplot())
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from obspy.core import Stream, UTCDateTime
|
||||
@@ -41,11 +42,11 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
if verbosity == 2:
|
||||
print('earllatepicker:')
|
||||
print('earllatepicker:')
|
||||
print('nfac:', nfac)
|
||||
print('Init pick:', Pick1)
|
||||
print('TSNR (T_noise, T_gap, T_signal):', TSNR)
|
||||
|
||||
|
||||
LPick = None
|
||||
EPick = None
|
||||
PickError = None
|
||||
@@ -69,14 +70,14 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
print('x_inoise:', x[inoise])
|
||||
print('x_isignal:', x[isignal])
|
||||
print('nlevel:', nlevel)
|
||||
|
||||
|
||||
# get time where signal exceeds nlevel
|
||||
ilup, = np.where(x[isignal] > nlevel)
|
||||
ildown, = np.where(x[isignal] < -nlevel)
|
||||
if not ilup.size and not ildown.size:
|
||||
if verbosity:
|
||||
print ("earllatepicker: Signal lower than noise level!\n"
|
||||
"Skip this trace!")
|
||||
print("earllatepicker: Signal lower than noise level!\n"
|
||||
"Skip this trace!")
|
||||
return LPick, EPick, PickError
|
||||
il = min(np.min(ilup) if ilup.size else float('inf'),
|
||||
np.min(ildown) if ildown.size else float('inf'))
|
||||
@@ -118,7 +119,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
|
||||
if iplot > 1:
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
fig = plt.figure() # iplot)
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, x, 'k', label='Data')
|
||||
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
@@ -131,9 +132,9 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None):
|
||||
ax.plot([LPick, LPick], [max(x) / 2, -max(x) / 2], '--k', label='lpp')
|
||||
ax.plot([EPick, EPick], [max(x) / 2, -max(x) / 2], '--k', label='epp')
|
||||
ax.plot([Pick1 + PickError, Pick1 + PickError],
|
||||
[max(x) / 2, -max(x) / 2], 'r--', label='spe')
|
||||
[max(x) / 2, -max(x) / 2], 'r--', label='spe')
|
||||
ax.plot([Pick1 - PickError, Pick1 - PickError],
|
||||
[max(x) / 2, -max(x) / 2], 'r--')
|
||||
[max(x) / 2, -max(x) / 2], 'r--')
|
||||
ax.set_xlabel('Time [s] since %s' % X[0].stats.starttime)
|
||||
ax.set_yticks([])
|
||||
ax.set_title(
|
||||
@@ -173,7 +174,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
|
||||
FM = None
|
||||
if Pick is not None:
|
||||
print ("fmpicker: Get first motion (polarity) of onset using unfiltered seismogram...")
|
||||
print("fmpicker: Get first motion (polarity) of onset using unfiltered seismogram...")
|
||||
|
||||
xraw = Xraw[0].data
|
||||
xfilt = Xfilt[0].data
|
||||
@@ -212,15 +213,15 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
else:
|
||||
li1 = index1[0]
|
||||
if np.size(xraw[ipick[0][1]:ipick[0][li1]]) == 0:
|
||||
print ("fmpicker: Onset on unfiltered trace too emergent for first motion determination!")
|
||||
print("fmpicker: Onset on unfiltered trace too emergent for first motion determination!")
|
||||
P1 = None
|
||||
else:
|
||||
imax1 = np.argmax(abs(xraw[ipick[0][1]:ipick[0][li1]]))
|
||||
if imax1 == 0:
|
||||
imax1 = np.argmax(abs(xraw[ipick[0][1]:ipick[0][index1[1]]]))
|
||||
if imax1 == 0:
|
||||
print ("fmpicker: Zero crossings too close!")
|
||||
print ("Skip first motion determination!")
|
||||
print("fmpicker: Zero crossings too close!")
|
||||
print("Skip first motion determination!")
|
||||
return FM
|
||||
|
||||
islope1 = np.where((t >= Pick) & (t <= Pick + t[imax1]))
|
||||
@@ -254,15 +255,15 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
else:
|
||||
li2 = index2[0]
|
||||
if np.size(xfilt[ipick[0][1]:ipick[0][li2]]) == 0:
|
||||
print ("fmpicker: Onset on filtered trace too emergent for first motion determination!")
|
||||
print("fmpicker: Onset on filtered trace too emergent for first motion determination!")
|
||||
P2 = None
|
||||
else:
|
||||
imax2 = np.argmax(abs(xfilt[ipick[0][1]:ipick[0][li2]]))
|
||||
if imax2 == 0:
|
||||
imax2 = np.argmax(abs(xfilt[ipick[0][1]:ipick[0][index2[1]]]))
|
||||
if imax2 == 0:
|
||||
print ("fmpicker: Zero crossings too close!")
|
||||
print ("Skip first motion determination!")
|
||||
print("fmpicker: Zero crossings too close!")
|
||||
print("Skip first motion determination!")
|
||||
return FM
|
||||
|
||||
islope2 = np.where((t >= Pick) & (t <= Pick + t[imax2]))
|
||||
@@ -286,11 +287,11 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
elif P1[0] > 0 >= P2[0]:
|
||||
FM = '+'
|
||||
|
||||
print ("fmpicker: Found polarity %s" % FM)
|
||||
print("fmpicker: Found polarity %s" % FM)
|
||||
|
||||
if iplot > 1:
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
fig = plt.figure() # iplot)
|
||||
ax1 = fig.add_subplot(211)
|
||||
ax1.plot(t, xraw, 'k')
|
||||
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick')
|
||||
@@ -304,11 +305,11 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None):
|
||||
ax1.set_title('First-Motion Determination, %s, Unfiltered Data' % Xraw[
|
||||
0].stats.station)
|
||||
|
||||
ax2=fig.add_subplot(2,1,2, sharex=ax1)
|
||||
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
|
||||
ax2.set_title('First-Motion Determination, Filtered Data')
|
||||
ax2.plot(t, xfilt, 'k')
|
||||
ax2.plot([Pick, Pick], [max(xfilt), -max(xfilt)], 'b',
|
||||
linewidth=2)
|
||||
linewidth=2)
|
||||
if P2 is not None:
|
||||
ax2.plot(t[islope2], xfilt[islope2])
|
||||
ax2.plot(zc2, np.zeros(len(zc2)), '*g', markersize=14)
|
||||
@@ -359,7 +360,7 @@ def getSNR(X, TSNR, t1, tracenum=0):
|
||||
SNR = None
|
||||
SNRdB = None
|
||||
noiselevel = None
|
||||
|
||||
|
||||
x = X[tracenum].data
|
||||
npts = X[tracenum].stats.npts
|
||||
sr = X[tracenum].stats.sampling_rate
|
||||
@@ -372,7 +373,7 @@ def getSNR(X, TSNR, t1, tracenum=0):
|
||||
# get signal window
|
||||
isignal = getsignalwin(t, t1, TSNR[2])
|
||||
if np.size(inoise) < 1:
|
||||
print ("getSNR: Empty array inoise, check noise window!")
|
||||
print("getSNR: Empty array inoise, check noise window!")
|
||||
return SNR, SNRdB, noiselevel
|
||||
|
||||
# demean over entire waveform
|
||||
@@ -380,13 +381,13 @@ def getSNR(X, TSNR, t1, tracenum=0):
|
||||
|
||||
# calculate ratios
|
||||
noiselevel = np.sqrt(np.mean(np.square(x[inoise])))
|
||||
#signallevel = np.sqrt(np.mean(np.square(x[isignal])))
|
||||
# signallevel = np.sqrt(np.mean(np.square(x[isignal])))
|
||||
|
||||
if np.size(isignal) < 1:
|
||||
print ("getSNR: Empty array isignal, check signal window!")
|
||||
print("getSNR: Empty array isignal, check signal window!")
|
||||
return SNR, SNRdB, noiselevel
|
||||
|
||||
#noiselevel = np.abs(x[inoise]).max()
|
||||
|
||||
# noiselevel = np.abs(x[inoise]).max()
|
||||
signallevel = np.abs(x[isignal]).max()
|
||||
|
||||
SNR = signallevel / noiselevel
|
||||
@@ -418,9 +419,9 @@ def getnoisewin(t, t1, tnoise, tgap):
|
||||
inoise, = np.where((t <= max([t1 - tgap, 0])) \
|
||||
& (t >= max([t1 - tnoise - tgap, 0])))
|
||||
if np.size(inoise) < 1:
|
||||
inoise, = np.where((t>=t[0]) & (t<=t1))
|
||||
inoise, = np.where((t >= t[0]) & (t <= t1))
|
||||
if np.size(inoise) < 1:
|
||||
print ("getnoisewin: Empty array inoise, check noise window!")
|
||||
print("getnoisewin: Empty array inoise, check noise window!")
|
||||
|
||||
return inoise
|
||||
|
||||
@@ -444,7 +445,7 @@ def getsignalwin(t, t1, tsignal):
|
||||
isignal, = np.where((t <= min([t1 + tsignal, len(t)])) \
|
||||
& (t >= t1))
|
||||
if np.size(isignal) < 1:
|
||||
print ("getsignalwin: Empty array isignal, check signal window!")
|
||||
print("getsignalwin: Empty array isignal, check signal window!")
|
||||
|
||||
return isignal
|
||||
|
||||
@@ -473,7 +474,7 @@ def getResolutionWindow(snr, extent):
|
||||
>>> getResolutionWindow(2)
|
||||
2.5
|
||||
"""
|
||||
|
||||
|
||||
res_wins = {
|
||||
'regional': {'HRW': 2., 'MRW': 5., 'LRW': 10., 'VLRW': 15.},
|
||||
'local': {'HRW': 2., 'MRW': 5., 'LRW': 10., 'VLRW': 15.},
|
||||
@@ -487,11 +488,11 @@ def getResolutionWindow(snr, extent):
|
||||
time_resolution = res_wins[extent]['LRW']
|
||||
elif snr < 3.:
|
||||
time_resolution = res_wins[extent]['MRW']
|
||||
elif snr >3.:
|
||||
elif snr > 3.:
|
||||
time_resolution = res_wins[extent]['HRW']
|
||||
else:
|
||||
time_resolution = res_wins[extent]['VLRW']
|
||||
|
||||
|
||||
return time_resolution / 2
|
||||
|
||||
|
||||
@@ -573,8 +574,8 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
|
||||
# calculate vp/vs ratio before check
|
||||
vpvsr = p1[0] + 1
|
||||
print ("###############################################")
|
||||
print ("wadaticheck: Average Vp/Vs ratio before check: %f" % vpvsr)
|
||||
print("###############################################")
|
||||
print("wadaticheck: Average Vp/Vs ratio before check: %f" % vpvsr)
|
||||
|
||||
checkedPpicks = []
|
||||
checkedSpicks = []
|
||||
@@ -611,23 +612,23 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
|
||||
# calculate vp/vs ratio after check
|
||||
cvpvsr = p2[0] + 1
|
||||
print ("wadaticheck: Average Vp/Vs ratio after check: %f" % cvpvsr)
|
||||
print ("wadatacheck: Skipped %d S pick(s)" % ibad)
|
||||
print("wadaticheck: Average Vp/Vs ratio after check: %f" % cvpvsr)
|
||||
print("wadatacheck: Skipped %d S pick(s)" % ibad)
|
||||
else:
|
||||
print ("###############################################")
|
||||
print ("wadatacheck: Not enough checked S-P times available!")
|
||||
print ("Skip Wadati check!")
|
||||
print("###############################################")
|
||||
print("wadatacheck: Not enough checked S-P times available!")
|
||||
print("Skip Wadati check!")
|
||||
|
||||
checkedonsets = pickdic
|
||||
|
||||
else:
|
||||
print ("wadaticheck: Not enough S-P times available for reliable regression!")
|
||||
print ("Skip wadati check!")
|
||||
print("wadaticheck: Not enough S-P times available for reliable regression!")
|
||||
print("Skip wadati check!")
|
||||
wfitflag = 1
|
||||
|
||||
# plot results
|
||||
if iplot > 0:
|
||||
plt.figure()#iplot)
|
||||
plt.figure() # iplot)
|
||||
f1, = plt.plot(Ppicks, SPtimes, 'ro')
|
||||
if wfitflag == 0:
|
||||
f2, = plt.plot(Ppicks, wdfit, 'k')
|
||||
@@ -645,12 +646,14 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
|
||||
return checkedonsets
|
||||
|
||||
|
||||
def RMS(X):
|
||||
'''
|
||||
Function returns root mean square of a given array X
|
||||
'''
|
||||
return np.sqrt(np.sum(np.power(X, 2))/len(X))
|
||||
|
||||
return np.sqrt(np.sum(np.power(X, 2)) / len(X))
|
||||
|
||||
|
||||
def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fig=None):
|
||||
'''
|
||||
Function to detect spuriously picked noise peaks.
|
||||
@@ -684,7 +687,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
print ("Checking signal length ...")
|
||||
print("Checking signal length ...")
|
||||
|
||||
if len(X) > 1:
|
||||
# all three components available
|
||||
@@ -714,21 +717,21 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
numoverthr = len(np.where(rms[isignal] >= minsiglevel)[0])
|
||||
|
||||
if numoverthr >= minnum:
|
||||
print ("checksignallength: Signal reached required length.")
|
||||
print("checksignallength: Signal reached required length.")
|
||||
returnflag = 1
|
||||
else:
|
||||
print ("checksignallength: Signal shorter than required minimum signal length!")
|
||||
print ("Presumably picked noise peak, pick is rejected!")
|
||||
print ("(min. signal length required: %s s)" % minsiglength)
|
||||
print("checksignallength: Signal shorter than required minimum signal length!")
|
||||
print("Presumably picked noise peak, pick is rejected!")
|
||||
print("(min. signal length required: %s s)" % minsiglength)
|
||||
returnflag = 0
|
||||
|
||||
if iplot == 2:
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
fig = plt.figure() # iplot)
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, rms, 'k', label='RMS Data')
|
||||
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax.axvspan(t[isignal[0]], t[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
|
||||
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
|
||||
ax.axvspan(t[isignal[0]], t[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
|
||||
ax.plot([t[isignal[0]], t[isignal[len(isignal) - 1]]],
|
||||
[minsiglevel, minsiglevel], 'g', linewidth=2, label='Minimum Signal Level')
|
||||
ax.plot([pick, pick], [min(rms), max(rms)], 'b', linewidth=2, label='Onset')
|
||||
@@ -771,8 +774,8 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
||||
stations.append(key)
|
||||
|
||||
# apply jackknife bootstrapping on variance of P onsets
|
||||
print ("###############################################")
|
||||
print ("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
||||
print("###############################################")
|
||||
print("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
||||
[xjack, PHI_pseudo, PHI_sub] = jackknife(Ppicks, 'VAR', 1)
|
||||
# get pseudo variances smaller than average variances
|
||||
# (times safety factor), these picks passed jackknife test
|
||||
@@ -780,7 +783,7 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
||||
# these picks did not pass jackknife test
|
||||
badjk = np.where(PHI_pseudo > 5 * xjack)
|
||||
badjkstations = np.array(stations)[badjk]
|
||||
print ("checkPonsets: %d pick(s) did not pass jackknife test!" % len(badjkstations))
|
||||
print("checkPonsets: %d pick(s) did not pass jackknife test!" % len(badjkstations))
|
||||
print(badjkstations)
|
||||
|
||||
# calculate median from these picks
|
||||
@@ -793,9 +796,9 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
||||
goodstations = np.array(stations)[igood]
|
||||
badstations = np.array(stations)[ibad]
|
||||
|
||||
print ("checkPonsets: %d pick(s) deviate too much from median!" % len(ibad))
|
||||
print ("checkPonsets: Skipped %d P pick(s) out of %d" % (len(badstations) \
|
||||
+ len(badjkstations), len(stations)))
|
||||
print("checkPonsets: %d pick(s) deviate too much from median!" % len(ibad))
|
||||
print("checkPonsets: Skipped %d P pick(s) out of %d" % (len(badstations) \
|
||||
+ len(badjkstations), len(stations)))
|
||||
|
||||
goodmarker = 'goodPonsetcheck'
|
||||
badmarker = 'badPonsetcheck'
|
||||
@@ -863,8 +866,8 @@ def jackknife(X, phi, h):
|
||||
g = len(X) / h
|
||||
|
||||
if type(g) is not int:
|
||||
print ("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
||||
print ("Choose another size for subgroups!")
|
||||
print("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
||||
print("Choose another size for subgroups!")
|
||||
return PHI_jack, PHI_pseudo, PHI_sub
|
||||
else:
|
||||
# estimator of undisturbed spot check
|
||||
@@ -932,7 +935,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
print ("Check for spuriously picked S onset instead of P onset ...")
|
||||
print("Check for spuriously picked S onset instead of P onset ...")
|
||||
|
||||
returnflag = 0
|
||||
|
||||
@@ -949,7 +952,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
|
||||
# get earliest time of all 3 traces
|
||||
min_t = min(zdat[0].stats.starttime, edat[0].stats.starttime, ndat[0].stats.starttime)
|
||||
|
||||
|
||||
# generate time arrays for all 3 traces
|
||||
tz = np.arange(0, zdat[0].stats.npts / zdat[0].stats.sampling_rate,
|
||||
zdat[0].stats.delta)
|
||||
@@ -961,11 +964,11 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
zdiff = (zdat[0].stats.starttime - min_t)
|
||||
ndiff = (ndat[0].stats.starttime - min_t)
|
||||
ediff = (edat[0].stats.starttime - min_t)
|
||||
|
||||
|
||||
# get signal windows
|
||||
isignalz = getsignalwin(tz, pick-zdiff, checkwin)
|
||||
isignaln = getsignalwin(tn, pick-ndiff, checkwin)
|
||||
isignale = getsignalwin(te, pick-ediff, checkwin)
|
||||
isignalz = getsignalwin(tz, pick - zdiff, checkwin)
|
||||
isignaln = getsignalwin(tn, pick - ndiff, checkwin)
|
||||
isignale = getsignalwin(te, pick - ediff, checkwin)
|
||||
|
||||
# calculate RMS of traces
|
||||
rmsz = RMS(zdat[0].data[isignalz])
|
||||
@@ -978,9 +981,9 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
# vertical P-coda level must exceed horizontal P-coda level
|
||||
# zfac times encodalevel
|
||||
if rmsz < minsiglevel:
|
||||
print ("checkZ4S: Maybe S onset? Skip this P pick!")
|
||||
print("checkZ4S: Maybe S onset? Skip this P pick!")
|
||||
else:
|
||||
print ("checkZ4S: P onset passes checkZ4S test!")
|
||||
print("checkZ4S: P onset passes checkZ4S test!")
|
||||
returnflag = 1
|
||||
|
||||
if iplot > 1:
|
||||
@@ -996,28 +999,28 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
'N': ndiff,
|
||||
'E': ediff}
|
||||
|
||||
signal_dict = {'Z': isignalz,
|
||||
'N': isignaln,
|
||||
'E': isignale}
|
||||
signal_dict = {'Z': isignalz,
|
||||
'N': isignaln,
|
||||
'E': isignale}
|
||||
|
||||
for i, key in enumerate(['Z', 'N', 'E']):
|
||||
rms = rms_dict[key]
|
||||
trace = traces_dict[key]
|
||||
t = np.arange(diff_dict[key], trace.stats.npts / trace.stats.sampling_rate+diff_dict[key],
|
||||
trace.stats.delta)
|
||||
t = np.arange(diff_dict[key], trace.stats.npts / trace.stats.sampling_rate + diff_dict[key],
|
||||
trace.stats.delta)
|
||||
if i == 0:
|
||||
ax1 = fig.add_subplot(3, 1, i+1)
|
||||
ax1 = fig.add_subplot(3, 1, i + 1)
|
||||
ax = ax1
|
||||
ax.set_title('CheckZ4S, Station %s' % zdat[0].stats.station)
|
||||
else:
|
||||
ax = fig.add_subplot(3,1,i+1, sharex=ax1)
|
||||
ax = fig.add_subplot(3, 1, i + 1, sharex=ax1)
|
||||
ax.plot(t, abs(trace.data), color='b', label='abs')
|
||||
ax.plot(t, trace.data, color='k')
|
||||
name = str(trace.stats.channel) + ': {}'.format(rms)
|
||||
ax.plot([pick, pick+checkwin], [rms, rms], 'r', label='RMS {}'.format(name))
|
||||
ax.plot([pick, pick + checkwin], [rms, rms], 'r', label='RMS {}'.format(name))
|
||||
ax.plot([pick, pick], ax.get_ylim(), 'm', label='Pick')
|
||||
ax.set_ylabel('Normalized Counts')
|
||||
ax.axvspan(pick, pick+checkwin, color='c', alpha=0.2,
|
||||
ax.axvspan(pick, pick + checkwin, color='c', alpha=0.2,
|
||||
lw=0)
|
||||
ax.legend()
|
||||
ax.set_xlabel('Time [s] since %s' % zdat[0].stats.starttime)
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
:author: Ludger Kueperkoch / MAGS2 EP3 working group
|
||||
"""
|
||||
import pdb
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from obspy.core import Stream, UTCDateTime
|
||||
import warnings
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from obspy.core import Stream, UTCDateTime
|
||||
|
||||
def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode = False):
|
||||
|
||||
def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode=False):
|
||||
'''
|
||||
Function to derive earliest and latest possible pick after Diehl & Kissling (2009)
|
||||
as reasonable uncertainties. Latest possible pick is based on noise level,
|
||||
@@ -45,7 +45,8 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode = False):
|
||||
EPick = None
|
||||
PickError = None
|
||||
if stealthMode is False:
|
||||
print 'earllatepicker: Get earliest and latest possible pick relative to most likely pick ...'
|
||||
print
|
||||
'earllatepicker: Get earliest and latest possible pick relative to most likely pick ...'
|
||||
|
||||
x = X[0].data
|
||||
t = np.arange(0, X[0].stats.npts / X[0].stats.sampling_rate,
|
||||
@@ -61,8 +62,8 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode = False):
|
||||
ilup, = np.where(x[isignal] > nlevel)
|
||||
ildown, = np.where(x[isignal] < -nlevel)
|
||||
if not ilup.size and not ildown.size:
|
||||
print ("earllatepicker: Signal lower than noise level!")
|
||||
print ("Skip this trace!")
|
||||
print("earllatepicker: Signal lower than noise level!")
|
||||
print("Skip this trace!")
|
||||
return LPick, EPick, PickError
|
||||
il = min(np.min(ilup) if ilup.size else float('inf'),
|
||||
np.min(ildown) if ildown.size else float('inf'))
|
||||
@@ -70,20 +71,21 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode = False):
|
||||
|
||||
# get earliest possible pick
|
||||
|
||||
EPick = np.nan; count = 0
|
||||
EPick = np.nan;
|
||||
count = 0
|
||||
pis = isignal
|
||||
|
||||
# if EPick stays NaN the signal window size will be doubled
|
||||
while np.isnan(EPick):
|
||||
if count > 0:
|
||||
print("earllatepicker: Doubled signal window size %s time(s) "
|
||||
"because of NaN for earliest pick." %count)
|
||||
"because of NaN for earliest pick." % count)
|
||||
if stealthMode is False:
|
||||
print("\nearllatepicker: Doubled signal window size %s time(s) "
|
||||
"because of NaN for earliest pick." %count)
|
||||
"because of NaN for earliest pick." % count)
|
||||
isigDoubleWinStart = pis[-1] + 1
|
||||
isignalDoubleWin = np.arange(isigDoubleWinStart,
|
||||
isigDoubleWinStart + len(pis))
|
||||
isigDoubleWinStart + len(pis))
|
||||
if (isigDoubleWinStart + len(pis)) < X[0].data.size:
|
||||
pis = np.concatenate((pis, isignalDoubleWin))
|
||||
else:
|
||||
@@ -97,7 +99,6 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, stealthMode = False):
|
||||
# T0/4 is assumed as time difference between most likely and earliest possible pick!
|
||||
EPick = Pick1 - T0 / 2
|
||||
|
||||
|
||||
# get symmetric pick error as mean from earliest and latest possible pick
|
||||
# by weighting latest possible pick two times earliest possible pick
|
||||
diffti_tl = LPick - Pick1
|
||||
@@ -165,7 +166,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0):
|
||||
|
||||
FM = None
|
||||
if Pick is not None:
|
||||
print ("fmpicker: Get first motion (polarity) of onset using unfiltered seismogram...")
|
||||
print("fmpicker: Get first motion (polarity) of onset using unfiltered seismogram...")
|
||||
|
||||
xraw = Xraw[0].data
|
||||
xfilt = Xfilt[0].data
|
||||
@@ -204,15 +205,15 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0):
|
||||
else:
|
||||
li1 = index1[0]
|
||||
if np.size(xraw[ipick[0][1]:ipick[0][li1]]) == 0:
|
||||
print ("fmpicker: Onset on unfiltered trace too emergent for first motion determination!")
|
||||
print("fmpicker: Onset on unfiltered trace too emergent for first motion determination!")
|
||||
P1 = None
|
||||
else:
|
||||
imax1 = np.argmax(abs(xraw[ipick[0][1]:ipick[0][li1]]))
|
||||
if imax1 == 0:
|
||||
imax1 = np.argmax(abs(xraw[ipick[0][1]:ipick[0][index1[1]]]))
|
||||
if imax1 == 0:
|
||||
print ("fmpicker: Zero crossings too close!")
|
||||
print ("Skip first motion determination!")
|
||||
print("fmpicker: Zero crossings too close!")
|
||||
print("Skip first motion determination!")
|
||||
return FM
|
||||
|
||||
islope1 = np.where((t >= Pick) & (t <= Pick + t[imax1]))
|
||||
@@ -246,15 +247,15 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0):
|
||||
else:
|
||||
li2 = index2[0]
|
||||
if np.size(xfilt[ipick[0][1]:ipick[0][li2]]) == 0:
|
||||
print ("fmpicker: Onset on filtered trace too emergent for first motion determination!")
|
||||
print("fmpicker: Onset on filtered trace too emergent for first motion determination!")
|
||||
P2 = None
|
||||
else:
|
||||
imax2 = np.argmax(abs(xfilt[ipick[0][1]:ipick[0][li2]]))
|
||||
if imax2 == 0:
|
||||
imax2 = np.argmax(abs(xfilt[ipick[0][1]:ipick[0][index2[1]]]))
|
||||
if imax2 == 0:
|
||||
print ("fmpicker: Zero crossings too close!")
|
||||
print ("Skip first motion determination!")
|
||||
print("fmpicker: Zero crossings too close!")
|
||||
print("Skip first motion determination!")
|
||||
return FM
|
||||
|
||||
islope2 = np.where((t >= Pick) & (t <= Pick + t[imax2]))
|
||||
@@ -278,7 +279,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0):
|
||||
elif P1[0] > 0 >= P2[0]:
|
||||
FM = '+'
|
||||
|
||||
print ("fmpicker: Found polarity %s" % FM)
|
||||
print("fmpicker: Found polarity %s" % FM)
|
||||
|
||||
if iplot > 1:
|
||||
plt.figure(iplot)
|
||||
@@ -353,10 +354,10 @@ def getSNR(X, TSNR, t1):
|
||||
# get signal window
|
||||
isignal = getsignalwin(t, t1, TSNR[2])
|
||||
if np.size(inoise) < 1:
|
||||
print ("getSNR: Empty array inoise, check noise window!")
|
||||
print("getSNR: Empty array inoise, check noise window!")
|
||||
return
|
||||
elif np.size(isignal) < 1:
|
||||
print ("getSNR: Empty array isignal, check signal window!")
|
||||
print("getSNR: Empty array isignal, check signal window!")
|
||||
return
|
||||
|
||||
# demean over entire waveform
|
||||
@@ -392,9 +393,9 @@ def getnoisewin(t, t1, tnoise, tgap):
|
||||
|
||||
# get noise window
|
||||
inoise, = np.where((t <= max([t1 - tgap, 0])) \
|
||||
& (t >= max([t1 - tnoise - tgap, 0])))
|
||||
& (t >= max([t1 - tnoise - tgap, 0])))
|
||||
if np.size(inoise) < 1:
|
||||
print ("getnoisewin: Empty array inoise, check noise window!")
|
||||
print("getnoisewin: Empty array inoise, check noise window!")
|
||||
|
||||
return inoise
|
||||
|
||||
@@ -416,9 +417,9 @@ def getsignalwin(t, t1, tsignal):
|
||||
|
||||
# get signal window
|
||||
isignal, = np.where((t <= min([t1 + tsignal, len(t)])) \
|
||||
& (t >= t1))
|
||||
& (t >= t1))
|
||||
if np.size(isignal) < 1:
|
||||
print ("getsignalwin: Empty array isignal, check signal window!")
|
||||
print("getsignalwin: Empty array isignal, check signal window!")
|
||||
|
||||
return isignal
|
||||
|
||||
@@ -457,7 +458,7 @@ def getResolutionWindow(snr):
|
||||
else:
|
||||
time_resolution = res_wins['HRW']
|
||||
|
||||
return time_resolution/2
|
||||
return time_resolution / 2
|
||||
|
||||
|
||||
def wadaticheck(pickdic, dttolerance, iplot):
|
||||
@@ -485,17 +486,16 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
SPtimes = []
|
||||
for key in pickdic:
|
||||
if pickdic[key]['P']['weight'] < 4 and pickdic[key]['S']['weight'] < 4:
|
||||
# calculate S-P time
|
||||
spt = pickdic[key]['S']['mpp'] - pickdic[key]['P']['mpp']
|
||||
# add S-P time to dictionary
|
||||
pickdic[key]['SPt'] = spt
|
||||
# add P onsets and corresponding S-P times to list
|
||||
UTCPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
UTCSpick = UTCDateTime(pickdic[key]['S']['mpp'])
|
||||
Ppicks.append(UTCPpick.timestamp)
|
||||
Spicks.append(UTCSpick.timestamp)
|
||||
SPtimes.append(spt)
|
||||
|
||||
# calculate S-P time
|
||||
spt = pickdic[key]['S']['mpp'] - pickdic[key]['P']['mpp']
|
||||
# add S-P time to dictionary
|
||||
pickdic[key]['SPt'] = spt
|
||||
# add P onsets and corresponding S-P times to list
|
||||
UTCPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
UTCSpick = UTCDateTime(pickdic[key]['S']['mpp'])
|
||||
Ppicks.append(UTCPpick.timestamp)
|
||||
Spicks.append(UTCSpick.timestamp)
|
||||
SPtimes.append(spt)
|
||||
|
||||
if len(SPtimes) >= 3:
|
||||
# calculate slope
|
||||
@@ -505,8 +505,8 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
|
||||
# calculate vp/vs ratio before check
|
||||
vpvsr = p1[0] + 1
|
||||
print ("###############################################")
|
||||
print ("wadaticheck: Average Vp/Vs ratio before check: %f" % vpvsr)
|
||||
print("###############################################")
|
||||
print("wadaticheck: Average Vp/Vs ratio before check: %f" % vpvsr)
|
||||
|
||||
checkedPpicks = []
|
||||
checkedSpicks = []
|
||||
@@ -527,7 +527,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
ibad += 1
|
||||
else:
|
||||
marker = 'goodWadatiCheck'
|
||||
checkedPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
checkedPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
checkedPpicks.append(checkedPpick.timestamp)
|
||||
checkedSpick = UTCDateTime(pickdic[key]['S']['mpp'])
|
||||
checkedSpicks.append(checkedSpick.timestamp)
|
||||
@@ -543,18 +543,18 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
|
||||
# calculate vp/vs ratio after check
|
||||
cvpvsr = p2[0] + 1
|
||||
print ("wadaticheck: Average Vp/Vs ratio after check: %f" % cvpvsr)
|
||||
print ("wadatacheck: Skipped %d S pick(s)" % ibad)
|
||||
print("wadaticheck: Average Vp/Vs ratio after check: %f" % cvpvsr)
|
||||
print("wadatacheck: Skipped %d S pick(s)" % ibad)
|
||||
else:
|
||||
print ("###############################################")
|
||||
print ("wadatacheck: Not enough checked S-P times available!")
|
||||
print ("Skip Wadati check!")
|
||||
print("###############################################")
|
||||
print("wadatacheck: Not enough checked S-P times available!")
|
||||
print("Skip Wadati check!")
|
||||
|
||||
checkedonsets = pickdic
|
||||
|
||||
else:
|
||||
print ("wadaticheck: Not enough S-P times available for reliable regression!")
|
||||
print ("Skip wadati check!")
|
||||
print("wadaticheck: Not enough S-P times available for reliable regression!")
|
||||
print("Skip wadati check!")
|
||||
wfitflag = 1
|
||||
|
||||
# plot results
|
||||
@@ -614,7 +614,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
|
||||
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
print ("Checking signal length ...")
|
||||
print("Checking signal length ...")
|
||||
|
||||
if len(X) > 1:
|
||||
# all three components available
|
||||
@@ -639,25 +639,25 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
|
||||
# calculate minimum adjusted signal level
|
||||
minsiglevel = max(rms[inoise]) * nfac
|
||||
# minimum adjusted number of samples over minimum signal level
|
||||
minnum = len(isignal) * minpercent/100
|
||||
minnum = len(isignal) * minpercent / 100
|
||||
# get number of samples above minimum adjusted signal level
|
||||
numoverthr = len(np.where(rms[isignal] >= minsiglevel)[0])
|
||||
|
||||
if numoverthr >= minnum:
|
||||
print ("checksignallength: Signal reached required length.")
|
||||
print("checksignallength: Signal reached required length.")
|
||||
returnflag = 1
|
||||
else:
|
||||
print ("checksignallength: Signal shorter than required minimum signal length!")
|
||||
print ("Presumably picked noise peak, pick is rejected!")
|
||||
print ("(min. signal length required: %s s)" % minsiglength)
|
||||
print("checksignallength: Signal shorter than required minimum signal length!")
|
||||
print("Presumably picked noise peak, pick is rejected!")
|
||||
print("(min. signal length required: %s s)" % minsiglength)
|
||||
returnflag = 0
|
||||
|
||||
if iplot == 2:
|
||||
plt.figure(iplot)
|
||||
p1, = plt.plot(t,rms, 'k')
|
||||
p1, = plt.plot(t, rms, 'k')
|
||||
p2, = plt.plot(t[inoise], rms[inoise], 'c')
|
||||
p3, = plt.plot(t[isignal],rms[isignal], 'r')
|
||||
p4, = plt.plot([t[isignal[0]], t[isignal[len(isignal)-1]]],
|
||||
p3, = plt.plot(t[isignal], rms[isignal], 'r')
|
||||
p4, = plt.plot([t[isignal[0]], t[isignal[len(isignal) - 1]]],
|
||||
[minsiglevel, minsiglevel], 'g', linewidth=2)
|
||||
p5, = plt.plot([pick, pick], [min(rms), max(rms)], 'b', linewidth=2)
|
||||
plt.legend([p1, p2, p3, p4, p5], ['RMS Data', 'RMS Noise Window',
|
||||
@@ -698,22 +698,22 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
||||
stations = []
|
||||
for key in pickdic:
|
||||
if pickdic[key]['P']['weight'] < 4:
|
||||
# add P onsets to list
|
||||
UTCPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
Ppicks.append(UTCPpick.timestamp)
|
||||
stations.append(key)
|
||||
# add P onsets to list
|
||||
UTCPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
||||
Ppicks.append(UTCPpick.timestamp)
|
||||
stations.append(key)
|
||||
|
||||
# apply jackknife bootstrapping on variance of P onsets
|
||||
print ("###############################################")
|
||||
print ("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
||||
[xjack,PHI_pseudo,PHI_sub] = jackknife(Ppicks, 'VAR', 1)
|
||||
print("###############################################")
|
||||
print("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
||||
[xjack, PHI_pseudo, PHI_sub] = jackknife(Ppicks, 'VAR', 1)
|
||||
# get pseudo variances smaller than average variances
|
||||
# (times safety factor), these picks passed jackknife test
|
||||
ij = np.where(PHI_pseudo <= 2 * xjack)
|
||||
# these picks did not pass jackknife test
|
||||
badjk = np.where(PHI_pseudo > 2 * xjack)
|
||||
badjkstations = np.array(stations)[badjk]
|
||||
print ("checkPonsets: %d pick(s) did not pass jackknife test!" % len(badjkstations))
|
||||
print("checkPonsets: %d pick(s) did not pass jackknife test!" % len(badjkstations))
|
||||
|
||||
# calculate median from these picks
|
||||
pmedian = np.median(np.array(Ppicks)[ij])
|
||||
@@ -725,9 +725,9 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
||||
goodstations = np.array(stations)[igood]
|
||||
badstations = np.array(stations)[ibad]
|
||||
|
||||
print ("checkPonsets: %d pick(s) deviate too much from median!" % len(ibad))
|
||||
print ("checkPonsets: Skipped %d P pick(s) out of %d" % (len(badstations) \
|
||||
+ len(badjkstations), len(stations)))
|
||||
print("checkPonsets: %d pick(s) deviate too much from median!" % len(ibad))
|
||||
print("checkPonsets: Skipped %d P pick(s) out of %d" % (len(badstations) \
|
||||
+ len(badjkstations), len(stations)))
|
||||
|
||||
goodmarker = 'goodPonsetcheck'
|
||||
badmarker = 'badPonsetcheck'
|
||||
@@ -794,8 +794,8 @@ def jackknife(X, phi, h):
|
||||
g = len(X) / h
|
||||
|
||||
if type(g) is not int:
|
||||
print ("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
||||
print ("Choose another size for subgroups!")
|
||||
print("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
||||
print("Choose another size for subgroups!")
|
||||
return PHI_jack, PHI_pseudo, PHI_sub
|
||||
else:
|
||||
# estimator of undisturbed spot check
|
||||
@@ -863,7 +863,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
|
||||
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
|
||||
|
||||
print ("Check for spuriously picked S onset instead of P onset ...")
|
||||
print("Check for spuriously picked S onset instead of P onset ...")
|
||||
|
||||
returnflag = 0
|
||||
|
||||
@@ -876,10 +876,9 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
if len(ndat) == 0: # check for other components
|
||||
ndat = X.select(component="1")
|
||||
|
||||
|
||||
z = zdat[0].data
|
||||
tz = np.arange(0, zdat[0].stats.npts / zdat[0].stats.sampling_rate,
|
||||
zdat[0].stats.delta)
|
||||
zdat[0].stats.delta)
|
||||
|
||||
# calculate RMS trace from vertical component
|
||||
absz = np.sqrt(np.power(z, 2))
|
||||
@@ -904,16 +903,16 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
# vertical P-coda level must exceed horizontal P-coda level
|
||||
# zfac times encodalevel
|
||||
if zcodalevel < minsiglevel:
|
||||
print ("checkZ4S: Maybe S onset? Skip this P pick!")
|
||||
print("checkZ4S: Maybe S onset? Skip this P pick!")
|
||||
else:
|
||||
print ("checkZ4S: P onset passes checkZ4S test!")
|
||||
print("checkZ4S: P onset passes checkZ4S test!")
|
||||
returnflag = 1
|
||||
|
||||
if iplot > 1:
|
||||
te = np.arange(0, edat[0].stats.npts / edat[0].stats.sampling_rate,
|
||||
edat[0].stats.delta)
|
||||
edat[0].stats.delta)
|
||||
tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate,
|
||||
ndat[0].stats.delta)
|
||||
ndat[0].stats.delta)
|
||||
plt.plot(tz, z / max(z), 'k')
|
||||
plt.plot(tz[isignal], z[isignal] / max(z), 'r')
|
||||
plt.plot(te, edat[0].data / max(edat[0].data) + 1, 'k')
|
||||
@@ -955,9 +954,8 @@ def writephases(arrivals, fformat, filename):
|
||||
:type: string
|
||||
'''
|
||||
|
||||
|
||||
if fformat == 'NLLoc':
|
||||
print ("Writing phases to %s for NLLoc" % filename)
|
||||
print("Writing phases to %s for NLLoc" % filename)
|
||||
fid = open("%s" % filename, 'w')
|
||||
# write header
|
||||
fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n')
|
||||
@@ -969,34 +967,32 @@ def writephases(arrivals, fformat, filename):
|
||||
onset = arrivals[key]['P']['mpp']
|
||||
year = onset.year
|
||||
month = onset.month
|
||||
day =onset.day
|
||||
day = onset.day
|
||||
hh = onset.hour
|
||||
mm = onset.minute
|
||||
ss = onset.second
|
||||
ss = onset.second
|
||||
ms = onset.microsecond
|
||||
ss_ms = ss + (ms / 1E06)
|
||||
fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' \
|
||||
% (key, fm, year, month, day, hh, mm, ss_ms))
|
||||
% (key, fm, year, month, day, hh, mm, ss_ms))
|
||||
if arrivals[key]['S']['weight'] < 4:
|
||||
fm = '?'
|
||||
onset = arrivals[key]['S']['mpp']
|
||||
year = onset.year
|
||||
month = onset.month
|
||||
day =onset.day
|
||||
day = onset.day
|
||||
hh = onset.hour
|
||||
mm = onset.minute
|
||||
ss = onset.second
|
||||
ss = onset.second
|
||||
ms = onset.microsecond
|
||||
ss_ms = ss + (ms / 1E06)
|
||||
fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' \
|
||||
% (key, fm, year, month, day, hh, mm, ss_ms))
|
||||
% (key, fm, year, month, day, hh, mm, ss_ms))
|
||||
|
||||
fid.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
||||
Reference in New Issue
Block a user