1

Github link to txt file`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.

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 .`

and those are images of the expected graphs for instance.

1st graph

Second Graph

9
  • Welcome to SO, please publish your data as well as a formatted code or shared link (no screenshot).
    – jlandercy
    Commented Jul 8 at 11:20
  • What does "the slope of the lower region" mean? If you mean the minimum point of the curve and the curve is smooth, you might just get away with find_linear_part = lambda: 0 ;-)
    – Joooeey
    Commented Jul 8 at 11:32
  • ok i know there is a confusion but what should I upload to understand better as screenshots are not allowed so the understanding is better ? Commented Jul 8 at 12:08
  • Screenshots of code/data are not allowed. Images/graphs that illustrate the expected logic are welcome.
    – mozway
    Commented Jul 8 at 12:13
  • Indeed I added the graphs but then removed them. Commented Jul 8 at 12:15

0

Browse other questions tagged or ask your own question.