timeseries.TimeSeries
- class timeseries.TimeSeries(times: ndarray | List | Tuple = [], periodic: bool = False, t_start: float | None = None, t_stop: float | None = None, plotting_backend: str | None = None, name: str = 'unnamed')[source]
Bases:
object
Base class to represent a continuous or event-based time series. You should use the subclasses
TSContinuous
andTSEvent
to represent continuous-time and event-based time series, respectively. See Working with time series data for futher explanation and examples.Attributes overview
(float) Duration of TimeSeries
(str) Current plotting backend
(float) Start time of time series
(float) Stop time of time series (final sample)
(ArrayLike[float]) Array of sample times
Methods overview
__init__
([times, periodic, t_start, t_stop, ...])Represent a continuous or event-based time series
concatenate_t
(series[, offset])Append multiple TimeSeries objects in time to a new series
contains
(times)Does the time series contain the time range specified in the given time trace? Always true for periodic series
copy
()Return a deep copy of this time series
delay
(offset[, inplace])Return a copy of
self
that is delayed by an offsetisempty
()Test if this
TimeSeries
object is emptyload
(path[, expected_type])Load TimeSeries object from file.
print
()Print an overview of the time series
set_plotting_backend
(backend[, verbose])Set which plotting backend to use with the
plot
methodstart_at
(t_start[, inplace])Convenience function that calls the
delay
method such thatself.t_start
falls att_start
.start_at_zero
([inplace])Convenience function that calls the
delay
method such thatself.t_start
falls at0
.- __init__(times: ndarray | List | Tuple = [], periodic: bool = False, t_start: float | None = None, t_stop: float | None = None, plotting_backend: str | None = None, name: str = 'unnamed')[source]
Represent a continuous or event-based time series
- Parameters:
times (ArrayLike) – [Tx1] vector of time samples
periodic (bool) – Treat the time series as periodic around the end points. Default:
False
t_start (Optional[float]) – If not
None
, the series start time ist_start
, otherwisetimes[0]
t_stop (Optional[float]) – If not
None
, the series stop time ist_stop
, otherwisetimes[-1]
plotting_backend (Optional[str]) – Determines plotting backend. If
None
, backend will be chosen automatically based on what is available.name (str) – Name of the
TimeSeries
object. Default: “unnamed”
- _modulo_period(times: ndarray | List | Tuple | float | int) ndarray | List | Tuple | float | int [source]
_modulo_period - Calculate provided times modulo
self.duration
- classmethod concatenate_t(series: Iterable[TS], offset: None | float | Iterable[float | None] = None) TS [source]
Append multiple TimeSeries objects in time to a new series
- Parameters:
series (Iterable) – Time series to be tacked at the end of each other. These series must have the same number of channels.
offset (Union[None, float, Iterable]) – Offset to be introduced between time traces. First value corresponds to delay of first time series.
- Return TimeSeries:
Time series with data from series in
series
- contains(times: int | float | ndarray | List | Tuple) bool [source]
Does the time series contain the time range specified in the given time trace? Always true for periodic series
- Parameters:
times (ArrayLike) – Array-like containing time points
- Return bool:
True iff all specified time points are contained within this time series
- delay(offset: int | float, inplace: bool = False) TS [source]
Return a copy of
self
that is delayed by an offsetFor delaying self, use the
inplace
argument, or.times += ...
instead.- Parameters:
Offset (float) – Time by which to offset this time series
inplace (bool) – If
True
, conduct operation in-place (Default:False
; create a copy)
- Return TimeSeries:
New
TimeSeries
, delayed
- property duration: float
(float) Duration of TimeSeries
- isempty() bool [source]
Test if this
TimeSeries
object is empty- Return bool:
True
iff theTimeSeries
object contains no samples
- classmethod load(path: str | Path, expected_type: str | None = None) TS [source]
Load TimeSeries object from file. If called from a subclass of :py:class’TimeSeries`, the type of the stored object must match that of the method class.
- Parameters:
path (Union[str, Path]) – Path to load from.
expected_type (Optional[str]) – Specify expected type of timeseires (
TSContinuous
or py:class:TSEvent
). Can only be set if method is called from py:class:TimeSeries
class. Default:None
, use whichever type is loaded.
- Return TimeSeries:
Loaded time series object
- Raises:
TypeError – Unsupported or unexpected type
TypeError – Argument
expected_type
is defined if class is notTimeSeries
.
- property name: str
- property plotting_backend
(str) Current plotting backend
- set_plotting_backend(backend: str | None, verbose: bool = True)[source]
Set which plotting backend to use with the
plot
method- Parameters:
backend (str) – Specify a backend to use. Supported: {“holoviews”, “matplotlib”}
verbose (bool) – If True, print feedback about which backend has been set
- start_at(t_start: float, inplace: bool = False) TS [source]
Convenience function that calls the
delay
method such thatself.t_start
falls att_start
.- Parameters:
t_start (float) – Time to which
self.t_start
should be shifted;inplace (bool) – If
True
, conduct operation in-place (Default:False
; create a copy)
- Return TimeSeries:
New
TimeSeries
, delayed
- start_at_zero(inplace: bool = False) TS [source]
Convenience function that calls the
delay
method such thatself.t_start
falls at0
.- Return TimeSeries:
New TimeSeries, with t_start at 0
- property t_start: float
(float) Start time of time series
- property t_stop: float
(float) Stop time of time series (final sample)
- property times
(ArrayLike[float]) Array of sample times