[cleanup] code cleanup in autopick.py using code inspection

This commit is contained in:
Darius Arnold 2017-10-05 16:07:29 +02:00
parent 6f65789844
commit 5931331b1d

View File

@ -11,8 +11,6 @@ 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.charfuns import CharacteristicFunction
from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf
from pylot.core.pick.picker import AICPicker, PragPicker
@ -51,13 +49,12 @@ def autopickevent(data, param, iplot=0, fig_dict=None, fig_dict_wadatijack=None,
input_tuples = []
try:
iplot = int(iplot)
except:
if iplot == True or iplot == 'True':
except ValueError:
if iplot is True or iplot == 'True':
iplot = 2
else:
iplot = 0
# get some parameters for quality control from
# parameter input file (usually pylot.in).
wdttolerance = param.get('wdttolerance')
@ -74,7 +71,7 @@ def autopickevent(data, param, iplot=0, fig_dict=None, fig_dict_wadatijack=None,
for station in stations:
topick = data.select(station=station)
if iplot == None or iplot == 'None' or iplot == 0:
if iplot is None or iplot == 'None' or iplot == 0:
input_tuples.append((topick, param, apverbose, metadata, origin))
if iplot > 0:
all_onsets[station] = autopickstation(topick, param, verbose=apverbose,
@ -101,12 +98,9 @@ def autopickevent(data, param, iplot=0, fig_dict=None, fig_dict_wadatijack=None,
pick.pop('station')
all_onsets[station] = pick
#return all_onsets
# quality control
# median check and jackknife on P-onset times
jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, jackfactor, 1, fig_dict_wadatijack)
#return jk_checked_onsets
# check S-P times (Wadati)
wadationsets = wadaticheck(jk_checked_onsets, wdttolerance, 1, fig_dict_wadatijack)
return wadationsets
@ -286,7 +280,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
# for global seismology: use tau-p method for estimating travel times (needs source and station coords.)
# if not given: sets Lc to infinity to use full stream
if use_taup == True:
if use_taup is True:
Lc = np.inf
print('autopickstation: use_taup flag active.')
if not metadata[1]:
@ -328,7 +322,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
pstart = max(pstart, 0)
pstop = min(pstop, len(zdat[0])*zdat[0].stats.delta)
if not use_taup == True or origin:
if not use_taup is True or origin:
Lc = pstop - pstart
Lwf = zdat[0].stats.endtime - zdat[0].stats.starttime
@ -463,8 +457,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
slope = aicpick.getSlope()
if not slope:
slope = 0
if (slope >= minAICPslope and
aicpick.getSNR() >= minAICPSNR and Pflag == 1):
if slope >= minAICPslope and aicpick.getSNR() >= minAICPSNR and Pflag == 1:
aicPflag = 1
msg = 'AIC P-pick passes quality control: Slope: {0} counts/s, ' \
'SNR: {1}\nGo on with refined picking ...\n' \
@ -533,7 +526,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
[SNRP, SNRPdB, Pnoiselevel] = getSNR(z_copy, tsnrz, mpickP)
# weight P-onset using symmetric error
if Perror == None:
if Perror is None:
Pweight = 4
else:
if Perror <= timeerrorsP[0]:
@ -588,8 +581,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
print('autopickstation: No vertical component data available!, '
'Skipping station!')
if ((len(edat) > 0 and len(ndat) == 0) or (
len(ndat) > 0 and len(edat) == 0)) and Pweight < 4:
if ((len(edat) > 0 and len(ndat) == 0) or (len(ndat) > 0 and len(edat) == 0)) and Pweight < 4:
msg = 'Go on picking S onset ...\n' \
'##################################################\n' \
'Only one horizontal component available!\n' \
@ -628,7 +620,6 @@ def autopickstation(wfstream, pickparam, verbose=False,
'traces ...'.format(edat[0].stats.station)
if verbose: print(msg)
if algoS == 'ARH':
# re-create stream object including both horizontal components
hdat = edat.copy()
@ -709,8 +700,7 @@ def autopickstation(wfstream, pickparam, verbose=False,
if not slope:
slope = 0
if (slope >= minAICSslope and
aicarhpick.getSNR() >= minAICSSNR and
aicarhpick.getpick() is not None):
aicarhpick.getSNR() >= minAICSSNR and aicarhpick.getpick() is not None):
aicSflag = 1
msg = 'AIC S-pick passes quality control: Slope: {0} counts/s, ' \
'SNR: {1}\nGo on with refined picking ...\n' \
@ -905,15 +895,15 @@ def autopickstation(wfstream, pickparam, verbose=False,
##############################################################
try:
iplot = int(iplot)
except:
if iplot == True or iplot == 'True':
except ValueError:
if iplot is True or iplot == 'True':
iplot = 2
else:
iplot = 0
if iplot > 0:
# plot vertical trace
if fig_dict == None or fig_dict == 'None':
if fig_dict is None or fig_dict == 'None':
fig = plt.figure()
plt_flag = 1
linecolor = 'k'
@ -1072,8 +1062,10 @@ def autopickstation(wfstream, pickparam, verbose=False,
ax3.set_title(trH2_filt.stats.channel)
if plt_flag == 1:
fig.show()
try: input()
except SyntaxError: pass
try:
input()
except SyntaxError:
pass
plt.close(fig)
##########################################################################
# calculate "real" onset times
@ -1189,8 +1181,7 @@ def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter, fig_dict=None):
print("iteratepicker: Small residuum, leave parameters unchanged for this phase!")
else:
pickparameter.setParam(pstart=pstart)
pickparameter.setParam(pstop=pickparameter.get('pstart') + \
(pickparameter.get('Precalcwin')))
pickparameter.setParam(pstop=pickparameter.get('pstart') + (pickparameter.get('Precalcwin')))
pickparameter.setParam(sstop=pickparameter.get('sstop') / 2)
pickparameter.setParam(pickwinP=pickparameter.get('pickwinP') / 2)
pickparameter.setParam(Precalcwin=pickparameter.get('Precalcwin') / 2)