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}()
├────────────────────────────────────────────────────────── file size ┤ 
  file 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"
├─────────────────────────────────────────────────────────────────── file size ┤ 
  file 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.900876  0.535562  0.310201   0.98439    …  0.104797  0.191941   0.627844
 0.337684  0.739208  0.20125    0.206179      0.699537  0.919172   0.0372749
 0.186741  0.817761  0.136611   0.0831171     0.72254   0.639187   0.784511
 0.150145  0.484549  0.330895   0.200126      0.220876  0.579075   0.52829
 0.483991  0.632841  0.0425075  0.741955      0.968135  0.292845   0.174194
 0.91142   0.937614  0.961539   0.318082   …  0.392392  0.0596837  0.0370048
 0.842418  0.880335  0.026562   0.977417      0.260632  0.558259   0.307546
 0.395585  0.145044  0.0822544  0.142301      0.542092  0.792609   0.997393
 0.402403  0.68403   0.263134   0.774804      0.899697  0.694295   0.347735
 0.29125   0.384717  0.58556    0.840998      0.882159  0.794035   0.802649

Get more details at the select page

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.