The algorithm you propose seems reasonable and as if it will work.
As it became clear in your comments, the problem with this is the rudeness with which your time was recorded. (This may be a common occurrence when unsynchronized data is recorded, i.e. the clock for data synchronization, for example, the frame rate, is not synchronized with the computer).
Easy way: read two points separated by a long time, for example, read the first time value, and then the 1000th time value . Then everything remains the same in your calculations, but you get the timestep by subtracting and then dividing by 1000
Here's a test that makes the data look like yours:
import matplotlib.pyplot as plt start = 97523.29783 increment = .000378912098 target = 97585.23452 # build a timeline times = [] time = start actual_index = None for i in range(1000000): trunc = float(str(time)[:10]) # truncate the time value times.append(trunc) if actual_index is None and time>target: actual_index = i time = time + increment # now test intervals = [1, 2, 5, 10, 100, 1000, 10000] for i in intervals: dt = (times[i] - times[0])/i index = int((target-start)/dt) print " %6i %8i %8i %.10f" % (i, actual_index, index, dt)
Result:
span actual guess est dt (actual=.000378912098) 1 163460 154841 0.0004000000 2 163460 176961 0.0003500000 5 163460 162991 0.0003800000 10 163460 162991 0.0003800000 100 163460 163421 0.0003790000 1000 163460 163464 0.0003789000 10000 163460 163460 0.0003789100
That is, as the space between the selected points increases, the estimate of the time interval becomes more accurate (compared with increment in the program), and the evaluation index (third column) approaches the actual index (2nd column). Please note that the accuracy of the dt estimate is mainly proportional to the number of digits in the span. The best you can do is use the time at the start and end points, but of you, it seemed hard to say that it would be difficult; but if it is not, it will give the most accurate estimate of your time interval. Please note that here, for clarity, I exaggerated the lack of accuracy, making my time interval very good, but in general, every force of 10 in your range increases your accuracy by the same amount.
As an example of this last point, if I reduce the fluidity of the time values ββby changing the line of the trunc = float(str(time)[:12]) , I get:
span actual guess est dt (actual=.000378912098) 1 163460 163853 0.0003780000 10 163460 163464 0.0003789000 100 163460 163460 0.0003789100 1000 163460 163459 0.0003789120 10000 163460 163459 0.0003789121
So, if, as you say, using range 1 comes close to you, using range 100 or 1000 should be more than enough.
Overall, this is very similar to the idea of ββa linear "interpolation search". This is a little easier to implement because it makes only one assumption based on interpolation, so it just takes one line of code: int((target-start)*i/(times[i] - times[0]))