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