pynapple.core.ts_group.TsGroup.count#

TsGroup.count(*args, dtype=None, **kwargs)[source]#

Count occurences of events within bin_size or within a set of bins defined as an IntervalSet. You can call this function in multiple ways :

1. tsgroup.count(bin_size=1, time_units = ‘ms’) -> Count occurence of events within a 1 ms bin defined on the time support of the object.

2. tsgroup.count(1, ep=my_epochs) -> Count occurent of events within a 1 second bin defined on the IntervalSet my_epochs.

3. tsgroup.count(ep=my_bins) -> Count occurent of events within each epoch of the intervalSet object my_bins

4. tsgroup.count() -> Count occurent of events within each epoch of the time support.

bin_size should be seconds unless specified. If bin_size is used and no epochs is passed, the data will be binned based on the time support of the object.

Parameters:
  • bin_size (None or float, optional) – The bin size (default is second)

  • ep (None or IntervalSet, optional) – IntervalSet to restrict the operation

  • time_units (str, optional) – Time units of bin size (‘us’, ‘ms’, ‘s’ [default])

  • dtype (type, optional) – Data type for the count. Default is np.int64.

Returns:

out – A TsdFrame with the columns being the index of each item in the TsGroup.

Return type:

TsdFrame

Examples

This example shows how to count events within bins of 0.1 second for the first 100 seconds.

>>> import pynapple as nap
>>> import numpy as np
>>> tmp = { 0:nap.Ts(t=np.arange(0,200), time_units='s'),
1:nap.Ts(t=np.arange(0,200,0.5), time_units='s'),
2:nap.Ts(t=np.arange(0,300,0.25), time_units='s'),
}
>>> tsgroup = nap.TsGroup(tmp)
>>> ep = nap.IntervalSet(start=0, end=100, time_units='s')
>>> bincount = tsgroup.count(0.1, ep)
>>> bincount
          0  1  2
Time (s)
0.05      0  0  0
0.15      0  0  0
0.25      0  0  1
0.35      0  0  0
0.45      0  0  0
...      .. .. ..
99.55     0  1  1
99.65     0  0  0
99.75     0  0  1
99.85     0  0  0
99.95     1  1  1
[1000 rows x 3 columns]