Skip to content

Getters

DimensionalData.jl defines consistent methods to retrieve information from objects like DimArray, DimStack, Tuples of Dimension, Dimension and Lookup.

First we will define an example DimArray.

julia
using DimensionalData
using DimensionalData.Lookups
x, y = X(10:-1:1), Y(100.0:10:200.0)
↓ X 10:-1:1,
→ Y 100.0:10.0:200.0
julia
julia> A = rand(x, y)
╭───────────────────────────╮
10×11 DimArray{Float64,2}
├───────────────────────────┴─────────────────────────────────── dims ┐
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points,
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points
└─────────────────────────────────────────────────────────────────────┘
  100.0         110.0180.0       190.0       200.0
 10      0.664038      0.464482        0.868966    0.530653    0.418968
  9      0.00832284    0.0980829       0.314535    0.322005    0.674881
  8      0.639212      0.233778        0.315591    0.190225    0.475569
  7      0.602315      0.0372362       0.950143    0.062593    0.948976
  6      0.375166      0.423798   …    0.640311    0.932968    0.98985
  5      0.153219      0.635963        0.293126    0.68781     0.309301
  4      0.00508449    0.829714        0.727149    0.585756    0.921145
  3      0.946824      0.906705        0.899632    0.471877    0.633956
  2      0.876112      0.831617        0.128932    0.428951    0.243803
  1      0.749253      0.864128   …    0.715102    0.921012    0.566574

dims retrieves dimensions from any object that has them.

What makes it so useful is you can filter which dimensions you want in what order, using any Dimension, Type{Dimension} or Symbol.

julia
julia> dims(A)
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points,
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points
julia
julia> dims(A, Y)
Y Sampled{Float64} ForwardOrdered Regular Points
wrapping: 100.0:10.0:200.0
julia
julia> dims(A, Y())
Y Sampled{Float64} ForwardOrdered Regular Points
wrapping: 100.0:10.0:200.0
julia
julia> dims(A, :Y)
Y Sampled{Float64} ForwardOrdered Regular Points
wrapping: 100.0:10.0:200.0
julia
julia> dims(A, (X,))
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points
julia
julia> dims(A, (Y, X))
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points,
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points
julia
julia> dims(A, reverse(dims(A)))
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points,
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points
julia
julia> dims(A, isregular)
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points,
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points

Predicates

These always return true or false. With multiple dimensions, fale means !all and true means all.

dims and all other methods listed above can use predicates to filter the returned dimensions.

julia
julia> issampled(A)
true
julia
julia> issampled(dims(A))
true
julia
julia> issampled(A, Y)
true
julia
julia> issampled(lookup(A, Y))
true
julia
julia> dims(A, issampled)
X Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points,
Y Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points
julia
julia> otherdims(A, issampled)
()
julia
julia> lookup(A, issampled)
Sampled{Int64} 10:-1:1 ReverseOrdered Regular Points,
Sampled{Float64} 100.0:10.0:200.0 ForwardOrdered Regular Points