Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I work with Python for similar analyses, and have a few suggestions to make. I didn't look at the details of your code, just to your problem statement:</p> <blockquote> <p>1) It grabs a small piece of data of size dx (starting with 3 datapoints)</p> <p>2) It evaluates whether the difference (i.e. |y(x+dx)-y(x-dx)| ) is larger than a certain minimum value (40x std. dev. of noise)</p> <p>3) If the difference is large enough, it will calculate the slope using OLS regression. If the difference is too small, it will increase dx and redo the loop with this new dx</p> <p>4) This continues for all the datapoints</p> </blockquote> <p>I think the more obvious reason for slow execution is the LOOPING nature of your code, when perhaps you could use the VECTORIZED (array-based operations) nature of Numpy.</p> <p>For step 1, instead of taking pairs of points, you can perform directly `data[3:] - data[-3:] and get all the differences in a single array operation;</p> <p>For step 2, you can use the result from array-based tests like <code>numpy.argwhere(data &gt; threshold)</code> instead of testing every element inside some loop;</p> <p>Step 3 sounds conceptually wrong to me. You say that if the difference is too small, it will increase <code>dx</code>. But if the difference is small, the resulting slope would be small because it IS actually small. Then, getting a small value is the right result, and artificially increasing <code>dx</code> to get a "better" result might not be what you want. Well, it might actually be what you want, but you should consider this. I would suggest that you calculate the slope for a fixed <code>dx</code> across the whole data, and then take the resulting array of slopes to select your regions of interest (for example, using <code>data_slope[numpy.argwhere(data_slope &gt; minimum_slope)]</code>.</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload