[change] initial pick now searches for latest local minimum instead of first increase in cf

This commit is contained in:
Marcel Paffrath 2018-07-05 15:29:09 +02:00
parent df0f059ff3
commit 2c588c1c80

View File

@ -23,7 +23,7 @@ import warnings
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from scipy.signal import argrelmax from scipy.signal import argrelmax, argrelmin
from pylot.core.pick.charfuns import CharacteristicFunction from pylot.core.pick.charfuns import CharacteristicFunction
from pylot.core.pick.utils import getnoisewin, getsignalwin from pylot.core.pick.utils import getnoisewin, getsignalwin
@ -197,10 +197,15 @@ class AICPicker(AutoPicker):
# find minimum in AIC-CF front of maximum of HOS/AR-CF # find minimum in AIC-CF front of maximum of HOS/AR-CF
lpickwindow = int(round(self.PickWindow / self.dt)) lpickwindow = int(round(self.PickWindow / self.dt))
for i in range(icfmax - 1, max([icfmax - lpickwindow, 2]), -1): tsafety = self.TSNR[1] # safety gap, AIC is usually a little bit too late
if aicsmooth[i - 1] >= aicsmooth[i]: left_corner_ind = max([icfmax - lpickwindow, 2])
self.Pick = self.Tcf[i] right_corner_ind = icfmax + int(tsafety / self.dt)
break aic_snip = aicsmooth[left_corner_ind : right_corner_ind]
minima = argrelmin(aic_snip)[0] # 0th entry of tuples for axes
if len(minima) > 0:
pickindex = minima[-1] + left_corner_ind
self.Pick = self.Tcf[pickindex]
# if no minimum could be found: # if no minimum could be found:
# search in 1st derivative of AIC-CF # search in 1st derivative of AIC-CF
if self.Pick is None: if self.Pick is None:
@ -215,6 +220,7 @@ class AICPicker(AutoPicker):
for i in range(icfmax - 1, max([icfmax - lpickwindow, 2]), -1): for i in range(icfmax - 1, max([icfmax - lpickwindow, 2]), -1):
if diffcf[i - 1] >= diffcf[i]: if diffcf[i - 1] >= diffcf[i]:
self.Pick = self.Tcf[i] self.Pick = self.Tcf[i]
pickindex = i
break break
if self.Pick is not None: if self.Pick is not None:
@ -244,7 +250,6 @@ class AICPicker(AutoPicker):
# calculate slope from CF after initial pick # calculate slope from CF after initial pick
# get slope window # get slope window
tslope = self.TSNR[3] # slope determination window tslope = self.TSNR[3] # slope determination window
tsafety = self.TSNR[1] # safety gap, AIC is usually a little bit too late
if tsafety >= 0: if tsafety >= 0:
islope = np.where((self.Tcf <= min([self.Pick + tslope + tsafety, self.Tcf[-1]])) \ islope = np.where((self.Tcf <= min([self.Pick + tslope + tsafety, self.Tcf[-1]])) \
& (self.Tcf >= self.Pick)) # TODO: put this in a seperate function like getsignalwin & (self.Tcf >= self.Pick)) # TODO: put this in a seperate function like getsignalwin
@ -263,7 +268,6 @@ class AICPicker(AutoPicker):
return return
try: try:
imaxs, = argrelmax(dataslope) imaxs, = argrelmax(dataslope)
imaxs.size
imax = imaxs[0] imax = imaxs[0]
except ValueError as e: except ValueError as e:
print(e, 'picker: argrelmax not working!') print(e, 'picker: argrelmax not working!')
@ -280,7 +284,7 @@ class AICPicker(AutoPicker):
if self.iplot > 1: if self.iplot > 1:
if self.fig == None or self.fig == 'None': if self.fig == None or self.fig == 'None':
fig = plt.figure() fig = plt.figure()
plt_flag = 1 plt_flag = iplot
else: else:
fig = self.fig fig = self.fig
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
@ -291,7 +295,7 @@ class AICPicker(AutoPicker):
ax.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime) ax.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax.set_yticks([]) ax.set_yticks([])
ax.set_title(self.Data[0].stats.station) ax.set_title(self.Data[0].stats.station)
if plt_flag == 1: if plt_flag in [1, 2]:
fig.show() fig.show()
try: input() try: input()
except SyntaxError: pass except SyntaxError: pass
@ -315,7 +319,7 @@ class AICPicker(AutoPicker):
if iplot > 1: if iplot > 1:
if self.fig == None or self.fig == 'None': if self.fig == None or self.fig == 'None':
fig = plt.figure() # self.iplot) fig = plt.figure() # self.iplot)
plt_flag = 1 plt_flag = iplot
else: else:
fig = self.fig fig = self.fig
fig._tight = True fig._tight = True
@ -359,11 +363,15 @@ class AICPicker(AutoPicker):
else: else:
ax1.set_title(self.Data[0].stats.station) ax1.set_title(self.Data[0].stats.station)
if plt_flag == 1: if plt_flag in [1, 2]:
fig.show() fig.show()
try: input() try: input()
except SyntaxError: pass except SyntaxError: pass
plt.close(fig) plt.close(fig)
if plt_flag == 3:
stats = self.Data[0].stats
netstlc = '{}.{}.{}'.format(stats.network, stats.station, stats.location)
fig.savefig('aicfig_{}_{}.png'.format(netstlc, stats.channel))
if self.Pick == None: if self.Pick == None:
print('AICPicker: Could not find minimum, picking window too short?') print('AICPicker: Could not find minimum, picking window too short?')