def get_echos(dat_arr,min_distance=10):
"""
getting local maxima and minima from 1D data -> e.g. speckle echos
strategy: using peak_local_max (from skimage) with min_distance parameter to find well defined local maxima
using np.argmin to find absolute minima between relative maxima
returns [max_ind,min_ind] -> lists of indices corresponding to local maxima/minima
by LW 10/23/2018
"""
from skimage.feature import peak_local_max
max_ind=peak_local_max(dat_arr, min_distance) # !!! careful, skimage function reverses the order (wtf?)
min_ind=[]
for i in range(len(max_ind[:-1])):
min_ind.append(max_ind[i+1][0]+np.argmin(dat_arr[max_ind[i+1][0]:max_ind[i][0]]))
#unfortunately, skimage function fu$$s up the format: max_ind is an array of a list of lists...fix this:
mmax_ind=[]
for l in max_ind:
mmax_ind.append(l[0])
#return [mmax_ind,min_ind]
return [list(reversed(mmax_ind)),list(reversed(min_ind))]
评论列表
文章目录