TimeseriesUtilities

Documentation for TimeseriesUtilities.

Most of the utilities operate on the time dimension by default, but you can specify other dimensions using the dim or query parameter.

TimeseriesUtilities.TimeseriesUtilitiesModule
TimeseriesUtilities

A collection of utilities to simplify common time series analysis.

From data cleaning to arithmetic operations (e.g. linear algebra) to common time series operations (e.g. resampling, filtering).

Data Cleaning

Query

(Windowed) Statistics

Algebra

Time-Domain Operations

Time-Frequency Domain Operations

source

Installation

using Pkg
Pkg.add("TimeseriesUtilities")

API Reference

TimeseriesUtilities.TimeseriesUtilitiesModule
TimeseriesUtilities

A collection of utilities to simplify common time series analysis.

From data cleaning to arithmetic operations (e.g. linear algebra) to common time series operations (e.g. resampling, filtering).

Data Cleaning

Query

(Windowed) Statistics

Algebra

Time-Domain Operations

Time-Frequency Domain Operations

source
TimeseriesUtilities.DiffQType
DiffQ(v, t; dim=1)

Difference quotient of v with respect to t.

To avoid undefined behavior for division by Date/DateTime, we convert the time difference to a Unitful.Quantity if eltype(v) is not a Unitful.Quantity.

source
TimeseriesUtilities.dimnumFunction
dimnum(x, query)

Get the number(s) of Dimension(s) as ordered in the dimensions of an object.

Extend the function for custom type x. By default, we fall back to DimensionalData.dimnum.

source
TimeseriesUtilities.dropnaMethod
dropna(A; dim=nothing)
dropna(A::AbstractDimArray; dim=nothing, query=nothing)

Remove slices containing NaN values along along the dim dimension.

source
TimeseriesUtilities.find_outliersMethod
find_outliers(A, [method, window]; dim = 1, kw...)

Find outliers in data A along the specified dim dimension.

Returns a Boolean array whose elements are true when an outlier is detected in the corresponding element of A.

The default method is :median (other option is :mean), which uses the median absolute deviation (MAD) to detect outliers. When the length of A is greater than 256, it uses a moving window of size 16.

See also: find_outliers_median, find_outliers_mean, isoutlier - MATLAB

source
TimeseriesUtilities.replace_outliers!Method
replace_outliers!(A, method, [find_method, window]; kwargs...)
replace_outliers!(A, method, outliers; kwargs...)

Replaces outliers in A with values determined by the specified method.

Outliers can be detected using find_outliers with optional find_method and window parameters or specified directly as a Boolean array outliers.

method can be one of the following:

  • :linear: Linear interpolation of neighboring, nonoutlier values
  • :previous: Previous nonoutlier value
  • :next: Next nonoutlier value
  • :nearest: Nearest nonoutlier value

See also: filloutliers - MATLAB

source
TimeseriesUtilities.smoothMethod
smooth(da::AbstractDimArray, window; dim=Ti, suffix="_smoothed", kwargs...)

Smooths a time series by computing a moving average over a sliding window.

The size of the sliding window can be either:

  • Quantity: A time duration that will be converted to number of samples based on data resolution
  • Integer: Number of samples directly

Arguments

  • dims=Ti: Dimension along which to perform smoothing (default: time dimension)
  • suffix="_smoothed": Suffix to append to the variable name in output
  • kwargs...: Additional arguments passed to RollingWindowArrays.rolling
source
TimeseriesUtilities.tclipMethod
tclip(A, t0, t1; query=nothing, sort=false)

Clip a Dimension or DimArray A to a time range [t0, t1].

For unordered dimensions, the dimension should be sorted before clipping (see tsort).

source
TimeseriesUtilities.tclipsMethod
tclips(xs...; trange=common_timerange(xs...))

Clip multiple arrays to a common time range trange.

If trange is not provided, automatically finds the common time range across all input arrays.

source
TimeseriesUtilities.tcrossMethod
tcross(x, y; dim = nothing, query=nothing)

Compute the cross product of two (arrays of) vectors along the specified dimension dim or query.

References:

  • https://docs.xarray.dev/en/stable/generated/xarray.cross.html
source
TimeseriesUtilities.tfilterFunction
tfilter(da, Wn1, Wn2=samplingrate(da) / 2; designmethod=nothing)

