Selectors
In addition to choosing dimensions by name, we can also select values within them.
First, we can create a DimArray with lookup values as well as dimension names:
using DimensionalDataA = rand(X(1.0:0.2:2.0), Y([:a, :b, :c]))Then we can use the Selector to select values from the array:
Lookups
Selectors find indices in the Lookup of each dimension. Lookups wrap other AbstractArray (often AbstractRange) but add additional traits to facilitate fast lookups or specifying point or interval behaviour. These are usually detected automatically.
using DimensionalData.LookupsThe Sampled(x) lookup holds values sampled along an axis. They may be Ordered/Unordered, Intervals/Points, and Regular/Irregular.
Most of these properties are usually detected automatically, but here we create a Sampled lookup manually:
l = Sampled(10.0:10.0:100.0; order=ForwardOrdered(), span=Regular(10.0), sampling=Intervals(Start()))To specify Irregular Intervals, we should include the outer bounds of the lookup, as we can't determine them from the vector.
l = Sampled([13, 8, 5, 3, 2, 1]; order=ForwardOrdered(), span=Irregular(1, 21), sampling=Intervals(Start()))Lookup autodetection
When we define an array, extra properties are detected:
A = DimArray(rand(7, 5), (X(10:10:70), Y([:a, :b, :c, :d, :e])))This array has a Sampled lookup with ForwardOrdered Regular Points for X, and a Categorical ForwardOrdered for Y.
Most lookup types and properties are detected automatically like this from the arrays and ranges used.
Arrays and ranges of
String,Symbol, andCharare set toCategoricallookup.orderis detected asUnordered,ForwardOrdered, orReverseOrdered
Arrays and ranges of
Number,DateTime, and other things are set toSampledlookups.orderis detected asUnordered,ForwardOrdered, orReverseOrdered.samplingis set toPoints()unless the values areIntervalSets.Interval, thenIntervals(Center())is used.spanis detected asRegular(step(range))forAbstractRangeandIrregular(nothing, nothing)for otherAbstractArray, wherenothing, nothingare the unknown outer bounds of the lookup. They are not needed forPointsas the outer values are the outer bounds. But they can be specified manually forIntervalsEmpty dimensions or dimension types are assigned
NoLookup()ranges that can't be used with selectors as they hold no values.
DimSelector
We can also index with arrays of selectors DimSelectors. These are like CartesianIndices or DimIndices, but holding the Selectors At, Near, or Contains.
A = rand(X(1.0:0.2:2.0), Y(10:2:20))We can define another array with partly matching indices
B = rand(X(1.0:0.04:2.0), Y(20:-1:10))And we can simply select values from B with selectors from A:
B[DimSelectors(A)]If the lookups aren't aligned, we can use Near instead of At, which is like doing a nearest neighbor interpolation:
C = rand(X(1.0:0.007:2.0), Y(10.0:0.9:30))
C[DimSelectors(A; selectors=Near)]