Merge branch 'develop' of 134.147.164.251:/data/git/pylot into develop

This commit is contained in:
2015-06-24 14:24:20 +02:00
5 changed files with 137 additions and 27 deletions

View File

@@ -74,6 +74,10 @@ def run_autopicking(wfstream, pickparam):
minFMSNR = pickparam.getParam('minFMSNR')
fmpickwin = pickparam.getParam('fmpickwin')
minfmweight = pickparam.getParam('minfmweight')
# parameters for checking signal length
minsiglength = pickparam.getParam('minsiglength')
minpercent = pickparam.getParam('minpercent')
nfacsl = pickparam.getParam('noisefactor')
# initialize output
Pweight = 4 # weight for P onset
@@ -94,6 +98,7 @@ def run_autopicking(wfstream, pickparam):
aicSflag = 0
aicPflag = 0
Pflag = 0
Sflag = 0
# split components
@@ -152,9 +157,15 @@ def run_autopicking(wfstream, pickparam):
# of class AutoPicking
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP)
##############################################################
# check signal length to detect spuriously picked noise peaks
z_copy[0].data = tr_filt.data
Pflag = checksignallength(z_copy, aicpick.getpick(), tsnrz, minsiglength, \
nfacsl, minpercent, iplot)
##############################################################
# go on with processing if AIC onset passes quality control
if (aicpick.getSlope() >= minAICPslope and
aicpick.getSNR() >= minAICPSNR):
aicpick.getSNR() >= minAICPSNR and
Pflag == 1):
aicPflag = 1
print 'AIC P-pick passes quality control: Slope: %f, SNR: %f' % \
(aicpick.getSlope(), aicpick.getSNR())
@@ -190,7 +201,7 @@ def run_autopicking(wfstream, pickparam):
mpickP = refPpick.getpick()
#############################################################
if mpickP is not None:
# quality assessment
# quality assessment
# get earliest and latest possible pick and symmetrized uncertainty
[lpickP, epickP, Perror] = earllatepicker(z_copy, nfacP, tsnrz, mpickP, iplot)
@@ -227,8 +238,8 @@ def run_autopicking(wfstream, pickparam):
Sflag = 0
else:
print 'run_autopicking: No vertical component data available, ' \
'skipping station!'
print 'run_autopicking: No vertical component data availabler!, ' \
'Skip station!'
if edat is not None and ndat is not None and len(edat) > 0 and len(
ndat) > 0 and Pweight < 4:

View File

@@ -9,6 +9,7 @@
"""
import numpy as np
import scipy as sc
import matplotlib.pyplot as plt
from obspy.core import Stream, UTCDateTime
import warnings
@@ -47,14 +48,11 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None):
x = X[0].data
t = np.arange(0, X[0].stats.npts / X[0].stats.sampling_rate,
X[0].stats.delta)
# get latest possible pick
# get noise window
inoise = getnoisewin(t, Pick1, TSNR[0], TSNR[1])
# get signal window
isignal = getsignalwin(t, Pick1, TSNR[2])
# remove mean
meanwin = np.hstack((inoise, isignal))
x = x - np.mean(x[meanwin])
x = x - np.mean(x[inoise])
# calculate noise level
nlevel = np.sqrt(np.mean(np.square(x[inoise]))) * nfac
# get time where signal exceeds nlevel
@@ -337,7 +335,7 @@ def getSNR(X, TSNR, t1):
return
# demean over entire snr window
x -= x[inoise[0]:isignal[-1]].mean()
x = x - np.mean(x[np.hstack([inoise, isignal])])
# calculate ratios
noiselevel = np.sqrt(np.mean(np.square(x[inoise])))
@@ -514,3 +512,88 @@ def wadaticheck(pickdic, dttolerance, iplot):
plt.close(iplot)
return checkedonsets
def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
'''
Function to detect spuriously picked noise peaks.
Uses envelope to determine, how many samples [per cent] after
P onset are below certain threshold, calculated from noise
level times noise factor.
: param: X, time series (seismogram)
: type: `~obspy.core.stream.Stream`
: param: pick, initial (AIC) P onset time
: type: float
: param: TSNR, length of time windows around initial pick [s]
: type: tuple (T_noise, T_gap, T_signal)
: param: minsiglength, minium required signal length [s] to
declare pick as P onset
: type: float
: param: nfac, noise factor (nfac * noise level = threshold)
: type: float
: param: minpercent, minimum required percentage of samples
above calculated threshold
: type: float
: param: iplot, if iplot > 1, results are shown in figure
: type: int
'''
assert isinstance(X, Stream), "%s is not a stream object" % str(X)
print 'Checking signal length ...'
x = X[0].data
t = np.arange(0, X[0].stats.npts / X[0].stats.sampling_rate,
X[0].stats.delta)
# generate envelope function from Hilbert transform
y = np.imag(sc.signal.hilbert(x))
e = np.sqrt(np.power(x, 2) + np.power(y, 2))
# get noise window
inoise = getnoisewin(t, pick, TSNR[0], TSNR[1])
# get signal window
isignal = getsignalwin(t, pick, TSNR[2])
# calculate minimum adjusted signal level
minsiglevel = max(e[inoise]) * nfac
# minimum adjusted number of samples over minimum signal level
minnum = len(isignal) * minpercent/100
# get number of samples above minimum adjusted signal level
numoverthr = len(np.where(e[isignal] >= minsiglevel)[0])
if numoverthr >= minnum:
print 'checksignallength: Signal reached required length.'
returnflag = 1
else:
print 'checksignallength: Signal shorter than required minimum signal length!'
print 'Presumably picked picked noise peak, pick is rejected!'
returnflag = 0
if iplot == 2:
plt.figure(iplot)
p1, = plt.plot(t,x, 'k')
p2, = plt.plot(t[inoise], e[inoise])
p3, = plt.plot(t[isignal],e[isignal], 'r')
p4, = plt.plot([t[isignal[0]], t[isignal[len(isignal)-1]]], \
[minsiglevel, minsiglevel], 'g')
p5, = plt.plot([pick, pick], [min(x), max(x)], 'c')
plt.legend([p1, p2, p3, p4, p5], ['Data', 'Envelope Noise Window', \
'Envelope Signal Window', 'Minimum Signal Level', \
'Onset'], loc='best')
plt.xlabel('Time [s] since %s' % X[0].stats.starttime)
plt.ylabel('Counts')
plt.title('Check for Signal Length, Station %s' % X[0].stats.station)
plt.yticks([])
plt.show()
raw_input()
plt.close(iplot)
return returnflag