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")

TIP

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

Quickstart

julia
using YAXArrays

You may check the installed version with:

julia
pkg> st YAXArrays

Let's assemble a YAXArray with 4 dimensions i.e. time, x,y and a variable dimension with two variables.

julia
using YAXArrays, DimensionalData
axlist = (
    Dim{:time}(range(1, 20, length=20)),
    X(range(1, 10, length=10)),
    Y(range(1, 5, length=15)),
    Dim{:Variable}(["var1", "var2"]))
# and the corresponding data.
data = rand(20, 10, 15, 2);

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.

You can also add additional properties via a Dictionary, namely

julia
props = Dict(
    "time" => "days",
    "x" => "lon",
    "y" => "lat",
    "var1" => "one of your variables",
    "var2" => "your second variable",
);

And our first YAXArray is built with:

julia
julia> ds = 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} ["var1", "var2"] ForwardOrdered
├──────────────────────────────────────────────────────────────────── metadata ┤
  Dict{String, String} with 5 entries:
  "var1" => "one of your variables"
  "time" => "days"
  "x"    => "lon"
  "var2" => "your second variable"
  "y"    => "lat"
├─────────────────────────────────────────────────────────────────── file size ┤
  file size: 46.88 KB
└──────────────────────────────────────────────────────────────────────────────┘

Getting data from a YAXArray

For axis can be via .

julia
ds.X
X Sampled{Float64} ForwardOrdered Regular DimensionalData.Dimensions.Lookups.Points
wrapping: 1.0:1.0:10.0

or better yet via lookup

julia
lookup(ds, :X)
Sampled{Float64} ForwardOrdered Regular DimensionalData.Dimensions.Lookups.Points
wrapping: 1.0:1.0:10.0

note that also the .data field can be use

julia
lookup(ds, :X).data
1.0:1.0:10.0

The data for one variables, i.e. var1 can be accessed via:

julia
julia> ds[Variable=At("var1")]
╭──────────────────────────────╮
20×10×15 YAXArray{Float64,3}
├──────────────────────────────┴───────────────────────────────────────── 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
├──────────────────────────────────────────────────────────────────── metadata ┤
  Dict{String, String} with 5 entries:
  "var1" => "one of your variables"
  "time" => "days"
  "x"    => "lon"
  "var2" => "your second variable"
  "y"    => "lat"
├─────────────────────────────────────────────────────────────────── file size ┤
  file size: 23.44 KB
└──────────────────────────────────────────────────────────────────────────────┘

and again, you can use the .data field to actually get the data.