Skip to content

Commit

Permalink
Add a YAXArray function for DD.Dimension to wrap them as a cube
Browse files Browse the repository at this point in the history
This enables to use the dimensions as a cube in mapCube calls.
Also reenables the documentation on filling a cube with a function.
  • Loading branch information
felixcremer committed Jul 19, 2023
1 parent 2de65d5 commit ce6e16e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions docs/examples/UserGuide/create_from_func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -60,4 +60,3 @@ gen_cube = mapCube(g, (lon, lat, time);
# Note that now the broadcasted dimension is `lon`.

gen_cube.data[:, :, 1]
=#
3 changes: 3 additions & 0 deletions src/Cubes/Cubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 148 in src/Cubes/Cubes.jl

View check run for this annotation

Codecov / codecov/patch

src/Cubes/Cubes.jl#L148

Added line #L148 was not covered by tests
# Base utility overloads
Base.size(a::YAXArray) = size(getdata(a))
Base.size(a::YAXArray, i::Int) = size(getdata(a), i)
Expand Down
2 changes: 1 addition & 1 deletion src/DAT/DAT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 182 in src/DAT/DAT.jl

View check run for this annotation

Codecov / codecov/patch

src/DAT/DAT.jl#L182

Added line #L182 was not covered by tests
elseif desc.chunksize == :input
map(axesSmall) do ax
for cc in incubes
Expand Down

0 comments on commit ce6e16e

Please sign in to comment.