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:
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.jlpackage, one variable can hold the values of a time series, its time points, spatial coordinates, units, metadata, and more.It facilitates generic functions that dispatch on the various types of time series; for instance, more efficient algorithms can be written for
RegularTimeSeriestypes than forIrregularTimeSeriestypes, 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.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:
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.ToolsDimension Type
ToolsDimensionA union of all Dimension types that fall within the scope of TimeseriesTools. Analogous to DimensionalData.Dimension for dispatch purposes.
See also
sourceTimeseriesTools.AbstractTimeSeries Type
AbstractTimeSeries{T, N, B}A type alias for an AbstractDimArray with a time index.
sourceTimeseriesTools.AbstractToolsArray Type
A local type to avoid overloading and piracy issues with DimensionalData.jl
sourceTimeseriesTools.BinaryTimeSeries Type
BinaryTimeSeriesA type alias for a time series of bits.
sourceTimeseriesTools.IrregularIndex Type
IrregularIndexA type alias for an irregularly sampled dimension, wrapping an AbstractVector.
TimeseriesTools.IrregularTimeIndex Type
IrregularTimeIndexA type alias for a tuple of dimensions containing a TimeIndex and any number of other dimensions.
TimeseriesTools.IrregularTimeSeries Type
IrregularTimeSeriesA type alias for a potentially irregularly sampled time series.
sourceTimeseriesTools.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.
sourceTimeseriesTools.MultivariateTimeSeries Type
MultivariateTimeSeries{T}A type alias for a multivariate time series (A matrix, with a first Ti dimension and an arbitrary second dimension).
TimeseriesTools.RegularIndex Type
RegularIndexA type alias for a regularly sampled dimension, wrapping an AbstractRange.
TimeseriesTools.RegularTimeIndex Type
RegularTimeIndexA type alias for a tuple of dimensions containing a TimeIndex and any number of other dimensions.
TimeseriesTools.RegularTimeSeries Type
RegularTimeSeries{T, N, B}A type alias for a regularly sampled time series.
sourceTimeseriesTools.SpikeTrain Type
SpikeTrainA 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).
TimeseriesTools.TDim Type
TDim{S, T}The TimeseriesTools version of DimensionalData.Dim (custom dimensions named with a symbol)
Examples
See also
sourceTimeseriesTools.TimeIndex Type
TimeIndexA type alias for a tuple containing a time dimension and any number of other dimensions.
sourceTimeseriesTools.ToolsDim Type
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
sourceTimeseriesTools.UnivariateTimeSeries Type
UnivariateTimeSeries{T}A type alias for a time series with one variable (a vector with only a Ti dimension).
TimeseriesTools.Var Type
VarA DimensionalData.jl dimension representing the variables of a multivariate time series.
sourceTimeseriesTools.TimeSeries Method
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)TimeseriesTools.TimeSeries Method
TimeSeries(t, f::Function)Construct a time series by mapping a function f over the time points t.
TimeseriesTools.TimeSeries Method
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)