Skip to content

Commit

Permalink
Update aggregate function: Remove missings
Browse files Browse the repository at this point in the history
  • Loading branch information
danlooo committed Nov 22, 2023
1 parent fa79457 commit 50d5c52
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Binary file added country_borders.shp
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ We can prevent this by providing a custom aggregation function:
using Statistics
aggregate_skip_undef(value) = value |> filter(! isnan) |> mean
dggs2 = DgGlobalGridSystem(sub_geo_cube, :isea4h, 6; aggregation_function = aggregate_skip_undef)
dggs2 = DgGlobalGridSystem(sub_geo_cube, :isea4h, 6; aggregate_function = aggregate_skip_undef)
plot_map(dggs2[4][time=DateTime("2020-01-01T01:00:00")])
```

Expand Down
6 changes: 3 additions & 3 deletions src/gridsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ function get_cube_pyramid(grids::Vector{<:AbstractGrid}, cell_cube::CellCube; ag
return res
end

function DgGlobalGridSystem(geo_cube::GeoCube, preset::Symbol, n_levels::Int=5; aggregation_function::Function=mean)
function DgGlobalGridSystem(geo_cube::GeoCube, preset::Symbol, n_levels::Int=5; aggregate_function::Function=x -> x |> filter(!ismissing) |> filter(!isnan) |> mean)
grids = [DgGrid(preset, level) for level in 0:n_levels-1]
finest_grid = grids[n_levels]
finest_cell_cube = CellCube(geo_cube, finest_grid)
cell_cubes = get_cube_pyramid(grids, finest_cell_cube; aggregate_function=aggregation_function)
cell_cubes = get_cube_pyramid(grids, finest_cell_cube; aggregate_function=aggregate_function)
levels = [Level(cell_cube, grid, level) for (cell_cube, grid, level) in zip(cell_cubes, grids, 1:length(grids))]
dggs = DgGlobalGridSystem(levels, preset, missing, missing, missing)
return dggs
end

function DgGlobalGridSystem(geo_cube::GeoCube, n_levels::Int=5, projection::Symbol=:isea, aperture::Int=4, topology::Symbol=:hexagon; aggregate_function::Function=mean)
function DgGlobalGridSystem(geo_cube::GeoCube, n_levels::Int=5, projection::Symbol=:isea, aperture::Int=4, topology::Symbol=:hexagon; aggregate_function::Function=x -> x |> filter(!ismissing) |> filter(!isnan) |> mean)
grids = [DgGrid(projection, aperture, topology, level) for level in 0:n_levels-1]
finest_grid = grids[n_levels]
finest_cell_cube = CellCube(geo_cube, finest_grid)
Expand Down
Empty file added test/.Rhistory
Empty file.

0 comments on commit 50d5c52

Please sign in to comment.