Getters
DimensionalData.jl defines consistent methods to retrieve information from objects like DimArray
, DimStack
, Tuple
s 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.0 120.0 … 190.0 200.0
10 0.616666 0.561953 0.0157247 0.177857 0.856524
9 0.660024 0.395523 0.0109523 0.552838 0.0536623
8 0.112606 0.548479 0.0545071 0.755722 0.830655
7 0.839223 0.0400057 0.702845 0.384116 0.445628
6 0.734452 0.65906 0.506965 … 0.654591 0.44097
5 0.89757 0.748725 0.00633515 0.178022 0.106904
4 0.969026 0.0042232 0.63959 0.423538 0.556096
3 0.106472 0.274713 0.589536 0.805743 0.390342
2 0.861535 0.167465 0.507581 0.799964 0.292431
1 0.245499 0.742732 0.095824 … 0.90203 0.86858
dims
retrieves dimensions from any object that has them.
What makes it so useful is that you can filter which dimensions you want, and specify 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, false
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