By default, the max frequency corresponding to the Nyquist frequency is used.

References

  • https://docs.juliadsp.org/stable/filters/
  • https://www.mathworks.com/help/signal/ref/filtfilt.html
  • https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html

Issues

  • DSP.jl and Unitful.jl: https://github.com/JuliaDSP/DSP.jl/issues/431
source
TimeseriesUtilities.time_gridMethod
time_grid(x, dt)

Create a time grid from the minimum to maximum time in x with the step size dt.

Examples

# Create hourly time grid
time_grid(x, Hour(1))
time_grid(x, 1u"hr")

# Create 1-s intervals
time_grid(x, Second(1))
time_grid(x, 1u"second")
time_grid(x, 1u"Hz")
source
TimeseriesUtilities.timerangeMethod
timerange(times)
timerange(x1, xs...)

Get the time range (minimum and maximum) of time series data.

For a single argument, returns a tuple (tmin, tmax) containing the minimum and maximum times. For multiple arguments, returns the common time range (intersection) across all arrays - equivalent to common_timerange(x1, xs...).

Examples

# Single time series
times = [1, 2, 3, 4, 5]
timerange(times)  # (1, 5)

# Multiple time series - find common range
x1_times = [1, 2, 3, 4]
x2_times = [2, 3, 4, 5]
timerange(x1_times, x2_times)  # (2, 4)

See also: common_timerange, tminimum, tmaximum

source
TimeseriesUtilities.tmask!Method
tmask!(da, t0, t1)
tmask!(da, it::Interval)
tmask!(da, its)

Mask all data values within the specified time range(s) (t0, t1) / it / its with NaN.

source
TimeseriesUtilities.tmeanMethod
tmean(x, [dt]; dim=nothing, query=nothing)

Calculate the arithmetic mean of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.tmedianMethod
tmedian(x, [dt]; dim=nothing, query=nothing)

Calculate the median of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.tnorm_combineMethod
tnorm_combine(x; dim=nothing, name=:magnitude)

Calculate the norm of each slice along query dimension and combine it with the original components.

source
TimeseriesUtilities.toprojMethod
toproj(A, B; dim=nothing, query=nothing)

Compute vector rejection (orthogonal projection) of array A from B along specified dimension dim or query.

source
TimeseriesUtilities.tprojMethod
tproj(A, B; dim=nothing, query=nothing)

Compute vector projection of A onto B along specified dimension dim or query.

source
TimeseriesUtilities.tselectMethod
tselect(A, t, [δt]; query=nothing)

Select the value of A closest to time t within the time range [t-δt, t+δt].

Similar to DimensionalData.Dimensions.Lookups.At but choose the closest value and return missing if the time range is empty.

source
TimeseriesUtilities.tsemMethod
tsem(x, [dt]; dim=nothing, query=nothing)

Calculate the standard error of the mean of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.tsprojMethod
tsproj(A, B; dim=nothing, query=nothing)

Compute scalar projection of A onto B along specified dimension dim or query.

source
TimeseriesUtilities.tstdMethod
tstd(x, [dt]; dim=nothing, query=nothing)

Calculate the standard deviation of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.tsubtractFunction
tsubtract(x, f=nanmedian; dims=timedim(x))

Subtract a statistic (default function f: nanmedian) along dimensions (default: time dimension) from x.

source
TimeseriesUtilities.tsumMethod
tsum(x, [dt]; dim=nothing, query=nothing)

Calculate the sum of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.tvarMethod
tvar(x, [dt]; dim=nothing, query=nothing)

Calculate the variance of x along the dim dimension, optionally grouped by dt.

It returns a value if x is a vector along the dim dimension, otherwise returns a DimArray with the specified dimension dropped.

If dim is not specified, it defaults to the query dimension (dimension of type TimeDim by default).

source
TimeseriesUtilities.unwrapMethod
unwrap(x)

Return the innermost object of the wrapped object x with similar behavior as x (e.g. same size, same type, etc.)

source
TimeseriesUtilities.window_bf_sizesMethod
window_bf_sizes(window)

Converts a window specification to backward and forward window sizes.

When window is a positive integer scalar, the window is centered about the current element and contains window-1 neighboring elements. If window is even, then the window is centered about the current and previous elements.

source