20  Perievent

20.1 Simulated spiking unit

import pynapple as nap
import numpy as np
stimuli = nap.Ts(t=np.arange(0, 1000, 1), time_units="s")

baseline = np.random.uniform(0, 1000, 500)
burst = np.concatenate([
        np.random.normal(
            st + 0.1, 0.05, 3
        ) 
        for st in stimuli.times()
    ])
ts = nap.Ts(t=np.sort(np.concatenate([baseline, burst])))
ts
Time (s)
0.08523415674248622
0.14164606655395304
0.15238348781207722
1.0246865979789603
1.0728664266703758
1.0744352279806042
1.607068738658235
...
998.0419174697408
998.0549143383058
998.17210900468
999.0081811278299
999.0978970661826
999.1157571264887
999.1998066179041
shape: 3500

20.2 Peri-Event Time Histograms (PETH)

peth = nap.compute_perievent(
    data=ts, 
    events=stimuli, 
    window=(-0.1, 0.4))
peth
Index    rate    events
-------  ------  --------
0        6.0     1.0
1        8.0     2.0
2        6.0     3.0
3        6.0     4.0
4        6.0     5.0
5        6.0     6.0
6        6.0     7.0
...      ...     ...
992      6.0     993.0
993      6.0     994.0
994      8.0     995.0
995      10.0    996.0
996      6.0     997.0
997      6.0     998.0
998      8.0     999.0
bin_size = 0.01
peth_counts = peth.count(bin_size)
peth_counts
Time (s)               0    1    2    3    4    ...
---------------------  ---  ---  ---  ---  ---  -----
-0.095                 0    0    0    0    0    ...
-0.08499999999999999   0    0    0    0    0    ...
-0.075                 0    0    0    0    0    ...
-0.065                 0    0    0    0    0    ...
-0.055                 0    0    0    0    0    ...
-0.045000000000000005  0    0    0    0    0    ...
-0.035                 0    1    0    0    0    ...
...                                             ...
0.335                  0    0    0    0    0    ...
0.34500000000000003    0    0    0    0    0    ...
0.355                  0    0    0    0    0    ...
0.365                  0    0    0    0    0    ...
0.375                  0    0    0    0    0    ...
0.385                  0    0    0    0    0    ...
0.395                  0    0    0    0    0    ...
Metadata
events                 1.0  2.0  3.0  4.0  5.0  ...
dtype: int64, shape: (50, 999)