Finding points

The methods listed here let you find indices corresponding to points in time, or perform aggregate functions (e.g. mean, min, max) on intervals within a time series.

Indices and values at specific times

datkit.index(times, t, ttol=1e-09)

Returns the index of time t in times, assuming times is a non-decreasing sequence.

A ValueError will be raised if time t cannot be found in times. Two times will be regarded as equal if they are within ttol of each other.

datkit.index_near(times, t)

Returns the index of time t in times, or the index of the nearest value to it, assuming times is a non-decreasing sequence.

If t is outside the range of times by more than half a sampling interval (as returned by datkit.sampling_interval()), a ValueError will be raised.

datkit.index_on(times, t0=None, t1=None, include_left=True, include_right=False)

Returns a tuple (i0, i1) corresponding to the interval from t0 to t1 in times, assuming times is a non-decreasing sequence.

By default, the interval is taken as t0 <= times < t1, but this can be customized using include_left and include_right.

If one or both points are out of range, indices corresponding to the first and/or last entries in times are returned. Note that this may result in an empty interval if t0 < t1 < times[0] or times[1] < t0 < t1.

If t0 is None, the first index will be 0, regardless of the value of include_left. If t1 is None the second index will be len(times), regardless of the value of include_right.

datkit.index_crossing(values, value=0)

Returns the lowest two indices i and j for which values crosses the given value (going either from below to above, or vice versa).

For example datkit.index([0, 1, 2, 3, 4], 2.5) returns (2, 3).

The method is best applied to smooth (denoised) data.

A ValueError is raised if no crossing can be found, or

datkit.time_crossing(times, values, value=0)

Returns the time at which values first crosses value.

Specifically, the method linearly interpolates between the entries from times at the indices returned by index_crossing(). No assumptions are made about times (other than that it has the same length as values), so that arrays representing other quantities can also be passed in.

The method is best applied to smooth (denoised) data.

See also index_crossing().

datkit.value_at(times, values, t, ttol=1e-09)

Returns values[i] such that times[i] is within ttol of the time t.

A ValueError will be raised if no such i can be found.

datkit.value_near(times, values, t)

Returns values[i] such that times[i] is the nearest point to t in the data.

A ValueError will be raised if no time near t can be found in times (see index_near()).

datkit.value_interpolated(times, values, t)

Returns the value at the given time, obtained by linear interpolation if t is not presesnt in times.

A ValueError is raised if no i can be found such that times[i] <= t <= times[i + 1].

datkit.data_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns a tuple (times2, values2) corresponding to the interval from t0 to t1 in times.

See also index_on().

Averages and extremes

datkit.mean_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns the mean of values on the interval from t0 to t1.

See also index_on().

datkit.max_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns a tuple (t_max, v_max) corresponding to the maximum value in values on the interval from t0 to t1.

See also index_on().

datkit.min_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns a tuple (t_min, v_min) corresponding to the minimum value in values on the interval from t0 to t1.

See also index_on().

datkit.abs_max_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns a tuple (t_max, v_max) corresponding to the maximum value in abs(values) on the interval from t0 to t1.

See also index_on().

datkit.imax_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns the index i corresponding to the maximum value on the interval from t0 to t1.

See also index_on().

datkit.imin_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns the index i corresponding to the maximum value on the interval from t0 to t1.

See also index_on().

datkit.iabs_max_on(times, values, t0=None, t1=None, include_left=True, include_right=False)

Returns the index i corresponding to the maximum of abs(values) on the interval from t0 to t1.

See also index_on().