spiketools.utils.extract.get_values_by_times

spiketools.utils.extract.get_values_by_times(timestamps, values, timepoints, time_threshold=None, drop_null=True, axis=None)[source]

Get values from a data array for a set of specified time points.

Parameters:
timestamps1d array

Timestamps, in seconds.

values1d or 2d array

Data values, corresponding to the time values in timestamps.

timepoints1d array

The time values, in seconds, to extract corresponding values 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 NaN.

drop_nullbool, optional, default: True

Whether to drop any null values from the outputs (outside threshold range). If False, outputs for any null values are NaN.

axis{0, 1}, optional

The axis argument for the values data, if it’s a 2d array, as {0: column, 1: row}. If not provided, is inferred from the values array.

Returns:
outputs1d or 2d array

The extracted values for the requested time points.

Examples

Get the data values for a specified set of timepoints:

>>> timestamps = np.array([0.5, 1, 1.5, 2, 2.5, 3 ])
>>> values = np.array([1, 2, 3, 4, 5, 6])
>>> timepoints = np.array([1, 2, 3])
>>> get_values_by_times(timestamps, values, timepoints)
array([2, 4, 6])