[Numpy-discussion] Overlapping time series
daniele at grinta.net
Tue Feb 11 10:52:11 EST 2014
On 11/02/2014 15:38, Sturla Molden wrote:
> Daniele Nicolodi <daniele at grinta.net> wrote:
>> I was probably not that clear: I have two 2xN arrays, one for each data
>> recording, one column for time (taken from the same clock for both
>> measurements) and one with data values. Each array has some gaps.
> If you want all subarrays where both timeseries are sampled, a single loop
> through the data
> can fix that. First find the smallest common timestamp. This is the first
> starting point. Then loop and follow the timestamps. As long as they are in
> synch, do just continue. If one timeseries suddenly skips forward (i.e.
> there is a gap), you have an end point. Then slice between the start and
> the end point, and append the view array to a list. Follow the timeseries
> that did not skip until timestamps are synchronous again, and you have the
> next starting point. Then just continue like this until the the two
> timeseries are exhausted. It is an O(n) strategy, so it will not be
> inefficient. If you are worried about the loop and performance, both Numba
> and Cython can transform this into C speed. Numba takes less effort to use.
> But Python loops are actually much faster than most scientists used to
> Matlab and the like would expect.
That's more or less my current approach (except that I use the fact that
the data is evenly samples to use np.where(np.diff(t1) != dt) to detect
the regions of continuous data, to avoid the loop.
More information about the NumPy-Discussion