pynapple.core.time_series.Tsd.value_from#

Tsd.value_from(data, ep=None)#

Replace the value with the closest value from Tsd/TsdFrame/TsdTensor argument

Parameters:
  • data (Tsd, TsdFrame or TsdTensor) – The object holding the values to replace.

  • ep (IntervalSet (optional)) – The IntervalSet object to restrict the operation. If None, the time support of the tsd input object is used.

Returns:

out – Object with the new values

Return type:

Tsd, TsdFrame or TsdTensor

Examples

In this example, the ts object will receive the closest values in time from tsd.

>>> import pynapple as nap
>>> import numpy as np
>>> t = np.unique(np.sort(np.random.randint(0, 1000, 100))) # random times
>>> ts = nap.Ts(t=t, time_units='s')
>>> tsd = nap.Tsd(t=np.arange(0,1000), d=np.random.rand(1000), time_units='s')
>>> ep = nap.IntervalSet(start = 0, end = 500, time_units = 's')

The variable ts is a time series object containing only nan. The tsd object containing the values, for example the tracking data, and the epoch to restrict the operation.

>>> newts = ts.value_from(tsd, ep)

newts has the same size of ts restrict to ep.

>>> print(len(ts.restrict(ep)), len(newts))
    52 52