pynapple.Ts.restrict#

Ts.restrict(iset)[source]#

Restricts a time series object to a set of time intervals delimited by an IntervalSet object

Parameters:

iset (IntervalSet) – the IntervalSet object

Returns:

Tsd object restricted to ep

Return type:

Ts, Tsd, TsdFrame or TsdTensor

Examples

>>> import pynapple as nap
>>> import numpy as np; np.random.seed(42)
>>> t = np.unique(np.sort(np.random.randint(0, 1000, 100))) # random times
>>> ts_before = nap.Ts(t=t, time_units='s')
>>> ts_before
Time (s)
1.0
13.0
20.0
21.0
34.0
58.0
71.0
...
897.0
931.0
942.0
955.0
957.0
975.0
shape: 94

ts_before is a timestamp object.

>>> ep = nap.IntervalSet(start = 0, end = 500, time_units = 's')
>>> ep
  index    start    end
      0        0    500
shape: (1, 2), time unit: sec.

ep is an IntervalSet object defining the epochs.

>>> ts_after = ts_before.restrict(ep)
>>> ts_after
Time (s)
1.0
13.0
20.0
21.0
34.0
58.0
...
466.0
474.0
475.0
476.0
484.0
491.0
shape: 53

ts_after is a timestamp object restricted to the epochs.