pynapple.TsdTensor.restrict#
- TsdTensor.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:
Examples
>>> import pynapple as nap >>> import numpy as np; np.random.seed(42) >>> t = np.unique(np.sort(np.random.randint(0, 1000, 100))) >>> tsdtensor_before = nap.TsdTensor(t=t, d=np.random.randn(len(t), 4, 4), time_units='s') >>> tsdtensor_before Time (s) ---------- ------------------------------- 1.0 [[-2.178334 ... 0.324199] ...] 13.0 [[-1.875677 ... -0.906721] ...] 20.0 [[0.326845 ... 0.736122] ...] 21.0 [[1.62292 ... 0.89663] ...] 34.0 [[-0.870305 ... 2.943663] ...] 58.0 [[-0.441766 ... -1.426479] ...] ... 897.0 [[ 0.962199 ... -0.370506] ...] 931.0 [[-0.511451 ... 0.5125 ] ...] 942.0 [[-0.828463 ... 0.300192] ...] 955.0 [[-1.193155 ... 0.247027] ...] 957.0 [[1.638941 ... 0.236425] ...] 975.0 [[ 0.393912 ... -1.180782] ...] dtype: float64, shape: (94, 4, 4)
tsdtensor_before is a timestamp tensor with data.
>>> 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.
>>> tsdtensor_after = tsdtensor_before.restrict(ep) >>> tsdtensor_after Time (s) ---------- ------------------------------- 1.0 [[-2.178334 ... 0.324199] ...] 13.0 [[-1.875677 ... -0.906721] ...] 20.0 [[0.326845 ... 0.736122] ...] 21.0 [[1.62292 ... 0.89663] ...] 34.0 [[-0.870305 ... 2.943663] ...] 58.0 [[-0.441766 ... -1.426479] ...] ... 466.0 [[-1.045913 ... 1.601238] ...] 474.0 [[ 1.354845 ... -0.382483] ...] 475.0 [[ 1.347856 ... -2.011918] ...] 476.0 [[-0.218104 ... -0.019882] ...] 484.0 [[0.454563 ... 0.636631] ...] 491.0 [[ 0.618141 ... -0.10405 ] ...] dtype: float64, shape: (53, 4, 4)
tsdtensor_after is a timestamp tensor restricted to the epochs.