TimeAxes

TimeAxes

Examples

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.TimeAxisType
TimeAxis

Subtype of AbstractAxis which can store timestamps to corresponding time keys.

source
TimeAxes.each_timeMethod
each_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_timedimMethod
has_timedim(x) -> Bool

Returns true if x has a dimension corresponding to time.

TimeAxes.leadMethod
lead(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
source
TimeAxes.ntimeMethod
ntime(x) -> Int

Returns the size along the dimension corresponding to the time. Defaults to 1

source
TimeAxes.select_timeMethod
select_time(x, i)

Return a view of all the data of x where the index for the time dimension equals i.

TimeAxes.time_axisMethod
time_axis(x, size[; first_pad=nothing, last_pad=nothing, stride=nothing, dilation=nothing])

Returns an AxisIterator along the time axis.

TimeAxes.time_axisMethod
time_axis(x)

Returns the axis corresponding to the time dimension.

TimeAxes.timedimMethod
timedim(x) -> Int

Returns the dimension corresponding to time.

TimeAxes.to_timestampMethod
to_timestamp(axis::TimeAxis, key)

Returns a timestamp where key corresponds to a key-value pair for the timestamps of axis.

source