pynapple.core.ts_group.TsGroup.to_tsd#

TsGroup.to_tsd(*args)[source]#

Convert TsGroup to a Tsd. The timestamps of the TsGroup are merged together and sorted.

Parameters:

*args – string, list, numpy.ndarray or pandas.Series

Examples

>>> import pynapple as nap
>>> import numpy as np
>>> tsgroup = nap.TsGroup({0:nap.Ts(t=np.array([0, 1])), 5:nap.Ts(t=np.array([2, 3]))})
Index    rate
-------  ------
0       1
5       1

By default, the values of the Tsd is the index of the timestamp in the TsGroup:

>>> tsgroup.to_tsd()
Time (s)
0.0    0.0
1.0    0.0
2.0    5.0
3.0    5.0
dtype: float64

Values can be inherited from the metadata of the TsGroup by giving the key of the corresponding columns.

>>> tsgroup.set_info( phase=np.array([np.pi, 2*np.pi]) ) # assigning a phase to my 2 elements of the TsGroup
>>> tsgroup.to_tsd("phase")
Time (s)
0.0    3.141593
1.0    3.141593
2.0    6.283185
3.0    6.283185
dtype: float64

Values can also be passed directly to the function from a list, numpy.ndarray or pandas.Series of values as long as the length matches :

>>> tsgroup.to_tsd([-1, 1])
Time (s)
0.0   -1.0
1.0   -1.0
2.0    1.0
3.0    1.0
dtype: float64

The reverse operation can be done with the Tsd.to_tsgroup function :

>>> my_tsd
Time (s)
0.0    0.0
1.0    0.0
2.0    5.0
3.0    5.0
dtype: float64
>>> my_tsd.to_tsgroup()
  Index    rate
-------  ------
      0       1
      5       1
Return type:

Tsd

Raises:

RuntimeError – “Index are not equals” : if pandas.Series indexes don’t match the TsGroup indexes “Values is not the same length” : if numpy.ndarray/list object is not the same size as the TsGroup object “Key not in metadata of TsGroup” : if string argument does not match any column names of the metadata, “Unknown argument format” ; if argument is not a string, list, numpy.ndarray or pandas.Series