Skip to content

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, simplifying 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 automatically, 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:

julia
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:

julia
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.ToolsDimension Type
julia
ToolsDimension

A union of all Dimension types that fall within the scope of TimeseriesTools. Analogous to DimensionalData.Dimension for dispatch purposes.

See also

source
TimeseriesTools.AbstractTimeSeries Type
julia
AbstractTimeSeries{T, N, B}

A type alias for an AbstractDimArray with a time index.

source
TimeseriesTools.AbstractToolsArray Type

A local type to avoid overloading and piracy issues with DimensionalData.jl

source
TimeseriesTools.BinaryTimeSeries Type
julia
BinaryTimeSeries

A type alias for a time series of bits.

source
TimeseriesTools.IrregularIndex Type
julia
IrregularIndex

A type alias for an irregularly sampled dimension, wrapping an AbstractVector.

source
TimeseriesTools.IrregularTimeIndex Type
julia
IrregularTimeIndex

A type alias for a tuple of dimensions containing a TimeIndex and any number of other dimensions.

source
TimeseriesTools.IrregularTimeSeries Type
julia
IrregularTimeSeries

A type alias for a potentially irregularly sampled time series.

source
TimeseriesTools.MultidimensionalTimeSeries Type

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.MultivariateTimeSeries Type
julia
MultivariateTimeSeries{T}

A type alias for a multivariate time series (A matrix, with a first Ti dimension and an arbitrary second dimension).

source
TimeseriesTools.RegularIndex Type
julia
RegularIndex

A type alias for a regularly sampled dimension, wrapping an AbstractRange.

source
TimeseriesTools.RegularTimeIndex Type
julia
RegularTimeIndex

A type alias for a tuple of dimensions containing a TimeIndex and any number of other dimensions.

source
TimeseriesTools.RegularTimeSeries Type
julia
RegularTimeSeries{T, N, B}

A type alias for a regularly sampled time series.

source
TimeseriesTools.SpikeTrain Type
julia
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.TDim Type
julia
TDim{S, T}

The TimeseriesTools version of DimensionalData.Dim (custom dimensions named with a symbol)

Examples

See also

source
TimeseriesTools.TimeIndex Type
julia
TimeIndex

A type alias for a tuple containing a time dimension and any number of other dimensions.

source
TimeseriesTools.ToolsDim Type
julia
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.UnivariateTimeSeries Type
julia
UnivariateTimeSeries{T}

A type alias for a time series with one variable (a vector with only a Ti dimension).

source
TimeseriesTools.Var Type
julia
Var

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

source
TimeseriesTools.TimeSeries Method
julia
TimeSeries(t, x)

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

Examples

@example
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.TimeSeries Method
julia
TimeSeries(t, f::Function)

Construct a time series by mapping a function f over the time points t.

source
TimeseriesTools.TimeSeries Method
julia
TimeSeries(t, v, x)

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

Examples

@example
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