Getters
DimensionalData.jl defines consistent methods to retreive 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)
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.60582 0.141215 0.21304 0.030899 0.225936
9 0.579684 0.194032 0.0925107 0.625407 0.864552
8 0.147835 0.320466 0.0218371 0.736047 0.273577
7 0.852385 0.410331 0.554825 0.0816985 0.558087
6 0.476084 0.398895 0.924338 … 0.342836 0.408025
5 0.737617 0.736993 0.262798 0.874753 0.367589
4 0.9423 0.0612503 0.51853 0.863122 0.0773346
3 0.402457 0.257745 0.692264 0.232609 0.872355
2 0.694731 0.721035 0.0105931 0.572112 0.416011
1 0.82384 0.00198649 0.928308 … 0.793683 0.717434
dims
retreives 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