The TimeseriesTools package provides a standardized collection of types designed for handling various types of time-series data. Defining consistent types for time series provides three key benefits:

  1. It simplifies the workspace and method signatures by aggregating much of the data that defines a time series into a single variable; thanks to the DimensionalData.jl package, one variable can hold the values of a time series, its time points, spatial coordinates, units, metadata, and more.
  2. It facilitates generic functions that dispatch on the various types of time series; for instance, more efficient algorithms can be written for RegularTimeSeries types than for IrregularTimeSeries types, but the same high-level functionality can be provided by the same generic function that dispatches these methods given the type of the input time series.
  3. Most importantly, this intuitively aligns the structure of time-series data in code to mathematical conventions, which can vastly simplify the process of developing and interpreting programs. Many small complexities (Was this time series regularly sampled? What are the output frequencies of my Fourier transform? The units of my power spectrum?) are handled effortlessly, leaving room to focus on higher-level problems.

To achieve this, TimeseriesTools.jl defines a custom version of the DimensionalData.DimArray and custom DimensionalData.Dimensions:

x = Timeseries(1:10, rand(10))
x isa AbstractToolsArray # In most cases, an AbstractToolsArray behaves like a DimArray; see DimensionalData
x isa AbstractTimeSeries # An AbstractTimeSeries is an AbstractToolsArray...
lookup(x, 1) isa 𝑡 # ...where the first dimension is a custom TimeDim 𝑡

If a ToolsArray or DimArray has a 𝑡 as its first dimension, it will be rebuilt as a ToolsArray (i.e. when using functions like eachcol). There are a small number of other custom dimensions, all exported, that share this property and are subtypes of ToolsDimension: e.g. 𝑥, 𝑦, 𝑧, 𝑓,Var, Obs. To define more of these ToolsDimensions, use:

DimensionalData.@dim NewDim ToolsDim "NameOfNewDim"

Please note that functions operating on a ToolsArray without a ToolsDimension as the first or last dimension may NOT return a ToolsArray, especially if they perform slicing and rebuilding. Be careful using the DimensionalData.Dim{:name} syntax.

Below is a full list of types defined in this package.

TimeseriesTools.MultidimensionalTimeSeriesType

A multidimensional time series has a regular sampling over a dimension other than time; a one-dimensional time series can be thought of as a field over an even grid in 1 dimension that fluctuates over time.

source
TimeseriesTools.SpikeTrainType
SpikeTrain

A type alias for a spike-train time series, which contains spike times in the time dimension and true for all values corresponding to a spike. The spike times can be retrieved with times(x).

source
TimeseriesTools.ToolsDimType
ToolsDim{T}

An abstract type for custom macro-defined dimensions in TimeseriesTools. Analogous to DimensionalData.Dimension for the purposes of DimensionalData.@dim.

Examples

DimensionalData.@dim MyDim ToolsDim "My dimension" # Defines a new `ToolsDim <: ToolsDimension`

See also

source
TimeseriesTools.VarType
Var

A DimensionalData.jl dimension representing the variables of a multivariate time series.

source
TimeseriesTools.TimeSeriesMethod
TimeSeries(t, x)

Constructs a univariate time series with time t and data x. Alteratively, use TS(t, x)

Examples

julia> using TimeseriesTools, Unitful;
julia> t = 1:100
julia> x = rand(100)
julia> ts = TimeSeries(t, x)
julia> ts isa typeintersect(UnivariateTimeSeries, RegularTimeSeries)
source
TimeseriesTools.TimeSeriesMethod
TimeSeries(t, v, x)

Constructs a multivariate time series with time t, variable v, and data x.

Examples

julia> t = 1:100;
julia> v = [:a, :b, :c];
julia> x = rand(100, 3);
julia> mts = TimeSeries(t, v, x)
julia> mts isa typeintersect(MultivariateTimeSeries, RegularTimeSeries)
source