spiketools.utils.epoch.epoch_data_by_range

spiketools.utils.epoch.epoch_data_by_range(timestamps, values, start_times, stop_times, reset=False)[source]

Epoch data into trials, based on time ranges of interest.

Parameters:
timestamps1d array

Timestamps, in seconds.

values1d or 2d array

Data values, corresponding the the timestamps.

start_times, stop_timeslist of float

The start and stop times, in seconds, of each epoch.

resetbool, optional, default: False

If True, resets the values in each epoch range to the start time of that epoch.

Returns:
trial_timestampslist of 1d array

The timestamps, per trial.

trial_valueslist of 1d array

The values, per trial.

Examples

Epoch data values into trials and reset the starting timestamps of each trial to zero:

>>> timestamps = np.array([0.1, 0.3, 0.4, 0.5])
>>> values = np.array([1, 2, 3, 4])
>>> start_times = [0.2, 0.5]
>>> stop_times = [0.45, 0.75]
>>> epoch_data_by_range(timestamps, values, start_times, stop_times, reset=True)
([array([0.1, 0.2]), array([0.])], [array([2, 3]), array([4])])