Utilities
Helpers for sampling metadata, windowing, embedding, regularisation, derivatives, and circular statistics. All operate on the core types from Time series.
Sampling metadata
TimeseriesBase.Utils.times Function
times(x::AbstractTimeseries)Returns the time indices of the AbstractTimeseries x.
Examples
julia> t = 1:100;
julia> x = rand(100);
julia> ts = Timeseries(x, t);
julia> times(ts) == tBase.step Function
step(x::RegularTimeseries)Returns the step size (time increment) of a regularly sampled RegularTimeseries.
Examples
julia> t = 1:100;
julia> x = rand(100);
julia> rts = Timeseries(x, t);
julia> step(rts) == 1TimeseriesBase.Utils.samplingrate Function
samplingrate(x::RegularTimeseries)Returns the sampling rate (inverse of the step size) of a regularly sampled RegularTimeseries.
Examples
julia> t = 1:100;
julia> x = rand(100);
julia> rts = Timeseries(x, t);
julia> samplingrate(rts) == 1TimeseriesBase.Utils.samplingperiod Function
samplingperiod(x::RegularTimeseries)Returns the sampling period (step size) of a regularly sampled RegularTimeseries.
Examples
julia> t = 1:100;
julia> x = rand(100);
julia> rts = Timeseries(x, t);
julia> samplingperiod(rts) == 1TimeseriesBase.Utils.duration Function
duration(x::AbstractTimeseries)Returns the duration of the AbstractTimeseries x.
Examples
julia> t = 1:100;
julia> x = rand(100);
julia> ts = Timeseries(x, t);
julia> TimeseriesBase.duration(ts) == 99Windowing and reshaping
coarsegrain downsamples by averaging within blocks; buffer returns non-overlapping windows as columns; window returns sliding windows; delayembed builds a delay-coordinate embedding.
using TimeseriesTools
x = Timeseries(sin.(0.0:0.01:9.99), 0.0:0.01:9.99)
b = buffer(x, 100) # 100-sample non-overlapping windows
size(b)(10,)TimeseriesBase.Utils.coarsegrain Function
coarsegrain(X::AbstractArray; dims = nothing, newdim=ndims(X)+1)Coarse-grain an array by taking every second element over the given dimensions dims and concatenating them in the dimension newdim. dims are coarse-grained in sequence, from last to first. If dims is not specified, we iterate over all dimensions that are not newdim. If the array has an odd number of slices in any dims, the last slice is discarded. This is more flexibile than the conventional, mean-based definition of coarse graining: it can be used to generate coarse-grained distributions from an array. To recover this conventional mean-based coarse-graining:
C = coarsegrain(X)
mean(C, dims=ndims(C))TimeseriesBase.Utils.buffer Function
buffer(x::RegularTimeseries, n::Integer, p::Integer; kwargs...)Buffer a time series x with a given window length and overlap between successive buffers.
Arguments
x: The regular time series to be buffered.n: The number of samples in each buffer.p: The number of samples of overlap betweeen the buffers.0indicates no overlap+
2indicates2samples of overlap between successive buffers-
2indicates2samples of gap between buffers
See also: window, delayembed, coarsegrain
TimeseriesBase.Utils.window Function
window(x::RegularTimeseries, n::Integer, p::Integer; kwargs...)Window a time series x with a given window length and step between successive windows.
Arguments
x: The regular time series to be windows.n: The number of samples in each window.p: The number of samples to slide each successive window.
See also: buffer, delayembed, coarsegrain
TimeseriesBase.Utils.delayembed Function
delayembed(x::UnivariateRegular, n::Integer, τ::Integer, p::Integer=1; kwargs...)Delay embed a univariate time series x with a given dimension n, delay τ, and skip length of p
Arguments
x: The regular time series to be delay embedded.n: The embedding dimension, i.e., the number of samples in each embedded vector.τ: The number of original sampling periods between each sample in the embedded vectors.p: The number of samples to skip between each successive embedded vector.
Missing docstring.
Missing docstring for interlace. Check Documenter's build log for details.
Missing docstring.
Missing docstring for Dropdims. Check Documenter's build log for details.
Regularising time axes
rectify and regularize repair float jitter in nominally regular lookups; matchdim and align bring multiple series onto a common axis.
Missing docstring.
Missing docstring for rectify. Check Documenter's build log for details.
TimeseriesBase.Utils.rectifytime Function
rectifytime(X::AbstractTimeseries; tol = 6, zero = false)Rectifies the time values of an IrregularTimeseries. Checks if the time step of the input time series is approximately constant. If it is, the function rounds the time step and constructs a RegularTimeseries with range time indices. If the time step is not approximately constant, a warning is issued and the rectification is skipped.
Arguments
X::IrregularTimeseries: The input time series.tol::Int: The number of significant figures for rounding the time step. Default is 6.zero::Bool: Iftrue, the rectified time values will start from zero. Default isfalse.
TimeseriesBase.Utils.regularize Function
regularize(d::DimensionalData.Dimension; atol=nothing, sigdigits=nothing,
strict=true)Return (new_lookup, original_lookup) where new_lookup is a regular range that best fits the values of d and original_lookup is the input lookup collected to a vector.
Use this method when you want to inspect the rectified grid yourself; most callers should use regularize on an AbstractDimArray instead.
Keyword arguments
atol: maximum allowed absolute deviation of any lookup point from the best-fit regular grid. Carries units if the lookup does. Ifnothing, a permissive~1e3 * epsfloor is used.sigdigits: override the number of digits used to round the step and start. Defaults to a value derived fromatolso rounding error stays within tolerance.strict=true: throw if regularity fails. Setfalseto warn and return the best-fit grid anyway.
regularize(X::AbstractDimArray; dims=𝑡, atol=nothing, sigdigits=nothing,
zero=false, strict=true)Replace the lookup of X along each of dims with a regular range that best fits the existing values, repairing accumulated float jitter. If a lookup deviates from regular by more than atol an ArgumentError is thrown (strict=false downgrades this to a warning).
If zero=true, the new lookup starts at zero and the genuine original lookup is stored in metadata(X) under the dimension name.
This replaces the older rectify and rectifytime methods.
regularize(Xs::AbstractVector{<:AbstractDimArray}; dims=𝑡, atol=nothing,
sigdigits=nothing, zero=false, strict=true)
regularize(X1, X2, ...; dims=𝑡, kwargs...)Align a collection of arrays to a common regular grid along each of dims.
The shared grid is computed from the element-wise mean of the lookups after each array has been cropped to the maximal common range and trimmed to the minimum common length. The same regularity check that the single-array method uses then applies to every input array — if any one of them deviates from the common grid by more than atol, an ArgumentError is thrown (or a warning, under strict=false) naming the offending array and index.
This replaces the older matchdim and the vararg form of rectify.
Missing docstring.
Missing docstring for matchdim. Check Documenter's build log for details.
TimeseriesBase.Utils.align Function
align(x::AbstractDimArray, ts, dt; dims = 1)Align a DimArray x to each of a set of dimension values ts, selecting a window given by dt centered at each element of ts. dt can be a two-element vector/tuple, or an interval. The dims argument specifies the dimension along which the alignment is performed. Each element of the resulting DimArray is an aligned portion of the original x.
Derivatives
Three finite-difference flavours: left, right, and centred. In-place (!) and allocating forms.
TimeseriesBase.Utils.centraldiff Function
centraldiff(x::RegularTimeseries; dims=𝑡, grad=-)Compute the central difference of a regular time series x. The first and last elements are set to the forward and backward difference, respectively. The dimension to perform differencing over can be specified as dims, and the differencing function can be specified as grad (defaulting to the euclidean distance, -) See centraldiff!.
TimeseriesBase.Utils.centraldiff! Function
centraldiff!(x::RegularTimeseries; dims=𝑡, grad=-)Compute the central difference of a regular time series x, in-place. The first and last elements are set to the forward and backward difference, respectively. The dimension to perform differencing over can be specified as dims, and the differencing function can be specified as grad (defaulting to the euclidean distance, -)
TimeseriesBase.Utils.centralderiv Function
centralderiv(x::AbstractTimeseries)Compute the central derivative of a time series x. See centraldiff for available keyword arguments. Also c.f. centralderiv!.
TimeseriesBase.Utils.centralderiv! Function
centralderiv!(x::RegularTimeseries; kwargs...)Compute the central derivative of a regular time series x, in-place. See centraldiff! for available keyword arguments.
Missing docstring.
Missing docstring for leftdiff. Check Documenter's build log for details.
Missing docstring.
Missing docstring for leftdiff!. Check Documenter's build log for details.
Missing docstring.
Missing docstring for leftderiv. Check Documenter's build log for details.
Missing docstring.
Missing docstring for leftderiv!. Check Documenter's build log for details.
Missing docstring.
Missing docstring for rightdiff. Check Documenter's build log for details.
Missing docstring.
Missing docstring for rightdiff!. Check Documenter's build log for details.
Missing docstring.
Missing docstring for rightderiv. Check Documenter's build log for details.
Missing docstring.
Missing docstring for rightderiv!. Check Documenter's build log for details.
Circular statistics
For phase series and other angular data.
Missing docstring.
Missing docstring for resultant. Check Documenter's build log for details.
Missing docstring.
Missing docstring for resultantlength. Check Documenter's build log for details.
Missing docstring.
Missing docstring for circularmean. Check Documenter's build log for details.
Missing docstring.
Missing docstring for circularvar. Check Documenter's build log for details.
Missing docstring.
Missing docstring for circularstd. Check Documenter's build log for details.
Missing docstring.
Missing docstring for phasegrad. Check Documenter's build log for details.
Metadata helpers
Missing docstring.
Missing docstring for addrefdim. Check Documenter's build log for details.
Missing docstring.
Missing docstring for addmetadata. Check Documenter's build log for details.
Spike-train helpers
Missing docstring.
Missing docstring for spiketrain. Check Documenter's build log for details.
Missing docstring.
Missing docstring for spiketimes. Check Documenter's build log for details.