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

Apply chunking of assets before indicator calculation #322

Merged
merged 8 commits into from
Aug 8, 2024
Merged

Conversation

goergen95
Copy link
Member

@goergen95 goergen95 commented Aug 7, 2024

This PR applies pre-chunking to assets. While adding overhead before indicator calculation begins, parallelization is more efficient because we now know in advance over how many items to iterate. This also means that we can get rid of the nested future topology, which is anyways really hard to reason about.

More specifically, chunking applies the following steps to all assets in a portfolio:

  • split assets within +/- 5 degrees of the dateline
  • split multipolygons into their components if their bbox area is larger than the chunk_size
  • split polygons with bbox larger than chunk_size into a grid with cellsize equal to chunk_size
  • each sub-part of an asset receives the same assetid, indicator results are then aggregated later based on its value

.chunk <- function(x, chunk_size) {
stopifnot(inherits(x, "sf") && "assetid" %in% names(x))
metadata <- st_drop_geometry(x)
x <- x[, "assetid"]
x[["chunked"]] <- FALSE
st_geometry(x) <- "geometry"
x <- .split_dateline(x)
x <- .split_multipolygons(x, chunk_size)
x <- .chunk_geoms(x, chunk_size)
.finalize_assets(x, metadata)
}

@goergen95 goergen95 self-assigned this Aug 7, 2024
Copy link

codecov bot commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 89.43089% with 13 lines in your changes missing coverage. Please review.

Project coverage is 86.06%. Comparing base (1ac0d9a) to head (6b93d4b).

Files Patch % Lines
R/chunking.R 89.71% 11 Missing ⚠️
R/calc_indicators.R 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   85.68%   86.06%   +0.38%     
==========================================
  Files          52       53       +1     
  Lines        2319     2361      +42     
==========================================
+ Hits         1987     2032      +45     
+ Misses        332      329       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@goergen95 goergen95 merged commit 479ae27 into main Aug 8, 2024
10 checks passed
@goergen95 goergen95 deleted the pre-chunk branch August 8, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant