Search code examples
pythonmatplotlibplotgradientanalysis

Find first minimum gradient python


I would need to find the first minimum of the gradient_array array, then the local minimum that is within the first 50 meters.

gradient_array= np.gradient(moving_avg_RCS)
MLH = min(gradient_array)

Attached: plot in which you can see the point of the minimum that it finds. I need the first minimum within 50 meters enter image description here


EDIT:

sodar_data = pd.read_csv('20141222_sodar-data.csv')    
headers=(sodar_data.columns).tolist()
height_str=headers[1:]    
height=[float(i) for i in height_str]  

gradient_array= np.gradient(moving_avg_RCS) 
MLH = min(gradient_array)
gradient = gradient_array.tolist()
index = gradient.index(MLH)
MLHS_height = height[index]

Solution

  • You'll need np.array for that :

    height = np.array(height)  
    gradient_array_within_50_meters = gradient_array[height < 50]
    
    min_within_50_meters = gradient_array_within_50_meters.min()
    height_min_within_50_meters = height[gradient_array_within_50_meters.argmin()]