pynapple.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]))})
By default, the values of the Tsd is the index of the timestamp in the TsGroup:
>>> tsgroup.to_tsd() Time (s) ---------- -- 0 0 1 0 2 5 3 5 dtype: float64, shape: (4,)
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 3.14159 1 3.14159 2 6.28319 3 6.28319 dtype: float64, shape: (4,)
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 -1 1 -1 2 1 3 1 dtype: float64, shape: (4,)
The reverse operation can be done with the Tsd.to_tsgroup function :
>>> my_tsd = tsgroup.to_tsd() >>> my_tsd Time (s) ---------- -- 0 0 1 0 2 5 3 5 dtype: float64, shape: (4,) >>> my_tsd.to_tsgroup() Index rate ------- ------ 0 1 5 1
- Return type:
- Raises:
RuntimeError – “Metadata indices do not match” : 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