spiketools.utils.extract.get_inds_by_times¶
- spiketools.utils.extract.get_inds_by_times(timestamps, timepoints, time_threshold=None, drop_null=True)[source]¶
Get indices for a set of specified time points.
- Parameters:
- timestamps1d array
Timestamps, in seconds.
- timepoints1d array
The time values, in seconds, to extract indices 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.
- drop_nullbool, optional, default: True
Whether to drop any null indices from the outputs (outside threshold range). If False, indices for any null values are -1.
- Returns:
- inds1d array
Indices for all requested timepoints.
Examples
Get the corresponding indices for specified timepoints:
>>> timestamps = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0]) >>> timepoints = np.array([1, 2, 3]) >>> get_inds_by_times(timestamps, timepoints) array([1, 3, 5])