danlooo / DGGS.jl

Discrete Global Grid System for Julia
GNU Affero General Public License v3.0
11 stars 2 forks source link

Conversion GeoCube -> CellCube -> GeoCube broken after using mapCube #32

Closed danlooo closed 1 year ago

danlooo commented 1 year ago
using Revise
using DGGS
using Test
using GLMakie

function plot_cube(cube)
    c = cube[Variable="air_temperature_2m", time=DateTime("2020-01-01T01:00:00")]
    m = Matrix(c.data.data)
    heatmap(m)
end

using EarthDataLab
esdc_cube = esdc(res="low")
subset_cube = esdc_cube[region="Europe", time=2020:2021, Variable=["ndvi", "air_temperature_2m"]]
geo_cube = GeoCube(subset_cube)
plot_cube(geo_cube)

plot_47

grid = DgGrid(:isea3h, 6)
cell_cube = CellCube(geo_cube, grid)
geo_cube2 = GeoCube(cell_cube)
plot_cube(geo_cube2)

plot_48

Furthermore, GeoCube -> CellCube -> GeoCube conversion fails if the cube has no additional dimensions:


convert(cube) = cube |> GeoCube |> x -> CellCube(x, grid) |> GeoCube

esdc_cube[region="Europe", time=2020:2021, Variable=["ndvi", "air_temperature_2m"]]|> convert
# passes

esdc_cube[region="Europe", Variable="air_temperature_2m", time=DateTime("2020-01-01T01:00:00")] |> convert
# ERROR: TaskFailedException
#     nested task error: BoundsError: attempt to access 190-element Vector{Union{Missing, Float32}} at index [5483]
#     Stacktrace:
#      [1] getindex
#        @ ./essentials.jl:13 [inlined]
#      [2] getindex(x::YAXArray{Union{Missing, Float32}, 1, Vector{Union{Missing, Float32}}, Vector{CubeAxis}}, i::Int64)
#        @ YAXArrays.Cubes ~/.julia/packages/YAXArrays/au5n4/src/Cubes/Cubes.jl:225
#      [3] map_reduce_cells_to_geo(xout::Matrix{Union{Missing, Float32}}, cell_values::Vector{Union{Missing, Float32}}, cell_cube::CellCube, longitudes::UnitRange{Int64}, latitudes::UnitRange{Int64})
#        @ DGGS ~/prj/DGGS.jl/src/cubes.jl:102