Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map-reduce syntax to CellCubes and DGGS #77

Closed
wants to merge 1 commit into from

Conversation

danlooo
Copy link
Owner

@danlooo danlooo commented Jan 25, 2024

No description provided.

@danlooo
Copy link
Owner Author

danlooo commented Jan 25, 2024

Problem

One might want to reduce spatial dimensions e.g. to get a spatial average.
However, the result is not a proper CellCube anymore due to the lack of spatial dimensions.

Solutions

  1. Return a plain YAXArray e.g. after mapslices(mean, dggs[6]; dims=["q2di_i", "q2di_j"]). Then, mapslice will change the type from input CellCube to output YAXArray
  2. Throw an error stating thata proper CellCube couldn't be thrown

What do you think? @meggart

julia> mapslices(mean, dggs[6]; dims=["q2di_i", "q2di_j"])
ERROR: Axis q2di_i is missing
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] CellCube(data::YAXArrays.Cubes.YAXArray{Union{Missing, Float32}, 2, Matrix{Union{Missing, Float32}}, Tuple{Dim{:q2di_n, DimensionalData.Dimensions.LookupArrays.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Int64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.NoMetadata}}, Ti{DimensionalData.Dimensions.LookupArrays.Sampled{Dates.DateTime, Vector{Dates.DateTime}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Irregular{Tuple{Nothing, Nothing}}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.NoMetadata}}}}, level::Int8)
   @ DGGS ~/prj/DGGS.jl/src/types.jl:19
 [3] mapslices(agg_func::Function, cell_cube::CellCube; dims::Vector{String}, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ DGGS ~/prj/DGGS.jl/src/cubes.jl:99
 [4] top-level scope
   @ REPL[41]:1

julia> mapslices(mean, dggs[6].data; dims=["q2di_i", "q2di_j"])
12×12 YAXArray{Union{Missing, Float32},2} with dimensions: 
  Dim{:q2di_n} Sampled{Int64} 0:1:11 ForwardOrdered Regular Points,
  Ti Sampled{Dates.DateTime} Dates.DateTime[2001-01-01T00:00:00, …, 2001-12-01T00:00:00] ForwardOrdered Irregular Points
Total size: 576.0 bytes

@danlooo danlooo closed this Apr 25, 2024
@danlooo danlooo deleted the danlooo/add_reduce_dimension branch April 25, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant