-
Notifications
You must be signed in to change notification settings - Fork 282
Update SDA Downscaling to allow sf #3431
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
base: develop
Are you sure you want to change the base?
Changes from 16 commits
4ac829f
be310eb
c5ae7dc
db36719
6ec8c14
fa087c2
da96331
7041d18
6af65d9
3411085
e4ca8a6
978254a
4f3ff5b
e00da0a
44bcddc
f53eef0
0211780
6eee5ac
07daf1c
b33a161
307228f
019afe4
bc202e0
0d6fa01
e7655e2
01def9a
ecd4ff1
29ab4d2
0310d65
0309308
b268ece
bddbc99
8235d54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,259 @@ | ||||||
| ##' @title Subset ensemble data for downscaling | ||||||
| ##' @name SDA_downscale_preprocess | ||||||
| ##' @author Sambhav Dixit, David LeBauer | ||||||
| ##' | ||||||
| ##' @param ensemble_data EFI standard tibble or data.frame | ||||||
| ##' @param site_coords data.frame with unique site id | ||||||
| ##' @param date Date. The date for the run, must be a date within `ensemble_data`. | ||||||
| ##' @param carbon_pool Character. Carbon pool of interest. Name must match the carbon pool name in ensemble_data. | ||||||
| ##' found within the file or object supplied to 'ensemble_data'. | ||||||
| ##' @details This function subsets ensemble data and ensures that the specified date and | ||||||
| ##' carbon pool are present in the ensemble data. | ||||||
| ##' | ||||||
| ##' @return A list containing the cleaned site coordinates and the ensemble carbon output for the | ||||||
| ##' specified date and carbon pool. | ||||||
|
|
||||||
| subset_ensemble <- function(ensemble_data, site_coords, date, carbon_pool) { | ||||||
|
|
||||||
| # Confirm date is in ensemble data | ||||||
| if (!any(lubridate::date(unique(ensemble_data$datetime)) == lubridate::date(date))) { | ||||||
| PEcAn.logger::logger.error(paste( | ||||||
| "Provided date", date, | ||||||
| "is not found in the ensemble_data input." | ||||||
| )) | ||||||
| } | ||||||
|
|
||||||
| # Ensure the carbon pool exists in the input data | ||||||
| if (!carbon_pool %in% unique(ensemble_data$variable)) { | ||||||
| PEcAn.logger::logger.error("Carbon pool", carbon_pool, "not found in the input data.") | ||||||
| } | ||||||
|
|
||||||
| # Ensure the sites are in the ensemble data | ||||||
| if (!all(unique(site_coords$id) %in% unique(ensemble_data$site))) { | ||||||
| PEcAn.logger::logger.error("Some sites in site_coords are not present in the ensemble_data.") | ||||||
| } | ||||||
|
|
||||||
| # Filter the ensemble data to the specified date and carbon pool | ||||||
| ensemble_data <- ensemble_data |> | ||||||
| filter( | ||||||
|
||||||
| filter( | |
| dplyr::filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll probably need .data$ on the column names here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for other tidyverse fn calls below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same function name used here and in downscale_function.R. Only whichever definition is parsed last at package byte-compilation time will be used (which I think is determined by collation order). Given Helper.functions.R already exists, I recommend moving all these dotted-name functions there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly encourage pulling this anonymous function out to its own definition and giving it an informative name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it appears i is only used to subset ensemble -- is there a reason not to pass each one directlly (i.e map(ensembles, function(ens) ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why the extra lambda -- does this differ from lapply(downscale_output$test_data, dplyr::pull, prediction), or indeed from lapply(downscale_output$test_data, `[[`, "prediction")?
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.