From ce6e16ef407793e845e49cf20a4ee1a176c9267c Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 19 Jul 2023 12:37:45 +0200 Subject: [PATCH] Add a YAXArray function for DD.Dimension to wrap them as a cube This enables to use the dimensions as a cube in mapCube calls. Also reenables the documentation on filling a cube with a function. --- docs/examples/UserGuide/create_from_func.jl | 11 +++++------ src/Cubes/Cubes.jl | 3 +++ src/DAT/DAT.jl | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/examples/UserGuide/create_from_func.jl b/docs/examples/UserGuide/create_from_func.jl index 6353d3d9..df199cf4 100644 --- a/docs/examples/UserGuide/create_from_func.jl +++ b/docs/examples/UserGuide/create_from_func.jl @@ -6,7 +6,7 @@ using Dates # !!! warning This is currently broken. # This is broken after the switch to DimensionalData -#= + f(lo, la, t) = (lo + la + Dates.dayofyear(t)) # ## Wrap function for mapCube output @@ -20,12 +20,12 @@ end # ## Create Cube's Axes -# We do this via `RangeAxis` for every dimension -lon = (Dim{:lon}(range(1, 15))) -lat = (Dim{:lat}(range(1, 10))) +# We wrap the dimensions of every axis into a YAXArray to use them in the mapCube function. +lon = YAXArray(Dim{:lon}(range(1, 15))) +lat = YAXArray(Dim{:lat}(range(1, 10))) # And a time axis tspan = Date("2022-01-01"):Day(1):Date("2022-01-30") -time = (Dim{:time}( tspan)) +time = YAXArray(Dim{:time}( tspan)) # ## Generate Cube from function @@ -60,4 +60,3 @@ gen_cube = mapCube(g, (lon, lat, time); # Note that now the broadcasted dimension is `lon`. gen_cube.data[:, :, 1] -=# \ No newline at end of file diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index 356ef927..41f956d8 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -143,6 +143,9 @@ function YAXArray(x::AbstractArray) YAXArray(ax, x, props,chunks=chunks) end + +# Overload the YAXArray constructor for dimensional data to use them inside of mapCube +YAXArray(dim::DD.Dimension) = YAXArray((dim,), dim.val) # Base utility overloads Base.size(a::YAXArray) = size(getdata(a)) Base.size(a::YAXArray, i::Int) = size(getdata(a), i) diff --git a/src/DAT/DAT.jl b/src/DAT/DAT.jl index 0000b114..0cd04a05 100644 --- a/src/DAT/DAT.jl +++ b/src/DAT/DAT.jl @@ -179,7 +179,7 @@ end function interpretoutchunksizes(desc, axesSmall, incubes) if desc.chunksize == :max - map(ax -> axname(ax) => RegularChunks(length(ax),0,length(ax)), axesSmall) + map(ax -> string(DD.name(ax)) => RegularChunks(length(ax),0,length(ax)), axesSmall) elseif desc.chunksize == :input map(axesSmall) do ax for cc in incubes