Skip to content

Getting Started

Installation

Install Julia v1.10 or above. YAXArrays.jl is available through the Julia package manager. You can enter it by pressing ] in the REPL and then typing

julia
pkg> add YAXArrays

Alternatively, you can also do

julia
import Pkg; Pkg.add("YAXArrays")

Quickstart

Create a simple array from random numbers given the size of each dimension or axis:

julia
using YAXArrays

a = YAXArray(rand(2,3))
╭─────────────────────────╮
│ 2×3 YAXArray{Float64,2} │
├─────────────────────────┴───────────────────────────────────── dims ┐
  ↓ Dim_1 Sampled{Int64} Base.OneTo(2) ForwardOrdered Regular Points,
  → Dim_2 Sampled{Int64} Base.OneTo(3) ForwardOrdered Regular Points
├─────────────────────────────────────────────────────────── metadata ┤
  Dict{String, Any}()
├─────────────────────────────────────────────────── loaded in memory ┤
  data size: 48.0 bytes
└─────────────────────────────────────────────────────────────────────┘

Assemble a more complex YAXArray with 4 dimensions, i.e. time, x, y and a variable type:

julia
using DimensionalData

# axes or dimensions with name and tick values
axlist = (
    Dim{:time}(range(1, 20, length=20)),
    X(range(1, 10, length=10)),
    Y(range(1, 5, length=15)),
    Dim{:variable}(["temperature", "precipitation"])
)

# the actual data matching the dimensions defined in axlist
data = rand(20, 10, 15, 2)

# metadata about the array
props = Dict(
    "origin" => "YAXArrays.jl example",
    "x" => "longitude",
    "y" => "latitude",
);

a2 = YAXArray(axlist, data, props)
╭────────────────────────────────╮
│ 20×10×15×2 YAXArray{Float64,4} │
├────────────────────────────────┴─────────────────────────────────────── dims ┐
  ↓ time     Sampled{Float64} 1.0:1.0:20.0 ForwardOrdered Regular Points,
  → X        Sampled{Float64} 1.0:1.0:10.0 ForwardOrdered Regular Points,
  ↗ Y        Sampled{Float64} 1.0:0.2857142857142857:5.0 ForwardOrdered Regular Points,
  ⬔ variable Categorical{String} ["temperature", "precipitation"] ReverseOrdered
├──────────────────────────────────────────────────────────────────── metadata ┤
  Dict{String, String} with 3 entries:
  "y"      => "latitude"
  "x"      => "longitude"
  "origin" => "YAXArrays.jl example"
├──────────────────────────────────────────────────────────── loaded in memory ┤
  data size: 46.88 KB
└──────────────────────────────────────────────────────────────────────────────┘

Get the temperature map at the first point in time:

julia
a2[variable=At("temperature"), time=1].data
10×15 view(::Array{Float64, 4}, 1, :, :, 1) with eltype Float64:
 0.325997   0.624506   0.655204  0.142733  …  0.587477   0.626919  0.606561
 0.0972941  0.0693719  0.828299  0.531092     0.884949   0.060422  0.265107
 0.393083   0.0776029  0.157268  0.339529     0.976187   0.811959  0.0302534
 0.928614   0.52908    0.902979  0.746804     0.0353507  0.634856  0.92491
 0.720352   0.825766   0.235707  0.245867     0.0474875  0.552072  0.607478
 0.240588   0.875981   0.755932  0.696114  …  0.542309   0.705063  0.902991
 0.507176   0.0512364  0.628915  0.935959     0.874428   0.812577  0.183083
 0.853962   0.461652   0.438885  0.665833     0.0743642  0.81705   0.00997173
 0.515079   0.283788   0.258509  0.807171     0.234116   0.404819  0.3785
 0.864937   0.0916764  0.235899  0.047283     0.768363   0.937012  0.732556

Updates

TIP

The Julia Compiler is always improving. As such, we recommend using the latest stable version of Julia.

You may check the installed version with:

julia
pkg> st YAXArrays

INFO

With YAXArrays.jl 0.5 we switched the underlying data type to be a subtype of the DimensionalData.jl types. Therefore the indexing with named dimensions changed to the DimensionalData syntax. See the DimensionalData.jl docs.