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.19093 0.311676 0.983506 0.636648 0.758395
9 0.694156 0.607075 0.973842 0.796537 0.110399
8 0.0904123 0.106733 0.456896 0.484191 0.488705
7 0.545064 0.688881 0.824833 0.753238 0.00956875
6 0.55922 0.359241 0.941277 … 0.0975188 0.834197
5 0.497435 0.513853 0.881306 0.971756 0.0734615
4 0.490313 0.222829 0.289705 0.518723 0.532442
3 0.00529101 0.239808 0.679315 0.202343 0.744793
2 0.444203 0.0574469 0.00132494 0.978464 0.271525
1 0.367348 0.474425 0.863738 … 0.744349 0.696446
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