import numpy as np
from scipy.signal import argrelextrema
a = np.array([0,2,4,2,0,2,3,2,3,2,0])
def raycrit(a,thresh):
min_ind = argrelextrema(a, np.less)
max_ind = argrelextrema(a, np.greater)
maxima = a[max_ind]
minima = a[min_ind]
if min_ind[0][0] > max_ind[0][0]:
for i in range(0,len(minima)):
if maxima[i] > thresh and maxima[i+1] > thresh:
if minima[i] > maxima[i]/2 and minima[i] > maxima[i+1]/2:
minima[i] = thresh
a[min_ind] = minima
return a
b = raycrit(a,2.5)
In the above code excerpt, I am trying to find local minima surrounded by local maxima that are more than half the height of the highest local maximum that neighbours it. And while this put into text might be confusing, I think reading the code helps understand what I'm trying to reach for. The problem arises with the fact that minima[i] = thresh stays unchanged even when the condition is triggered. Here the result should be [0,2,4,2,0,2,3,2.5,3,2,0] but remains [0,2,4,2,0,2,3,2,3,2,0] and I am quite confused as to why...