-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from KWB-R/dev
LID scenarios
- Loading branch information
Showing
26 changed files
with
1,337 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
^codecov\.yml$ | ||
^index\.md$ | ||
^README\.md$ | ||
^data-raw$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' Convert LID config to SWMM LID controls | ||
#' @param df data frame for a single scenario of a LID (as returned by | ||
#' \code{\link{read_scenarios}}) | ||
#' @return data frame with SWMM LID controls | ||
#' @export | ||
#' @importFrom readr cols read_csv | ||
#' @importFrom kwb.swmm extdata_file | ||
#' @importFrom dplyr any_vars bind_rows filter_at left_join mutate select vars | ||
#' @importFrom tidyr pivot_wider | ||
#' @importFrom rlang .data | ||
#' @importFrom tidyselect all_of starts_with | ||
#' @importFrom stringr str_to_upper | ||
#' @examples | ||
#' scenarios <- keys.lid::read_scenarios() | ||
#' unique(scenarios$lid_name_tidy) | ||
#' lid <- "permeable_pavement" | ||
#' lid_selected <- scenarios %>% dplyr::filter(.data$lid_name_tidy == lid) | ||
#' scenario_names <- unique(lid_selected$scenario_name) | ||
#' scenario_name <- scenario_names[1] | ||
#' scenario_name | ||
#' lid_selected_scenario <- lid_selected[lid_selected$scenario_name == scenario_name,] | ||
#' lid_controls <- lidconfig_to_swmm(lid_selected_scenario) | ||
#' str(lid_controls) | ||
lidconfig_to_swmm <- function(df) { | ||
|
||
lid_para <- readr::read_csv(kwb.swmm::extdata_file("lid/required_parameteristion.csv"), | ||
col_types = readr::cols(.default = "c")) | ||
|
||
lid_parametersation <- df %>% | ||
dplyr::filter(!is.na(.data$value)) %>% | ||
dplyr::filter(!is.na(.data$id_type_parameter)) %>% | ||
dplyr::select(tidyselect::all_of(c("lid_name_tidy", "type", "id_type_parameter", "scenario_name", "value"))) %>% | ||
dplyr::left_join(lid_para %>% | ||
dplyr::select(.data$lid_id, .data$lid_name_tidy), by = "lid_name_tidy") %>% | ||
dplyr::mutate("Name" = sprintf("%s.%s", .data$lid_name_tidy, .data$scenario_name), | ||
"Type/Layer" = stringr::str_to_upper(.data$type), | ||
) %>% | ||
dplyr::filter(!is.na(.data$value)) %>% | ||
dplyr::select(tidyselect::all_of(c("Name", "Type/Layer", "id_type_parameter", "value"))) %>% | ||
tidyr::pivot_wider(names_from = "id_type_parameter", | ||
names_prefix = "Par", | ||
values_from = "value") %>% | ||
dplyr::filter_at(dplyr::vars(tidyselect::starts_with("Par")), dplyr::any_vars(!is.na(.data))) | ||
|
||
## dont know why 5 is needed by SWMM (but generated in SWMM GUI) | ||
lid_parametersation[lid_parametersation$`Type/Layer` == "SURFACE", "Par5"] <- 5 | ||
|
||
lid_id <- lid_para$lid_id[lid_para$lid_name_tidy == unique(df$lid_name_tidy)] | ||
|
||
lid_header <- lid_parametersation[1,] | ||
lid_header[1,3:ncol(lid_header)] <- NA_real_ | ||
lid_header$`Type/Layer` <- lid_id | ||
|
||
dplyr::bind_rows(lid_header, lid_parametersation) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#' Performance results for LIDs | ||
#' | ||
#' A dataset containing the performance of LIDs for different climate conditions | ||
#' created with R script in /data-raw/performances.R | ||
#' | ||
#' @format A nested tibble with 290 rows and 16 variables: | ||
#' \describe{ | ||
#' \item{zone_id}{climate zone id} | ||
#' \item{lid_name_tidy}{tidy LID name} | ||
#' \item{scenario_name}{name of LID scenario} | ||
#' \item{catchment_area_m2}{catchment area in squaremeters} | ||
#' \item{lid_area_fraction}{fraction of LID compared to total catchment} | ||
#' \item{lid_area_m2}{total LID area} | ||
#' \item{lid_usage}{tibble with LID usage parameterisation} | ||
#' \item{lid_controls}{tibble with LID controls parameterisation} | ||
#' \item{subcatchment}{tibble with subcatchment parameterisation} | ||
#' \item{annual}{tibble with two columns "year" and "vrr" (volume rainfall retended for each year} | ||
#' \item{events_max}{tibble with maximum values for each rainfall event} | ||
#' \item{events_sum}{tibble with sum values for each rainfall event} | ||
#' \item{col_eventsep}{name of SWMM results used for event separation} | ||
#' \item{model_inp}{path to SWMM model input file} | ||
#' \item{model_rpt}{path to SWMM model report file} | ||
#' \item{model_out}{path to SWMM model output file} | ||
#' } | ||
"performances" |
Oops, something went wrong.