spiketools.utils.extract.get_ind_by_time

spiketools.utils.extract.get_ind_by_time(timestamps, timepoint, time_threshold=None)[source]

Get the index for a set of timepoints closest to a specified timepoint.

Parameters:
timestamps1d array

Timestamps, in seconds.

timepointfloat

The time value to extract the index for.

time_thresholdfloat, optional

The threshold that the closest time value must be within to be returned. If the temporal distance is greater than the threshold, output is -1.

Returns:
indint

The index value for the requested timepoint, or -1 if out of threshold range.

Examples

Get the index for a specified timepoint:

>>> timestamps = np.array([0.5, 1, 1.5, 2, 2.5, 3 ])
>>> get_ind_by_time(timestamps, 2.5)
4