pynapple.TsdFrame#
- class pynapple.TsdFrame(t, d=None, time_units='s', time_support=None, columns=None, load_array=True, metadata=None)[source]#
Bases:
_BaseTsd
,_MetadataMixin
Column-based container for neurophysiological time series. A pandas.DataFrame can be passed directly.
- Parameters:
t (numpy.ndarray or pandas.DataFrame) – the time index t, or a pandas.DataFrame (if d is None)
d (numpy.ndarray) – The data
time_units (str, optional) – The time units in which times are specified (‘us’, ‘ms’, ‘s’ [default]).
time_support (IntervalSet, optional) – The time support of the TsdFrame object
columns (iterables) – Column names
load_array (bool, optional) – Whether the data should be converted to a numpy (or jax) array. Useful when passing a memory map object like zarr. Default is True. Does not apply if d is already a numpy array or a numpy memory map.
metadata (pd.DataFrame or dict, optional) – Metadata associated with data columns. Metadata names are pulled from DataFrame columns or dictionary keys. The length of the metadata should match the number of data columns. If a DataFrame is passed, the index should match the columns of the TsdFrame.
Examples
Initialize a TsdFrame:
>>> import pynapple as nap >>> import numpy as np >>> t = np.arange(100) >>> d = np.ones((100, 3)) >>> tsdframe = nap.TsdFrame(t=t, d=d) >>> tsdframe Time (s) 0 1 2 ---------- --- --- --- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 ... ... ... ... 95.0 1.0 1.0 1.0 96.0 1.0 1.0 1.0 97.0 1.0 1.0 1.0 98.0 1.0 1.0 1.0 99.0 1.0 1.0 1.0 dtype: float64, shape: (100, 3)
Initialize a TsdFrame with column names:
>>> tsdframe = nap.TsdFrame(t=t, d=d, columns=['A', 'B', 'C']) >>> tsdframe Time (s) A B C ---------- --- --- --- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 ... ... ... ... 95.0 1.0 1.0 1.0 96.0 1.0 1.0 1.0 97.0 1.0 1.0 1.0 98.0 1.0 1.0 1.0 99.0 1.0 1.0 1.0 dtype: float64, shape: (100, 3)
Initialize a TsdFrame with metadata:
>>> metadata = {"color": ["red", "blue", "green"], "depth": [1, 2, 3]} >>> tsdframe = nap.TsdFrame(t=t, d=d, columns=["A", "B", "C"], metadata=metadata) >>> tsdframe Time (s) A B C ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 ... ... ... ... 95.0 1.0 1.0 1.0 96.0 1.0 1.0 1.0 97.0 1.0 1.0 1.0 98.0 1.0 1.0 1.0 99.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green depth 1 2 3 dtype: float64, shape: (100, 3)
Initialize a TsdFrame with a pandas DataFrame:
>>> import pandas as pd >>> data = pd.DataFrame(index=t, columns=["A", "B", "C"], data=d) >>> metadata = pd.DataFrame( ... index=["A", "B", "C"], ... columns=["color", "depth"], ... data=[["red", 1], ["blue", 2], ["green", 3]], ... ) >>> tsdframe = nap.TsdFrame(data, metadata=metadata) >>> tsdframe Time (s) A B C ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 ... ... ... ... 95.0 1.0 1.0 1.0 96.0 1.0 1.0 1.0 97.0 1.0 1.0 1.0 98.0 1.0 1.0 1.0 99.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green depth 1 2 3 dtype: float64, shape: (100, 3)
- __init__(t, d=None, time_units='s', time_support=None, columns=None, load_array=True, metadata=None)[source]#
Methods
__init__
(t[, d, time_units, time_support, ...])as_array
()Return the data.
Convert the TsdFrame object to a pandas.DataFrame object.
as_units
([units])Returns a DataFrame with time expressed in the desired unit.
bin_average
(bin_size[, ep, time_units])Bin the data by averaging points within bin_size bin_size should be seconds unless specified.
convolve
(array[, ep, trim])Return the discrete linear convolution of the time series with a one dimensional sequence.
copy
()Copy the data, index and time support
count
([bin_size, ep, time_units, dtype])Count occurences of events within bin_size or within a set of bins defined as an IntervalSet.
data
()Return the data.
dropna
([update_time_support])Drop every row containing NaNs.
end_time
([units])The last time index in the time series object
find_support
(min_gap[, time_units])find the smallest (to a min_gap resolution) IntervalSet containing all the times in the Tsd
get
(start[, end, time_units])Slice the time series from start to end such that all the timestamps satisfy start<=t<=end.
get_info
(key)Returns metadata based on metadata column name or index.
get_slice
(start[, end, time_unit])Get a slice object from the time series data based on the start and end values such that all the timestamps satisfy start<=t<=end.
interpolate
(ts[, ep, left, right])Wrapper of the numpy linear interpolation method.
restrict
(iset)Restricts a time series object to a set of time intervals delimited by an IntervalSet object
save
(filename)Save TsdFrame object in npz format.
set_info
([metadata])Add metadata information about the object.
smooth
(std[, windowsize, time_units, ...])Smooth a time series with a gaussian kernel.
start_time
([units])The first time index in the time series object
times
([units])The time index of the object, returned as np.double in the desired time units.
to_numpy
()Return the data as a numpy.ndarray.
value_from
(data[, ep])Replace the value with the closest value from Tsd/TsdFrame/TsdTensor argument
Attributes
The last time index in the time series
Returns a read-only version (copy) of the _metadata DataFrame
List of metadata column names.
The shape of the time series
The first time index in the time series
The time index of the time series
Data column names of the TsdFrame
An array of the time series data
The time index of the time series
Frequency of the time series (Hz) computed over the time support
The time support of the time series
Row index for metadata DataFrame.
- as_array()#
Return the data.
- Returns:
out – _
- Return type:
array-like
- as_dataframe()[source]#
Convert the TsdFrame object to a pandas.DataFrame object.
- Returns:
out – _
- Return type:
pandas.DataFrame
- as_units(units='s')[source]#
Returns a DataFrame with time expressed in the desired unit.
- Parameters:
units (str, optional) – (‘us’, ‘ms’, ‘s’ [default])
- Returns:
the series object with adjusted times
- Return type:
pandas.DataFrame
- bin_average(bin_size, ep=None, time_units='s')#
Bin the data by averaging points within bin_size bin_size should be seconds unless specified. If no epochs is passed, the data will be binned based on the time support.
- Parameters:
bin_size (float) – The bin size (default is second)
ep (None or IntervalSet, optional) – IntervalSet to restrict the operation
time_units (str, optional) – Time units of bin size (‘us’, ‘ms’, ‘s’ [default])
- Returns:
out – A Tsd object indexed by the center of the bins and holding the averaged data points.
- Return type:
Examples
This example shows how to bin data within bins of 0.1 second.
>>> import pynapple as nap >>> import numpy as np >>> tsd = nap.Tsd(t=np.arange(100), d=np.random.rand(100)) >>> bintsd = tsd.bin_average(0.1)
An epoch can be specified:
>>> ep = nap.IntervalSet(start = 10, end = 80, time_units = 's') >>> bintsd = tsd.bin_average(0.1, ep=ep)
And bintsd automatically inherit ep as time support:
>>> bintsd.time_support >>> start end >>> 0 10.0 80.0
- columns: Index#
Data column names of the TsdFrame
- convolve(array, ep=None, trim='both')#
Return the discrete linear convolution of the time series with a one dimensional sequence.
A parameter ep can control the epochs for which the convolution will apply. Otherwise the convolution is made over the time support.
This function assume a constant sampling rate of the time series.
The only mode supported is full. The returned object is trimmed to match the size of the original object. The parameter trim controls which side the trimming operates. Default is ‘both’.
See the numpy documentation here : https://numpy.org/doc/stable/reference/generated/numpy.convolve.html
- Parameters:
array (array-like) – 1-D or 2-D array with kernel(s) to be used for convolution. First dimension is assumed to be time.
ep (None, optional) – The epochs to apply the convolution
trim (str, optional) – The side on which to trim the output of the convolution (‘left’, ‘right’, ‘both’ [default])
- Returns:
The convolved time series
- Return type:
- copy()#
Copy the data, index and time support
- count(bin_size=None, ep=None, time_units='s', dtype=None)#
Count occurences of events within bin_size or within a set of bins defined as an IntervalSet. You can call this function in multiple ways :
1. tsd.count(bin_size=1, time_units = ‘ms’) -> Count occurence of events within a 1 ms bin defined on the time support of the object.
2. tsd.count(1, ep=my_epochs) -> Count occurent of events within a 1 second bin defined on the IntervalSet my_epochs.
3. tsd.count(ep=my_bins) -> Count occurent of events within each epoch of the intervalSet object my_bins
4. tsd.count() -> Count occurent of events within each epoch of the time support.
bin_size should be seconds unless specified. If bin_size is used and no epochs is passed, the data will be binned based on the time support of the object.
- Parameters:
bin_size (None or float, optional) – The bin size (default is second)
ep (None or IntervalSet, optional) – IntervalSet to restrict the operation
time_units (str, optional) – Time units of bin size (‘us’, ‘ms’, ‘s’ [default])
dtype (type, optional) – Data type for the count. Default is np.int64.
- Returns:
out – A Tsd object indexed by the center of the bins.
- Return type:
Examples
This example shows how to count events within bins of 0.1 second.
>>> import pynapple as nap >>> import numpy as np >>> t = np.unique(np.sort(np.random.randint(0, 1000, 100))) >>> ts = nap.Ts(t=t, time_units='s') >>> bincount = ts.count(0.1)
An epoch can be specified:
>>> ep = nap.IntervalSet(start = 100, end = 800, time_units = 's') >>> bincount = ts.count(0.1, ep=ep)
And bincount automatically inherit ep as time support:
>>> bincount.time_support start end 0 100.0 800.0
- property d#
- data()#
Return the data.
- Returns:
out – _
- Return type:
array-like
- dropna(update_time_support=True)#
Drop every row containing NaNs. By default, the time support is updated to start and end around the time points that are non NaNs. To change this behavior, you can set update_time_support=False.
- property end#
The last time index in the time series
- end_time(units='s')#
The last time index in the time series object
- Parameters:
units (str, optional) – (‘us’, ‘ms’, ‘s’ [default])
- Returns:
out – _
- Return type:
numpy.float64
- find_support(min_gap, time_units='s')#
find the smallest (to a min_gap resolution) IntervalSet containing all the times in the Tsd
- Parameters:
min_gap (float or int) – minimal interval between timestamps
time_units (str, optional) – Time units of min gap
- Returns:
Description
- Return type:
- get(start, end=None, time_units='s')#
Slice the time series from start to end such that all the timestamps satisfy start<=t<=end. If end is None, only the timepoint closest to start is returned.
By default, the time support doesn’t change. If you want to change the time support, use the restrict function.
- Parameters:
start (float or int) – The start (or closest time point if end is None)
end (float or int or None) – The end
- get_info(key)[source]#
Returns metadata based on metadata column name or index.
If the metadata name does not contain special nor overlaps with class attributes, it can also be accessed as an attribute.
If the metadata name does not overlap with class-reserved keys, it can also be accessed as a key.
- Parameters:
key –
str: metadata column name or metadata index (for TsdFrame with string column names)
list of str: multiple metadata column names or metadata indices (for TsdFrame with string column names)
Number: metadata index (for TsGroup and IntervalSet)
list, np.ndarray, pd.Series: metadata index (for TsGroup and IntervalSet)
tuple: metadata index and column name (for TsGroup and IntervalSet)
- Returns:
The metadata information based on the key provided.
- Return type:
pandas.Series or pandas.DataFrame or Any (for single location)
- Raises:
IndexError – If the metadata index is not found.
Examples
>>> import pynapple as nap >>> import numpy as np >>> metadata = {"l1": [1, 2, 3], "l2": ["x", "x", "y"]} >>> tsdframe = nap.TsdFrame(t=np.arange(5), d=np.ones((5, 3)), metadata=metadata) >>> print(tsdframe) Time (s) 0 1 2 ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- l1 1 2 3 l2 x x y dtype: float64, shape: (5, 3)
To access a single metadata column:
>>> tsdframe.get_info("l1") 0 1 1 2 2 3 Name: l1, dtype: int64
To access multiple metadata columns:
>>> tsdframe.get_info(["l1", "l2"]) l1 l2 0 1 x 1 2 x 2 3 y
To access metadata of a single column:
>>> tsdframe.get_info(0) rate 0.667223 l1 1 l2 x Name: 0, dtype: object
To access metadata of multiple columns:
>>> tsdframe.get_info([0, 1]) rate l1 l2 0 0.667223 1 x 1 1.334445 2 x
To access metadata of a single column and metadata key:
>>> tsdframe.get_info((0, "l1")) np.int64(1)
To access metadata as an attribute:
>>> tsdframe.l1 0 1 1 2 2 3 Name: l1, dtype: int64
To access metadata as a key:
>>> tsdframe["l1"] 0 1 1 2 2 3 Name: l1, dtype: int64
Multiple metadata columns can be accessed as keys:
>>> tsdframe[["l1", "l2"]] l1 l2 0 1 x 1 2 x 2 3 y
- get_slice(start, end=None, time_unit='s')#
Get a slice object from the time series data based on the start and end values such that all the timestamps satisfy start<=t<=end. If end is None, only the timepoint closest to start is returned.
By default, the time support doesn’t change. If you want to change the time support, use the restrict function.
This function is equivalent of calling the get method.
- Parameters:
start (int or float) – The starting value for the slice.
end (int or float, optional) – The ending value for the slice. Defaults to None.
time_unit (str, optional) – The time unit for the start and end values. Defaults to “s” (seconds).
- Returns:
slice – A slice determining the start and end indices, with unit step Slicing the array will be equivalent to calling get: ts[s].t == ts.get(start, end).t with s being the slice object.
- Return type:
slice
- Raises:
ValueError –
If start or end is not a number. - If start is greater than end.
Examples
>>> import pynapple as nap
>>> ts = nap.Ts(t = [0, 1, 2, 3])
>>> # slice over a range >>> start, end = 1.2, 2.6 >>> print(ts.get_slice(start, end)) # returns `slice(2, 3, None)` >>> start, end = 1., 2. >>> print(ts.get_slice(start, end, mode="forward")) # returns `slice(1, 3, None)`
>>> # slice a single value >>> start = 1.2 >>> print(ts.get_slice(start)) # returns `slice(1, 2, None)` >>> start = 2. >>> print(ts.get_slice(start)) # returns `slice(2, 3, None)`
- index: TsIndex#
The time index of the time series
- interpolate(ts, ep=None, left=None, right=None)#
Wrapper of the numpy linear interpolation method. See [numpy interpolate](https://numpy.org/doc/stable/reference/generated/numpy.interp.html) for an explanation of the parameters. The argument ts should be Ts, Tsd, TsdFrame, TsdTensor to ensure interpolating from sorted timestamps in the right unit,
- Parameters:
ts (Ts, Tsd, TsdFrame or TsdTensor) – The object holding the timestamps
ep (IntervalSet, optional) – The epochs to use to interpolate. If None, the time support of Tsd is used.
left (None, optional) – Value to return for ts < tsd[0], default is tsd[0].
right (None, optional) – Value to return for ts > tsd[-1], default is tsd[-1].
- property loc#
- property metadata#
Returns a read-only version (copy) of the _metadata DataFrame
- property metadata_columns#
List of metadata column names.
- metadata_index: np.ndarray | pd.Index#
Row index for metadata DataFrame. This matches the index for TsGroup and IntervalSet, and the columns for TsdFrame.
- property ndim#
- rate: float#
Frequency of the time series (Hz) computed over the time support
- restrict(iset)#
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
The Ts object is restrict to the intervals defined by ep.
>>> import pynapple as nap >>> import numpy as np >>> t = np.unique(np.sort(np.random.randint(0, 1000, 100))) >>> ts = nap.Ts(t=t, time_units='s') >>> ep = nap.IntervalSet(start=0, end=500, time_units='s') >>> newts = ts.restrict(ep)
The time support of newts automatically inherit the epochs defined by ep.
>>> newts.time_support start end 0 0.0 500.0
- save(filename)[source]#
Save TsdFrame object in npz format. The file will contain the timestamps, the data and the time support.
The main purpose of this function is to save small/medium sized time series objects. For example, you extracted several channels from your recording and filtered them. You can save the filtered channels as a npz to avoid reprocessing it.
You can load the object with nap.load_file. Keys are ‘t’, ‘d’, ‘start’, ‘end’, ‘type’ and ‘columns’ for columns names.
- Parameters:
filename (str) – The filename
Examples
>>> import pynapple as nap >>> import numpy as np >>> tsdframe = nap.TsdFrame(t=np.array([0., 1.]), d = np.array([[2, 3],[4,5]]), columns=['a', 'b']) >>> tsdframe.save("my_path/my_tsdframe.npz")
To load you file, you can use the nap.load_file function :
>>> tsdframe = nap.load_file("my_path/my_tsdframe.npz") >>> tsdframe a b Time (s) 0.0 2 3 1.0 4 5
- Raises:
RuntimeError – If filename is not str, path does not exist or filename is a directory.
- set_info(metadata=None, **kwargs)[source]#
Add metadata information about the object. Metadata are saved as a pandas.DataFrame.
If the metadata name does not contain special nor overlaps with class attributes, it can also be set using attribute assignment.
If the metadata name does not overlap with class-reserved keys, it can also be set using key assignment.
Metadata entries (excluding “rate” for TsGroup) are mutable and can be overwritten.
- Parameters:
metadata (pandas.DataFrame or dict or pandas.Series, optional) –
Object containing metadata information, where metadata names are extracted from column names (pandas.DataFrame), key names (dict), or index (pandas.DataFrame).
If a pandas.DataFrame is passed, the index must match the metadata index.
If a dictionary is passed, the length of each value must match the metadata index length.
A pandas.Series can only be passed if the object has a single interval.
**kwargs (optional) – Key-word arguments for setting metadata. Values can be either pandas.Series, numpy.ndarray, list or tuple, and must have the same length as the metadata index. If pandas.Series, the index must match the metadata index. If the object only has one index, non-iterable values are also accepted.
- Raises:
ValueError –
If metadata index does not match input index (pandas.DataFrame, pandas.Series) - If input array length does not match metadata length (numpy.ndarray, list, tuple)
RuntimeError – If the metadata argument is passed as a pandas.Series (for more than one metadata index), numpy.ndarray, list or tuple.
TypeError – If key-word arguments are not of type pandas.Series, tuple, list, or numpy.ndarray and cannot be set.
Examples
>>> import pynapple as nap >>> import numpy as np >>> tsdframe = nap.TsdFrame(t=np.arange(5), d=np.ones((5, 3)), columns=["a", "b", "c"])
To add metadata with a pandas.DataFrame:
>>> import pandas as pd >>> metadata = pd.DataFrame(index=tsdframe.columns, data=["red", "blue", "green"], columns=["color"]) >>> tsdframe.set_info(metadata) >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green dtype: float64, shape: (5, 3)
To add metadata with a dictionary:
>>> metadata = {"xpos": [10, 20, 30]} >>> tsdframe.set_info(metadata) >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green xpos 10 20 30 dtype: float64, shape: (5, 3)
To add metadata with a keyword arument (pd.Series, numpy.ndarray, list or tuple):
>>> ypos = pd.Series(index=tsdframe.columns, data = [10, 10, 10]) >>> tsdframe.set_info(ypos=ypos) >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green xpos 10 20 30 ypos 10 10 10 dtype: float64, shape: (5, 3)
To add metadata as an attribute:
>>> tsdframe.label = ["a", "b", "c"] >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green xpos 10 20 30 ypos 10 10 10 label a b c dtype: float64, shape: (5, 3)
To add metadata as a key:
>>> tsdframe["region"] = ["M1", "M1", "M2"] >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green xpos 10 20 30 ypos 10 10 10 label a b c region M1 M1 M2 dtype: float64, shape: (5, 3)
Metadata can be overwritten:
>>> tsdframe.set_info(label=["x", "y", "z"]) >>> tsdframe Time (s) a b c ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- color red blue green xpos 10 20 30 ypos 10 10 10 label x y z region M1 M1 M2 dtype: float64, shape: (5, 3)
- property shape#
The shape of the time series
- property size#
- smooth(std, windowsize=None, time_units='s', size_factor=100, norm=True)#
Smooth a time series with a gaussian kernel.
std is the standard deviation of the gaussian kernel in units of time. If only std is passed, the function will compute the standard deviation and size in number of time points automatically based on the sampling rate of the time series. For example, if the time series tsd has a sample rate of 100 Hz and std is 50 ms, the standard deviation will be converted to an integer through tsd.rate * std = int(100 * 0.05) = 5.
If windowsize is None, the function will select a kernel size as 100 times the std in number of time points. This behavior can be controlled with the parameter size_factor.
norm set to True normalizes the gaussian kernel to sum to 1.
In the following example, a time series tsd with a sampling rate of 100 Hz is convolved with a gaussian kernel. The standard deviation is 0.05 second and the windowsize is 2 second. When instantiating the gaussian kernel from scipy, it corresponds to parameters M = 200 and std=5
>>> tsd.smooth(std=0.05, windowsize=2, time_units='s', norm=False)
This line is equivalent to :
>>> from scipy.signal.windows import gaussian >>> kernel = gaussian(M = 200, std=5) >>> tsd.convolve(window)
It is generally a good idea to visualize the kernel before applying any convolution.
See the scipy documentation for the [gaussian window](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.windows.gaussian.html)
- Parameters:
std (Number) – Standard deviation in units of time
windowsize (Number) – Size of the gaussian window in units of time.
time_units (str, optional) – The time units in which std and windowsize are specified (‘us’, ‘ms’, ‘s’ [default]).
size_factor (int, optional) – How long should be the kernel size as a function of the standard deviation. Default is 100. Bypassed if windowsize is used.
norm (bool, optional) – Whether to normalized the gaussian kernel or not. Default is True.
- Returns:
Time series convolved with a gaussian kernel
- Return type:
- property start#
The first time index in the time series
- start_time(units='s')#
The first time index in the time series object
- Parameters:
units (str, optional) – (‘us’, ‘ms’, ‘s’ [default])
- Returns:
out – _
- Return type:
numpy.float64
- property t#
The time index of the time series
- time_support: IntervalSet#
The time support of the time series
- times(units='s')#
The time index of the object, returned as np.double in the desired time units.
- Parameters:
units (str, optional) – (‘us’, ‘ms’, ‘s’ [default])
- Returns:
out – the time indexes
- Return type:
numpy.ndarray
- to_numpy()#
Return the data as a numpy.ndarray.
Mostly useful for matplotlib plotting when calling plot(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:
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 timestamp object. 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 is the same size as ts restrict to ep.
>>> print(len(ts.restrict(ep)), len(newts)) 52 52
- values: np.ndarray#
An array of the time series data