pynapple.process.perievent#

Functions to realign time series relative to a reference time.

Functions

compute_event_trigger_average(group, ...[, ...])

Bin the event timestamps within binsize and compute the Event Trigger Average (ETA) within windowsize.

compute_perievent(data, tref, minmax[, ...])

Center the timestamps of a time series object or a time series group around the timestamps given by the tref argument.

compute_perievent_continuous(data, tref, minmax)

Center continuous time series around the timestamps given by the 'tref' argument.

pynapple.process.perievent.compute_event_trigger_average(group, feature, binsize, windowsize=None, ep=None, time_unit='s')[source]#

Bin the event timestamps within binsize and compute the Event Trigger Average (ETA) within windowsize. If C is the event count matrix and feature is a Tsd array, the function computes the Hankel matrix H from windowsize=(-t1,+t2) by offseting the Tsd array.

The ETA is then defined as the dot product between H and C divided by the number of events.

The object feature can be any dimensions.

Parameters:
  • group (TsGroup) – The group of Ts/Tsd objects that hold the trigger time.

  • feature (Tsd, TsdFrame or TsdTensor) – The feature to average.

  • binsize (float or int) – The bin size. Default is second. If different, specify with the parameter time_unit (‘s’ [default], ‘ms’, ‘us’).

  • windowsize (tuple of float/int or float/int) – The window size. Default is second. For example windowsize = (-1, 1) is equivalent to windowsize = 1 If different, specify with the parameter time_unit (‘s’ [default], ‘ms’, ‘us’).

  • ep (IntervalSet) – The epochs on which the average is computed

  • time_unit (str, optional) – The time unit of the parameters. They have to be consistent for binsize and windowsize. (‘s’ [default], ‘ms’, ‘us’).

pynapple.process.perievent.compute_perievent(data, tref, minmax, time_unit='s')[source]#

Center the timestamps of a time series object or a time series group around the timestamps given by the tref argument. minmax indicates the start and end of the window. If minmax=(-5, 10), the window will be from -5 second to 10 second. If minmax=10, the window will be from -10 second to 10 second.

To center continuous time series around a set of timestamps, you can use compute_perievent_continuous.

Parameters:
  • data (Ts, Tsd or TsGroup) – The data to align to tref. If Ts/Tsd, returns a TsGroup. If TsGroup, returns a dictionary of TsGroup

  • tref (Ts or Tsd) – The timestamps of the event to align to

  • minmax (tuple, int or float) – The window size. Can be unequal on each side i.e. (-500, 1000).

  • time_unit (str, optional) – Time units of the minmax (‘s’ [default], ‘ms’, ‘us’).

Returns:

A TsGroup if data is a Ts/Tsd or a dictionary of TsGroup if data is a TsGroup.

Return type:

dict

Raises:

RuntimeError – if tref is not a Ts/Tsd object or if data is not a Ts/Tsd or TsGroup

pynapple.process.perievent.compute_perievent_continuous(data, tref, minmax, ep=None, time_unit='s')[source]#

Center continuous time series around the timestamps given by the ‘tref’ argument. minmax indicates the start and end of the window. If minmax=(-5, 10), the window will be from -5 second to 10 second. If minmax=10, the window will be from -10 second to 10 second.

To realign timestamps around a set of timestamps, you can use compute_perievent_continuous.

This function assumes a constant sampling rate of the time series.

Parameters:
  • data (Tsd, TsdFrame or TsdTensor) – The data to align to tref.

  • tref (Ts or Tsd) – The timestamps of the event to align to

  • minmax (tuple or int or float) – The window size. Can be unequal on each side i.e. (-500, 1000).

  • ep (IntervalSet, optional) – The epochs to perform the operation. If None, the default is the time support of the data.

  • time_unit (str, optional) – Time units of the minmax (‘s’ [default], ‘ms’, ‘us’).

Returns:

If data is a one-dimensional Tsd, the output is a TsdFrame. Each column is one timestamps from tref. If data is a TsdFrame or TsdTensor, the output is a TsdTensor with one more dimension. The first dimension is always time and the second dimension is the ‘tref’ timestamps.

Return type:

TsdFrame, TsdTensor

Raises:

RuntimeError – if tref is not a Ts/Tsd object or if data is not a Tsd/TsdFrame/TsdTensor object.