spiketools.utils.epoch.epoch_data_by_event

spiketools.utils.epoch.epoch_data_by_event(timestamps, values, events, window)[source]

Epoch data into trials, based on events of interest.

Parameters:
timestamps1d array

Timestamps, in seconds.

values1d or 2d array

Data values.

events1d array

The set of event times to extract from the data.

windowlist of [float, float]

The time window to extract around each event, in seconds.

Returns:
trial_timestampslist of 1d array

The timestamps, per trial.

trial_valueslist of 1d array

The values, per trial.

Examples

Epoch data into trials based on event windows:

>>> timestamps = np.array([0.1, 0.3, 0.5, 0.7, 0.9])
>>> values = np.array([1.0, 1.5, 2.0, 2.5, 3.0])
>>> events = np.array([0.3, 0.6])
>>> window = [0.0, 0.25]
>>> epoch_data_by_event(timestamps, values, events, window)
([array([0. , 0.2]), array([0.1])], [array([1.5, 2. ]), array([2.5])])