`So I have a project , of which the data are of atomic force microscopy. I have two values d = distance and f = force plotted on a normal x-y graph. So there will curves of slightly differnt shapes and values but will look somehow the same. Exmaple Photos [First Image ]
(https://i.sstatic.net/yrrv3s70.png)
Second Image
I am using numpy and using sliding window method unfortuantely it does not work ans the proffesor told me in one curve the data points are increasing and on the other the data points are dereasing. My sample code is :
def find_linear_part(d, f, window_size=120, min_slope=0.01):
slope = 0
intercept = 0
fit = 0
min_residual = float('inf')
for i in range(len(d) - window_size + 1):
d_window = d[i:i + window_size]
f_window = f[i:i + window_size]
slope, intercept = np.polyfit(d_window, f_window, 1)
y_fit = slope * d_window + intercept
residual = np.sum((f_window - y_fit) ** 2)
if residual < min_residual:
min_residual = residual
fit = (d_window, f_window)
new_slope = slope
new_intercept = intercept
return fit, new_slope, new_intercept
I used here a threshold for the slope as some of the slopes were mentioned on the graph .`
LeCroissant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.