clean-up to meet coding conventions

This commit is contained in:
Sebastian Wehling-Benatelli 2015-06-29 16:14:11 +02:00
parent a46fb88282
commit 0fcd6fab9d

View File

@ -14,6 +14,8 @@ import matplotlib.pyplot as plt
from obspy.core import Stream, UTCDateTime
import warnings
import pdb
def earllatepicker(X, nfac, TSNR, Pick1, iplot=None):
'''
Function to derive earliest and latest possible pick after Diehl & Kissling (2009)
@ -432,7 +434,7 @@ def getResolutionWindow(snr):
else:
time_resolution = res_wins['HRW']
return time_resolution/2
return time_resolution / 2
def wadaticheck(pickdic, dttolerance, iplot):
@ -471,7 +473,6 @@ def wadaticheck(pickdic, dttolerance, iplot):
Spicks.append(UTCSpick.timestamp)
SPtimes.append(spt)
if len(SPtimes) >= 3:
# calculate slope
p1 = np.polyfit(Ppicks, SPtimes, 1)
@ -503,7 +504,8 @@ def wadaticheck(pickdic, dttolerance, iplot):
checkedPpicks.append(checkedPpick.timestamp)
checkedSpick = UTCDateTime(pickdic[key]['S']['mpp'])
checkedSpicks.append(checkedSpick.timestamp)
checkedSPtime = pickdic[key]['S']['mpp'] - pickdic[key]['P']['mpp']
checkedSPtime = pickdic[key]['S']['mpp'] - \
pickdic[key]['P']['mpp']
checkedSPtimes.append(checkedSPtime)
pickdic[key]['S']['marked'] = marker
@ -526,7 +528,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
print 'wadaticheck: Not enough S-P times available for reliable regression!'
print 'Skip wadati check!'
wfitflag = 1
iplot=2
iplot = 2
# plot results
if iplot > 1:
plt.figure(iplot)
@ -538,7 +540,8 @@ def wadaticheck(pickdic, dttolerance, iplot):
plt.title('Wadati-Diagram, %d S-P Times, Vp/Vs(raw)=%5.2f,' \
'Vp/Vs(checked)=%5.2f' % (len(SPtimes), vpvsr, cvpvsr))
plt.legend([f1, f2, f3, f4], ['Skipped S-Picks', 'Wadati 1', \
'Reliable S-Picks', 'Wadati 2'], loc='best')
'Reliable S-Picks', 'Wadati 2'],
loc='best')
else:
plt.title('Wadati-Diagram, %d S-P Times' % len(SPtimes))
@ -600,7 +603,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
# calculate minimum adjusted signal level
minsiglevel = max(e[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(e[isignal] >= minsiglevel)[0])
@ -614,16 +617,17 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
if iplot == 2:
plt.figure(iplot)
p1, = plt.plot(t,x, 'k')
p1, = plt.plot(t, x, 'k')
p2, = plt.plot(t[inoise], e[inoise], 'c')
p3, = plt.plot(t[isignal],e[isignal], 'r')
p3, = plt.plot(t[isignal], e[isignal], 'r')
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]]], \
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)], 'b', linewidth=2)
plt.legend([p1, p2, p3, p4, p5], ['Data', 'Envelope Noise Window', \
'Envelope Signal Window', 'Minimum Signal Level', \
'Envelope Signal Window',
'Minimum Signal Level', \
'Onset'], loc='best')
plt.xlabel('Time [s] since %s' % X[0].stats.starttime)
plt.ylabel('Counts')
@ -667,7 +671,7 @@ def checkPonsets(pickdic, dttolerance, iplot):
# apply jackknife bootstrapping on variance of P onsets
print 'checkPonsets: Apply jackknife bootstrapping on P-onset times ...'
[xjack,PHI_pseudo,PHI_sub] = jackknife(Ppicks, 'VAR', 1)
[xjack, PHI_pseudo, PHI_sub] = jackknife(Ppicks, 'VAR', 1)
# get pseudo variances smaller than average variances
# these picks passed jackknife test
ij = np.where(PHI_pseudo <= xjack)
@ -686,7 +690,8 @@ def checkPonsets(pickdic, dttolerance, iplot):
badstations = np.array(stations)[ibad]
print 'checkPonset: Skipped %d P onsets out of %d' % (len(badstations) \
+ len(badjkstations), len(stations))
+ len(badjkstations),
len(stations))
goodmarker = 'goodPonsetcheck'
badmarker = 'badPonsetcheck'
@ -726,6 +731,7 @@ def checkPonsets(pickdic, dttolerance, iplot):
return checkedonsets
def jackknife(X, phi, h):
'''
Function to calculate the Jackknife Estimator for a given quantity,
@ -790,7 +796,7 @@ def jackknife(X, phi, h):
return PHI_jack, PHI_pseudo, PHI_sub
if __name__ == '__main__':
import doctest
doctest.testmod()