TimeAxes
TimeAxesExamples
A simple array with a time dimension time units along the axis.
julia> using TimeAxes
julia> using Unitful: s
julia> A = NamedAxisArray{(:time,)}(collect(1:100), (1:100)s);Iteration
One could use the time axis for iteration...
julia> sum([A[i] for i in axes(A, 1)])
5050
julia> sum([A[time=i] for i in time_axis(A)])
5050
...or windows of the time axis.
julia> A2 = sum([A[i] for i in AxisIterator(axes(A, 1), 10)])
10-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:10 s
1 s 460
2 s 470
3 s 480
4 s 490
5 s 500
6 s 510
7 s 520
8 s 530
9 s 540
10 s 550
julia> sum([A[time=i] for i in time_axis(A, 10)])
10-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:10 s
1 s 460
2 s 470
3 s 480
4 s 490
5 s 500
6 s 510
7 s 520
8 s 530
9 s 540
10 s 550
Some other basic functions related to time data are also available.
julia> lag(A2, 1)
9-element NamedAxisArray{Int64,1}
• time - 2 s:1 s:10 s
2 s 460
3 s 470
4 s 480
5 s 490
6 s 500
7 s 510
8 s 520
9 s 530
10 s 540
julia> lead(A2, 1)
9-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:9 s
1 s 470
2 s 480
3 s 490
4 s 500
5 s 510
6 s 520
7 s 530
8 s 540
9 s 550
More time specific methods may be found in the References
References
TimeAxes.TimeAxis — TypeTimeAxisSubtype of AbstractAxis which can store timestamps to corresponding time keys.
TimeAxes.assert_timedim_last — Methodassert_timedim_last(x)Throw an error if the x has a time dimension that is not the last dimension.
TimeAxes.duration — Methodduration(x)Duration of the event along the time axis.
TimeAxes.each_time — Methodeach_time(x)Create a generator that iterates over the time dimensions A, returning views that select all the data from the other dimensions in A.
TimeAxes.has_timedim — Methodhas_timedim(x) -> BoolReturns true if x has a dimension corresponding to time.
TimeAxes.lead — Methodlead(A::AbstractArray, nshift::Integer[, dim::Integer])Shift the elements of A along the the axis of the dimension dim by nshift elements earlier. If dim is not specified then the dimension returned by timedim is used. If A does not have a time dimension then the last dimension is assumed to be the time dimension.
Examples
julia> using TimeAxes
julia> using Unitful: s
julia> A = NamedAxisArray{(:time,)}(collect(1:5), (1:5)s)
5-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:5 s
1 s 1
2 s 2
3 s 3
4 s 4
5 s 5
julia> lead(A, 1)
4-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:4 s
1 s 2
2 s 3
3 s 4
4 s 5
julia> lead([1 2 3; 4 5 6; 7 8 9], 1, 1)
2×3 Array{Int64,2}:
4 5 6
7 8 9
julia> lead([1 2 3; 4 5 6; 7 8 9], 1, 2)
3×2 Array{Int64,2}:
2 3
5 6
8 9
TimeAxes.ntime — Methodntime(x) -> IntReturns the size along the dimension corresponding to the time. Defaults to 1
TimeAxes.onset — Methodonset(x)First time point along the time axis.
TimeAxes.sampling_rate — Methodsampling_rate(x)Number of samples per second.
TimeAxes.select_time — Methodselect_time(x, i)Return a view of all the data of x where the index for the time dimension equals i.
TimeAxes.time_axis — Methodtime_axis(x, size[; first_pad=nothing, last_pad=nothing, stride=nothing, dilation=nothing])Returns an AxisIterator along the time axis.
TimeAxes.time_axis — Methodtime_axis(x)Returns the axis corresponding to the time dimension.
TimeAxes.time_axis_type — Methodtime_axis_type(x)Returns the key type corresponding to the time axis.
TimeAxes.time_end — Methodtime_end(x)Last time point along the time axis.
TimeAxes.time_indices — Methodtime_indices(x)Returns the indices corresponding to the time axis
TimeAxes.time_keys — Methodtime_keys(x)Returns the keys corresponding to the time axis
TimeAxes.time_step — Methodtime_step(x)The time step/interval between each element.
TimeAxes.timedim — Methodtimedim(x) -> IntReturns the dimension corresponding to time.
TimeAxes.to_timestamp — Methodto_timestamp(axis::TimeAxis, key)Returns a timestamp where key corresponds to a key-value pair for the timestamps of axis.