### DimStackArray usage example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of creating a DimStack, wrapping it as a DimStackArray, indexing to get values from all layers, and viewing a slice. ```julia using DimensionalData # Create a DimStack da1 = DimArray(ones(2,2), (X(1:2), Y(1:2)); name=:temp) da2 = DimArray(2ones(2,2), (X(1:2), Y(1:2)); name=:precip) stack = DimStack((da1, da2)) # Wrap as DimStackArray arr = DimStackArray(stack) # Get values from all layers at position [1,1] arr[1,1] # Returns (temp=1.0, precip=2.0) # Views maintain DimStack structure view(arr, 1:2, 1) ``` -------------------------------- ### reorder example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example showing how to reverse a DimArray and then use reorder to restore the original order. The output is true. ```julia using DimensionalData # Create a DimArray da = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(300:-100:100))) # Reverse it rev = reverse(da, dims=Y) # using `da` in reorder will return it to the original order reorder(rev, da) == da # output true ``` -------------------------------- ### @d macro example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of using the @d macro with different options: dims, strict, and name. ```julia using DimensionalData da1 = ones(X(3)) da2 = fill(2, Y(4), X(3)) @d da1 .* da2 @d da1 .* da2 .+ 5 dims=(Y, X) @d da1 .* da2 .+ 5 (dims=(Y, X), strict=false, name=:testname) ``` -------------------------------- ### swapdims example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example usage of `swapdims` with a `DimArray` and new dimension objects. The example shows constructing an array with `X`, `Y`, `Z` dimensions and swapping them to `Dim{:a}`, `Dim{:b}`, `Dim{:c}`. ```julia using DimensionalData A = ones(X(2), Y(4), Z(2)) Dimensions.swapdims(A, (Dim{:a}, Dim{:b}, Dim{:c})) ``` -------------------------------- ### Install and check DimensionalData version Source: https://rafaqz.github.io/DimensionalData.jl/stable/basics Install DimensionalData with the Julia package manager. The first command uses the interactive Pkg mode (press ']'), the second uses the Pkg.add function, and the third checks the installed version with the status command. ```julia julia> ] # ']' should be pressed pkg> add DimensionalData ``` ```julia julia> using Pkg julia> Pkg.add("DimensionalData") ``` ```julia julia> ] pkg> status DimensionalData ``` -------------------------------- ### dimnum Function Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example of using 'dimnum' to get position numbers of dimensions in the order they appear. ```julia julia> using DimensionalData julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> dimnum(A, (Z, X, Y)) (3, 1, 2) julia> dimnum(A, Y) 2 ``` -------------------------------- ### Define example dimensions with X and Y Source: https://rafaqz.github.io/DimensionalData.jl/stable/get_info Sets up an example DimArray by defining X and Y dimensions. The output shows the resulting tuple of dimensions. ```julia using DimensionalData using DimensionalData.Lookups x, y = X(10:-1:1), Y(100.0:10:200.0) ``` ```julia (↓ X 10:-1:1, → Y 100.0:10.0:200.0) ``` -------------------------------- ### Load packages for groupby examples Source: https://rafaqz.github.io/DimensionalData.jl/stable/groupby Loads the packages needed for the grouping examples: DimensionalData, Dates, Statistics, and defines the alias DD. ```julia using DimensionalData using Dates using Statistics const DD = DimensionalData ``` -------------------------------- ### DimStack construction and indexing example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Complete example showing how to create a DimStack from multiple DimArrays and index it with At selectors, demonstrating that indexing returns a NamedTuple of values. ```julia julia> using DimensionalData julia> A = [1.0 2.0 3.0; 4.0 5.0 6.0]; julia> dimz = (X([:a, :b]), Y(10.0:10.0:30.0)) (↓ X [:a, :b], → Y 10.0:10.0:30.0) julia> da1 = DimArray(1A, dimz; name=:one); julia> da2 = DimArray(2A, dimz; name=:two); julia> da3 = DimArray(3A, dimz; name=:three); julia> s = DimStack(da1, da2, da3); julia> s[At(:b), At(10.0)] (one = 4.0, two = 8.0, three = 12.0) julia> s[X(At(:a))] isa DimStack true ``` -------------------------------- ### @d macro with @. example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of using @d with @. as the inner macro. Note that @d does not imply @., so each broadcast must be specified. ```julia using DimensionalData da1 = ones(X(3)) da2 = fill(2, Y(4), X(3)) @d @. da1 * da2 # Use parentheses around `@.` if you need to pass options @d (@. da1 * da2 .+ 5) dims=(Y, X) ``` -------------------------------- ### modify example with CuArray Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of using modify to copy a DimArray to an Nvidia GPU with CuArray. ```julia A = DimArray(rand(100, 100), (X, Y)) modify(CuArray, A) ``` -------------------------------- ### DimArray indexing example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of indexing a DimArray with Selectors and Dimensions. Shows using Near, At, and Between selectors. The output shows the resulting DimArray with selected values. ```julia julia> using Dates, DimensionalData julia> ti = Ti(DateTime(2001):Month(1):DateTime(2001,12)); julia> x = X(10:10:100); julia> A = DimArray(rand(12,10), (ti, x), name="example"); julia> A[X(Near([12, 35])), Ti(At(DateTime(2001,5)))] ┌ 2-element DimArray{Float64, 1} example ┐ ├────────────────────────────────────────┴──────────────── dims ┐ ↓ X Sampled{Int64} [10, 40] ForwardOrdered Irregular Points └───────────────────────────────────────────────────────────────┘ 10 0.253849 40 0.637077 julia> A[Near(DateTime(2001, 5, 4)), Between(20, 50)] ┌ 4-element DimArray{Float64, 1} example ┐ ├────────────────────────────────────────┴────────────── dims ┐ ↓ X Sampled{Int64} 20:10:50 ForwardOrdered Regular Points └─────────────────────────────────────────────────────────────┘ 20 0.774092 30 0.823656 40 0.637077 50 0.692235 ``` -------------------------------- ### X dimension type and examples Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the X dimension type and shows examples of creating an X dimension, indexing with it, and using it in mean. ```julia X <: XDim X(val=:) ``` ```julia xdim = X(2:2:10) ``` ```julia val = A[X(1)] ``` ```julia mean(A; dims=X) ``` -------------------------------- ### All selector usage example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using the All selector to combine multiple selectors for different dimensions. The output shows a 2×4 DimArray with the selected values. ```julia using DimensionalData, Unitful dimz = X(10.0:20:200.0), Ti(1u"s":5u"s":100u"s") A = DimArray((1:10) * (1:20)', dimz) A[X=All(At(10.0), At(50.0)), Ti=All(1u"s"..10u"s", 90u"s"..100u"s")] # output ┌ 2×4 DimArray{Int64, 2} ┐ ├────────────────────────┴─────────────────────────────────────────────── dims ┐ ↓ X Sampled{Float64} [10.0, 50.0] ForwardOrdered Irregular Points, → Ti Sampled{Unitful.Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}} [1 s, …, 96 s] ForwardOrdered Irregular Points └──────────────────────────────────────────────────────────────────────────────┘ ↓ → 1 s 6 s 91 s 96 s 10.0 1 2 19 20 50.0 3 6 57 60 ``` -------------------------------- ### At selector example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example usage of the At selector. Creates a DimArray with X and Y dimensions and selects the element at X=20 and Y=6. ```julia using DimensionalData A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(5:7))) A[X(At(20)), Y(At(6))] ``` -------------------------------- ### commondims example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example usage of `commondims` with a `DimArray` and various dimension queries. Shows the output tuples for `X`, `(X, Z)`, and `Ti`. ```julia julia> using DimensionalData, .Dimensions julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> commondims(A, X) (↓ X) julia> commondims(A, (X, Z)) (↓ X, → Z) julia> commondims(A, Ti) () ``` -------------------------------- ### Start position type definition Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Defines the `Start` type as a subtype of `Position`, with a no-argument constructor. It specifies that lookup values correspond to the start locus of an interval. ```julia Start <: Position Start() ``` -------------------------------- ### Import DimensionalData, Dates, and Statistics Source: https://rafaqz.github.io/DimensionalData.jl/stable/broadcasts Loads the required packages for the example: DimensionalData for dim arrays, Dates for DateTime and Month, and Statistics for the month function. ```julia using DimensionalData using Dates using Statistics ``` -------------------------------- ### hasdim Function Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example of using 'hasdim' to check for the presence of specific dimensions. ```julia julia> using DimensionalData julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> hasdim(A, X) true julia> hasdim(A, (Z, X, Y)) (true, true, true) julia> hasdim(A, Ti) false ``` -------------------------------- ### mergedims example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example usage of mergedims on a tuple of dimensions, merging X and Y into a new dimension :space. Shows the resulting dimension tuple. ```julia julia> using DimensionalData julia> ds = (X(0:0.1:0.4), Y(10:10:100), Ti([0, 3, 4])) (↓ X 0.0:0.1:0.4, → Y 10:10:100, ↗ Ti [0, …, 4]) julia> mergedims(ds, (X, Y) => :space) (↓ Ti [0, …, 4], → space MergedLookup{Tuple{Float64, Int64}} [(0.0, 10), …, (0.4, 100)] (↓ X, → Y)) ``` -------------------------------- ### Base.fill example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Example of using Base.fill to create a DimArray filled with true values. The dimensions X(2) and Y(4) set the axis lengths. ```julia julia> using DimensionalData, Random; Random.seed!(123); julia> fill(true, X(2), Y(4)) ┌ 2×4 DimArray{Bool, 2} ┐ ├───────────────── dims ┤ ↓ X, → Y └───────────────────────┘ 1 1 1 1 1 1 1 1 ``` -------------------------------- ### Import required packages Source: https://rafaqz.github.io/DimensionalData.jl/stable/tables Loads the DimensionalData, Dates, and DataFrames packages, which are required for the examples on this page. ```julia using DimensionalData using Dates using DataFrames ``` -------------------------------- ### Near Usage Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using Near to select the nearest index to a value in a DimArray. The output is 4. ```julia using DimensionalData A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(5:7))) A[X(Near(23)), Y(Near(5.1))] # output 4 ``` -------------------------------- ### Define dimensions X, Y, and Ti Source: https://rafaqz.github.io/DimensionalData.jl/stable/broadcasts Creates the dimensions used in the example: X as 1:100, Y as 1:25, and Ti as monthly DateTime from January to December 2000. ```julia julia> x, y, t = X(1:100), Y(1:25), Ti(DateTime(2000):Month(1):DateTime(2000, 12)) ``` -------------------------------- ### Equivalent maplayers call Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Shows the equivalent maplayers call to the previous mean example, applying a function to each layer. ```julia maplayers(A -> mean(A; dims=Ti), mydimstack) ``` -------------------------------- ### Transformed lookup example with LinearMap Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Creates a DimArray with Transformed lookups using a LinearMap from CoordinateTransformations.jl, then indexes with At selectors. The output is 9. ```julia using DimensionalData, DimensionalData.Lookups, CoordinateTransformations m = LinearMap([0.5 0.0; 0.0 0.5]) A = [1 2 3 4 5 6 7 8 9 10 11 12]; da = DimArray(A, (X(Transformed(m)), Y(Transformed(m)))) da[X(At(6.0)), Y(At(2.0))] # output 9 ``` -------------------------------- ### Z dimension type and examples Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the Z dimension type and shows examples of creating a Z dimension, indexing with it, and using it in mean. ```julia Z <: ZDim Z(val=:) ``` ```julia zdim = Z(10:10:100) ``` ```julia val = A[Z(1)] ``` ```julia mean(A; dims=Z) ``` -------------------------------- ### @dim macro definition and example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the @dim macro for creating new dimensions. Shows an example of defining Lat and Lon dimensions with YDim and XDim supertypes. ```julia @dim typ [supertype=Dimension] [label::String=string(typ)] ``` ```julia using DimensionalData using DimensionalData: @dim, YDim, XDim @dim Lat YDim "Latitude" @dim Lon XDim "Longitude" ``` -------------------------------- ### Touches selector example with DimArray Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using the Touches selector to subset a DimArray. It selects indices that touch the closed interval [15, 25] for X and [4, 6.5] for Y. The output shows the resulting 1×2 DimArray. ```julia using DimensionalData A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(5:7))) A[X(Touches(15, 25)), Y(Touches(4, 6.5))] # output ┌ 1×2 DimArray{Int64, 2} ┐ ├────────────────────────┴────────────────────────────── dims ┐ ↓ X Sampled{Int64} 20:10:20 ForwardOrdered Regular Points, → Y Sampled{Int64} 5:6 ForwardOrdered Regular Points └─────────────────────────────────────────────────────────────┘ ↓ → 5 6 20 4 5 ``` -------------------------------- ### Create array with Interval sampling Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Creates an array with Interval sampling and Regular span. Sets the locus of Intervals to Start, specifying that lookup values are for the start of each interval. ```julia using DimensionalData, DimensionalData.Lookups x = X(Sampled(100:-20:10; sampling=Intervals(Start()))) y = Y(Sampled([1, 4, 7, 10]; span=Regular(3), sampling=Intervals(Start()))) A = ones(x, y) ``` -------------------------------- ### Create Sampled lookup manually Source: https://rafaqz.github.io/DimensionalData.jl/stable/selectors Creates a Sampled lookup manually with Regular intervals of 10.0 and Start sampling. The output shows the lookup wrapping 10.0:10.0:100.0. ```julia julia> l = Sampled(10.0:10.0:100.0; order=ForwardOrdered(), span=Regular(10.0), sampling=Intervals(Start())) ``` -------------------------------- ### Create a Dimension object with `X(1)` Source: https://rafaqz.github.io/DimensionalData.jl/stable/object_modification Creates a Dimension object `X` with value 1. This is a simple example of constructing a dimension. ```julia julia> d = X(1) ``` -------------------------------- ### prune example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Prunes a DimTree to keep a specific branch and then converts it to a DimStack. The pruned tree no longer has branches with divergent dimensions. ```julia pruned = prune(dimtree; keep=:branch => :leaf) DimStack(pruned) ``` -------------------------------- ### Create a random Matrix for DimArray shortcuts Source: https://rafaqz.github.io/DimensionalData.jl/stable/dimarrays Creates another random 5×10 Matrix for use in the DimArray constructor shortcuts example. ```julia julia> A = rand(5, 10) ``` ```output 5×10 Matrix{Float64}: 0.223602 0.737979 0.996807 0.194501 … 0.0959042 0.628507 0.893267 0.0392779 0.792885 0.249616 0.519235 0.0315486 0.113704 0.997572 0.451879 0.0959455 0.373575 0.891743 0.700389 0.958811 0.00385747 0.689712 0.0927459 0.765773 0.273573 0.688928 0.761347 0.596077 0.0102884 0.688175 0.254555 0.081724 0.239557 0.886959 0.386439 ``` -------------------------------- ### Create a named tuple for `rebuild` example Source: https://rafaqz.github.io/DimensionalData.jl/stable/object_modification Creates a named tuple `nt` with fields `a` and `b`. This is used to demonstrate that `rebuild` works on arbitrary objects. ```julia julia> nt = (a = 1, b = 2) ``` -------------------------------- ### Create demo DateTime range Source: https://rafaqz.github.io/DimensionalData.jl/stable/groupby Creates a demo DateTime range from year 2000 with hourly steps over two years. The output is shown in the next block. ```julia julia> tempo = range(DateTime(2000), step=Hour(1), length=365*24*2) ``` -------------------------------- ### Example: Create array with Categorical lookups Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Creates a DimArray with Categorical lookups for X and Y dimensions, then displays the lookups. The output shows Categorical{String} and Categorical{Symbol} with their orders. ```julia using DimensionalData ds = X(["one", "two", "three"]), Y([:a, :b, :c, :d]) A = DimArray(rand(3, 4), ds) Dimensions.lookup(A) # output Categorical{String} ["one", …, "three"] Unordered, Categorical{Symbol} [:a, …, :d] ForwardOrdered ``` -------------------------------- ### Between Usage Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using Between to select indices between two values in a DimArray. The output is 5. ```julia using DimensionalData A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(5:7))) A[X(Between(15, 25)), Y(Between(4, 6.5))] ``` -------------------------------- ### otherdims Function Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example of using 'otherdims' on a 10x10x10 array to find dimensions not in the query. ```julia julia> using DimensionalData, DimensionalData.Dimensions julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> otherdims(A, X) (↓ Y, → Z) julia> otherdims(A, (Y, Z)) (↓ X) ``` -------------------------------- ### X Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions X dimension constructor. ```APIDOC ## X ### Description X `Dimension`. `X <: XDim <: IndependentDim` ### Type `X <: XDim` ### Constructor `X(val=:)` ### Examples ```julia xdim = X(2:2:10) ``` ```julia val = A[X(1)] ``` ```julia mean(A; dims=X) ``` ``` -------------------------------- ### Y dimension type and examples Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the Y dimension type and shows examples of creating a Y dimension, indexing with it, and using it in mean. ```julia Y <: YDim Y(val=:) ``` ```julia ydim = Y(['a', 'b', 'c']) ``` ```julia val = A[Y(1)] ``` ```julia mean(A; dims=Y) ``` -------------------------------- ### dims Function Example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Example of using the dims function on a DimArray. It creates a 2x3x2 array and then extracts the X and Y dimensions. ```julia julia> using DimensionalData julia> A = DimArray(ones(2, 3, 2), (X, Y, Z)) ┌ 2×3×2 DimArray{Float64, 3} ┐ ├────────────────────── dims ┤ ↓ X, → Y, ↗ Z └────────────────────────────┘ [:, :, 1] 1.0 1.0 1.0 1.0 1.0 1.0 julia> dims(A, (X, Y)) (↓ X, → Y) ``` -------------------------------- ### DimTree example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Creates a DimTree from multiple arrays with different dimensions. Dimensions shared with the base must be identical; branches can have different lookup values for the same dimension, enabling tiles with different extents or pyramid layers. ```julia xdim, ydim = X(1:10), Y(1:15) z1, z2 = Z([:a, :b, :c]), Z([:d, :e, :f]) a = rand(xdim, ydim) b = rand(Float32, xdim, ydim) c = rand(Int, xdim, ydim, z1) d = rand(Int, xdim, z2) DimTree(a, b) ``` -------------------------------- ### DimStack constructor for AbstractDimArray Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Shows the constructor signature for creating a DimStack from a single AbstractDimArray, with optional keywords for layersfrom, name, metadata, and refdims. ```julia function DimStack(A::AbstractDimArray; layersfrom=nothing, name=nothing, metadata=metadata(A), refdims=refdims(A), kw... ) ``` -------------------------------- ### Where selector usage example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using the Where selector to filter dimensions by a predicate function. The output shows a 1×2 DimArray with the selected values. ```julia using DimensionalData A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(19:21))) A[X(Where(x -> x > 15)), Y(Where(x -> x in (19, 21)))] # output ┌ 1×2 DimArray{Int64, 2} ┐ ├────────────────────────┴─────────────────────────────── dims ┐ ↓ X Sampled{Int64} [20] ForwardOrdered Irregular Points, → Y Sampled{Int64} [19, 21] ForwardOrdered Irregular Points └──────────────────────────────────────────────────────────────┘ ↓ → 19 21 20 4 6 ``` -------------------------------- ### DimIndices example Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Indexes a DimArray with DimIndices. Unlike CartesianIndices, the dimensions do not need to be in the same order or all contained in the array. The example shows the array and the DimIndices object. ```julia julia> A = rand(Y(0.0:0.3:1.0), X('a':'f')) ┌ 4×6 DimArray{Float64, 2} ┐ ├──────────────────────────┴───────────────────────────────── dims ┐ ↓ Y Sampled{Float64} 0.0:0.3:0.9 ForwardOrdered Regular Points, → X Categorical{Char} 'a':1:'f' ForwardOrdered └──────────────────────────────────────────────────────────────────┘ ↓ → 'a' 'b' 'c' 'd' 'e' 'f' 0.0 0.9063 0.253849 0.0991336 0.0320967 0.774092 0.893537 0.3 0.443494 0.334152 0.125287 0.350546 0.183555 0.354868 0.6 0.745673 0.427328 0.692209 0.930332 0.297023 0.131798 0.9 0.512083 0.867547 0.136551 0.959434 0.150155 0.941133 julia> di = DimIndices((X(1:2:4), Y(1:2:4))) ┌ 2×2 DimIndices{Tuple{X{Int64}, Y{Int64}}, 2} ┐ ├──────────────────────────────────────── dims ┤ ↓ X 1:2:3, → Y 1:2:3 └──────────────────────────────────────────────┘ ↓ → 1 3 1 (↓ X 1, → Y 1) (↓ X 1, → Y 3) 3 (↓ X 3, → Y 1) (↓ X 3, → Y 3) ``` -------------------------------- ### print_top call for show Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Call `print_top` to add the main part of `show`. At the least, you likely want to call this. `show_main` will also call `print_metadata_block`. ```julia print_top(io, mime, A) ``` -------------------------------- ### Base.copy! (AbstractDimStack, AbstractDimStack) Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Copy all or a subset of layers from one stack to another. Optionally specify which keys to copy. ```APIDOC ## Base.copy! (AbstractDimStack, AbstractDimStack) ### Description Copy all or a subset of layers from one stack to another. ### Method Function call ### Signature ```julia Base.copy!(dst::AbstractDimStack, src::AbstractDimStack, [keys=keys(dst)]) ``` ### Parameters - **dst** (AbstractDimStack) - Required - Destination stack. - **src** (AbstractDimStack) - Required - Source stack. - **keys** (Tuple of Symbol) - Optional - The keys of layers to copy. Defaults to all keys in dst. ### Example Copy just the `:sea_surface_temp` and `:humidity` layers from `src` to `dst`: ```julia copy!(dst::AbstractDimStack, src::AbstractDimStack, keys=(:sea_surface_temp, :humidity)) ``` ``` -------------------------------- ### Ti dimension type and examples Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the Ti time dimension type and shows examples of creating a Ti dimension, indexing with it, and using it in mean. ```julia Ti(val=:) ``` ```julia timedim = Ti(DateTime(2021, 1):Month(1):DateTime(2021, 12)) ``` ```julia val = A[Ti(1)] ``` ```julia mean(A; dims=Ti) ``` -------------------------------- ### Base.copy! (AbstractArray, AbstractDimStack, Key) Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Copy the stack layer specified by key to a destination array, which can be any AbstractArray. ```APIDOC ## Base.copy! (AbstractArray, AbstractDimStack, Key) ### Description Copy the stack layer `key` to `dst`, which can be any `AbstractArray`. ### Method Function call ### Signature ```julia Base.copy!(dst::AbstractArray, src::AbstractDimStack, key::Key) ``` ### Parameters - **dst** (AbstractArray) - Required - Destination array. - **src** (AbstractDimStack) - Required - Source stack. - **key** (Key) - Required - The layer key to copy. ### Example Copy the `:humidity` layer from `stack` to `array`: ```julia copy!(array, stack, :humidity) ``` ``` -------------------------------- ### Use Begin and End types for first/last element indexing Source: https://rafaqz.github.io/DimensionalData.jl/stable/dimarrays In base Julia, begin and end keywords work for indexing, but not with named indexing. Use the types Begin and End instead. The example returns a scalar value. ```julia julia> da[X=Begin+1, Y=End] ``` ```output 0.7748300143766251 ``` -------------------------------- ### Contains selector example with DimArray Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Example of using the Contains selector to select the interval containing a value. It uses Intervals with Center sampling. The output shows the resulting 1×1 DimArray. ```julia using DimensionalData; const DD = DimensionalData dims_ = X(10:10:20; sampling=DD.Intervals(DD.Center())), Y(5:7; sampling=DD.Intervals(DD.Center())) A = DimArray([1 2 3; 4 5 6], dims_) A[X(Contains(8)), Y(Contains(6.8))] # output ┌ 1×1 DimArray{Int64, 2} ┐ ├────────────────────────┴────────────────────────────── dims ┐ ↓ X Sampled{Int64} 10:10:20 ForwardOrdered Regular Intervals{Int64, Center}, → Y Sampled{Int64} 5:7 ForwardOrdered Regular Intervals{Int64, Center} └─────────────────────────────────────────────────────────────┘ ↓ → 6 10 5 ``` -------------------------------- ### show_after method signatures Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Interface methods for adding additional `show` text for `AbstractDimArray` and `AbstractDimStack` subtypes. Always include `kw` to avoid future breaking changes. Additional keywords may be added at any time. ```julia show_after(io::IO, mime, A::AbstractDimArray) show_after(io::IO, mime, A::AbstractDimStack) ``` -------------------------------- ### NoMetadata Type Definition Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/lookuparrays Indicates an object has no metadata. Unlike using nothing, get, keys, and haskey still work on it, with get always returning the fallback argument, keys returning (), and haskey always returning false. ```julia NoMetadata <: AbstractMetadata NoMetadata() ``` -------------------------------- ### otherdims Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Get the dimensions of an object not in the query. ```APIDOC ## otherdims ### Description Get the dimensions of an object _not_ in `query`. A tuple holding the unmatched dimensions is always returned. ### Method Function ### Endpoint `otherdims(x, query) => Tuple{Vararg{Dimension,N}}` ### Parameters #### Arguments - `x` (any) - Required - Any object with a `dims` method, a `Tuple` of `Dimension`. - `query` (Tuple or single `Dimension` or dimension `Type`) - Required - The dimensions to exclude. - `f` (function) - Optional - `<:` by default, but can be `>:` to match abstract types to concrete types. ### Returns - `Tuple{Vararg{Dimension,N}}` - A tuple of the unmatched dimensions. ### Example ```julia julia> using DimensionalData, DimensionalData.Dimensions julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> otherdims(A, X) (↓ Y, → Z) julia> otherdims(A, (Y, Z)) (↓ X) ``` ``` -------------------------------- ### DimStack constructor signature Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Shows the main constructor signatures for DimStack, including variants for a table, multiple arrays, and a single array with layersfrom. ```julia DimStack(table, [dims]; kw...) DimStack(data::AbstractDimArray...; kw...) DimStack(data::Union{AbstractArray,Tuple,NamedTuple}, [dims::DimTuple]; kw...) DimStack(data::AbstractDimArray; layersfrom, kw...) ``` -------------------------------- ### dimnum Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Get the number(s) of dimensions as ordered in the dimensions of an object. ```APIDOC ## dimnum ### Description Get the number(s) of `Dimension`(s) as ordered in the dimensions of an object. The return type will be a Tuple of `Int` or a single `Int`, depending on whether `query` is a `Tuple` or single `Dimension`. ### Method Function ### Endpoint `dimnum(x, query::Tuple) => NTuple{Int}` `dimnum(x, query) => Int` ### Parameters #### Arguments - `x` (any) - Required - Any object with a `dims` method, a `Tuple` of `Dimension` or a single `Dimension`. - `query` (Tuple, Array or single `Dimension` or dimension `Type`) - Required - The dimensions to get numbers for. ### Returns - `NTuple{Int}` - A tuple of dimension numbers. - `Int` - A single dimension number. ### Example ```julia julia> using DimensionalData julia> A = DimArray(ones(10, 10, 10), (X, Y, Z)); julia> dimnum(A, (Z, X, Y)) (3, 1, 2) julia> dimnum(A, Y) 2 ``` ``` -------------------------------- ### Benchmark stack indexing with integer indices Source: https://rafaqz.github.io/DimensionalData.jl/stable/stacks Benchmarks indexing a stack using integer indices (1, 4). The output shows the time and allocations, followed by the resulting NamedTuple. ```julia julia> @btime $st[1, 4] ``` ```text 4.738 ns (0 allocations: 0 bytes) (a = 0.4988459421184759, b = 0.2571287355813575, c = 0.9821724302512657, d = 0.2868262581079416) ``` -------------------------------- ### name Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Get the name of an array or Dimension, or a tuple of either as a Symbol. ```APIDOC ## name ### Description Get the name of an array or Dimension, or a tuple of either as a Symbol. The second argument `dims` can be `Dimension`s, `Dimension` types, or `Symbols` for `Dim{Symbol}`. ### Method Function ### Endpoint `name(x) => Symbol` `name(xs:Tuple) => NTuple{N,Symbol}` `name(x, dims::Tuple) => NTuple{N,Symbol}` `name(x, dim) => Symbol` ### Parameters #### Arguments - `x` (any) - Required - The object to get the name from. - `xs` (Tuple) - Optional - A tuple of objects to get names from. - `dims` (Tuple) - Optional - A tuple of dimensions to get names from. - `dim` (Dimension) - Optional - A single dimension to get the name from. ### Returns - `Symbol` - The name of the object or dimension. - `NTuple{N,Symbol}` - A tuple of names. ``` -------------------------------- ### Replace dimension lookup with setdims and retrieve with lookup Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Shows how to replace a dimension's lookup with a categorical one using setdims, then retrieve the new lookup with lookup. Requires DimensionalData, DimensionalData.Dimensions, and DimensionalData.Lookups. ```julia using DimensionalData, DimensionalData.Dimensions, DimensionalData.Lookups A = ones(X(10), Y(10:10:100)) B = setdims(A, Y(Categorical('a':'j'; order=ForwardOrdered()))) lookup(B, Y) ``` -------------------------------- ### otherdims Function Definition Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/dimensions Defines the 'otherdims' function which gets all dimensions not in a query. ```julia otherdims(x, query) => Tuple{Vararg{Dimension,N}} ``` -------------------------------- ### issampled(A, Y) predicate Source: https://rafaqz.github.io/DimensionalData.jl/stable/get_info Checks whether the dimension Y of A is sampled. Returns true for the example A. ```julia julia> issampled(A, Y) ``` ```text true ``` -------------------------------- ### DimensionalData.show_main Function Source: https://rafaqz.github.io/DimensionalData.jl/stable/api/reference Show the main content of an AbstractDimArray or AbstractDimStack. ```APIDOC ## show_main Function ### Description Show the main content of an `AbstractDimArray` or `AbstractDimStack`. ### Function Signatures ```julia show_main(io::IO, mime, A::AbstractDimArray) show_main(io::IO, mime, A::AbstractDimStack) ``` ``` -------------------------------- ### issampled(A) predicate Source: https://rafaqz.github.io/DimensionalData.jl/stable/get_info Checks whether the dimension A is sampled. Returns true for the example A. ```julia julia> issampled(A) ``` ```text true ``` -------------------------------- ### Bin groups into N bins using Bins Source: https://rafaqz.github.io/DimensionalData.jl/stable/groupby Uses the `Bins` wrapper to break the month groups into 4 bins. The output is a DimGroupByArray with 4 intervals, each containing a subset of the data. Note that bin edges are slightly padded, making the lookup less than ideal. ```julia julia> groupby(A, Ti=>Bins(month, 4)) ``` -------------------------------- ### issampled(dims(A)) predicate Source: https://rafaqz.github.io/DimensionalData.jl/stable/get_info Checks whether all dimensions of A are sampled. Returns true for the example A. ```julia julia> issampled(dims(A)) ``` ```text true ```