[change] include safetygap in check for other maxima in front of first one

And some changes to improve readability/understandability
This commit is contained in:
Darius Arnold 2017-08-26 19:19:55 +02:00
parent 01dc489569
commit 2b7ff9fd3a
2 changed files with 11 additions and 8 deletions

View File

@ -194,7 +194,8 @@ class AICPicker(AutoPicker):
aicsmooth = aicsmooth - offset aicsmooth = aicsmooth - offset
# get maximum of HOS/AR-CF as startimg point for searching # get maximum of HOS/AR-CF as startimg point for searching
# minimum in AIC function # minimum in AIC function
icfmax = get_maximum_index(self.Data[0].data, self.checkwindow, self.minfactor) icfmax = get_maximum_index(self.Data[0].data, self.checkwindow, self.minfactor,
int(self.TSNR[1]/self.Data[0].stats.delta))
# 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))

View File

@ -1173,20 +1173,22 @@ def removePicksAbove(pickDic, minWeight):
return newdic return newdic
def get_maximum_index(data, checkwindow, minfactor): def get_maximum_index(data, checkwindow, minfactor, safetygap):
'''get maximum of CF as starting point, then check for highest local maximum '''get maximum of CF as starting point, then check for highest local maximum
in front of it. in front of it.
return second maximum if its larger than first maximum * minfactor, else return second maximum if its larger than first maximum * minfactor, else
return first maximum''' return first maximum.
checkwindow and safetygap are given in samples'''
icfmax1 = np.argmax(data) icfmax1 = np.argmax(data)
imax_local = argrelextrema(data[icfmax1 - checkwindow:icfmax1], np.greater) # indices of local maxima imax_local = argrelextrema(data[icfmax1 - checkwindow:icfmax1 - safetygap], np.greater)[0] # indices of local maxima
if (len(imax_local[0]) > 0): if imax_local.size > 0:
imax_local = imax_local[0] + icfmax1 - checkwindow imax_local = imax_local + icfmax1 - checkwindow
local_maxima = (imax_local, data[imax_local]) local_maxima = (imax_local, data[imax_local])
icfmax2 = local_maxima[0][np.where(local_maxima[1] == max(local_maxima[1]))][0] largest_local_max = np.where(local_maxima[1] == max(local_maxima[1]))
icfmax2 = local_maxima[0][largest_local_max]
if data[icfmax2] > data[icfmax1] * minfactor: if data[icfmax2] > data[icfmax1] * minfactor:
print("Found valid local maximum in front of first maximum") print("Found valid local maximum in front of first maximum")
return icfmax2 return icfmax2[0]
else: else:
print("First maximum is the largest: {}>{}".format(data[icfmax1], print("First maximum is the largest: {}>{}".format(data[icfmax1],
data[icfmax2])) data[icfmax2]))