-
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 #18 from KWB-R/dev
Release v0.1.0
- Loading branch information
Showing
25 changed files
with
804 additions
and
115 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
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ sensitivity_analysis_models/tmp.out | |
docs | ||
inst/doc | ||
.Rhistory | ||
swmm_scenarios |
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
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,35 @@ | ||
#' Title | ||
#' | ||
#' @param export_dir default: tempdir() | ||
#' | ||
#' @return write "performances" to "swmm_lid-performances.xlsx" in directory | ||
#' "export_dir" and return path to fike | ||
#' @export | ||
#' | ||
#' @importFrom stats setNames | ||
#' @importFrom tidyselect all_of | ||
#' @importFrom openxlsx write.xlsx | ||
#' @importFrom dplyr select | ||
#' @importFrom tidyr nest | ||
export_performances <- function(export_dir = tempdir()) { | ||
|
||
path <- file.path(export_dir, "swmm_lid-performances.xlsx") | ||
|
||
list_elements <- names(performances)[sapply(performances, is.list)] | ||
|
||
|
||
unnest_list_col <- function(list_element) { | ||
list_elements_to_remove <- list_elements[! list_elements %in% list_element] | ||
|
||
performances %>% | ||
dplyr::select(!tidyselect::all_of(list_elements_to_remove)) %>% | ||
tidyr::unnest(tidyselect::all_of(list_element)) | ||
} | ||
|
||
export <- stats::setNames(lapply(list_elements, function(list_element) { | ||
unnest_list_col(list_element)}), | ||
list_elements) | ||
|
||
openxlsx::write.xlsx(x = export, file = path) | ||
path | ||
} |
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,86 @@ | ||
#' Get Percentiles for Events | ||
#' | ||
#' @param performances nested tibble (default: \code{\link{performances}}) | ||
#' @return list with percentiles for "event_sum" and "event_max" | ||
#' @export | ||
#' @importFrom tidyselect all_of | ||
#' @importFrom tidyr unnest | ||
#' @importFrom dplyr select group_by mutate summarise | ||
get_event_percentiles <- function(performances = keys.lid::performances) { | ||
|
||
volume <- performances %>% | ||
tidyr::unnest(.data$events_sum) | ||
|
||
sel_cols <- c("zone_id", | ||
"lid_name_tidy", | ||
"scenario_name", | ||
"lid_area_fraction", | ||
"runoff_cbm", | ||
"tBeg", | ||
"tEnd") | ||
|
||
volume_stats <- volume %>% | ||
dplyr::select(tidyselect::all_of(sel_cols)) %>% | ||
dplyr::group_by(.data$zone_id, | ||
.data$lid_name_tidy, | ||
.data$scenario_name, | ||
.data$lid_area_fraction) %>% | ||
dplyr::mutate(runoff_LitrePerSqm = 1000 * .data$runoff_cbm) %>% | ||
dplyr::summarise(datetime_min = min(.data$tBeg), | ||
datetime_max = max(.data$tEnd), | ||
timeperiod_days = as.numeric(diff(c(datetime_min, datetime_max))), | ||
timeperiod_years = timeperiod_days/365, | ||
number_of_events = dplyr::n(), | ||
events_per_year = number_of_events / timeperiod_years, | ||
runoff_LitrePerSqm_q00 = quantile(.data$runoff_LitrePerSqm, probs = 0), | ||
runoff_LitrePerSqm_q01 = quantile(.data$runoff_LitrePerSqm, probs = 0.01), | ||
runoff_LitrePerSqm_q05 = quantile(.data$runoff_LitrePerSqm, probs = 0.05), | ||
runoff_LitrePerSqm_q10 = quantile(.data$runoff_LitrePerSqm, probs = 0.10), | ||
runoff_LitrePerSqm_q25 = quantile(.data$runoff_LitrePerSqm, probs = 0.25), | ||
runoff_LitrePerSqm_q50 = quantile(.data$runoff_LitrePerSqm, probs = 0.5), | ||
runoff_LitrePerSqm_q75 = quantile(.data$runoff_LitrePerSqm, probs = 0.75), | ||
runoff_LitrePerSqm_q90 = quantile(.data$runoff_LitrePerSqm, probs = 0.9), | ||
runoff_LitrePerSqm_q95 = quantile(.data$runoff_LitrePerSqm, probs = 0.95), | ||
runoff_LitrePerSqm_q99 = quantile(.data$runoff_LitrePerSqm, probs = 0.99), | ||
runoff_LitrePerSqm_q100 = quantile(.data$runoff_LitrePerSqm, probs = 1)) | ||
|
||
|
||
peak <- performances %>% | ||
tidyr::unnest(.data$events_max) | ||
|
||
sel_cols <- c("zone_id", | ||
"lid_name_tidy", | ||
"scenario_name", | ||
"lid_area_fraction", | ||
"max_total_runoff_mmPerHour", | ||
"tBeg", | ||
"tEnd") | ||
|
||
peak_stats <- peak %>% | ||
dplyr::select(tidyselect::all_of(sel_cols)) %>% | ||
dplyr::group_by(.data$zone_id, | ||
.data$lid_name_tidy, | ||
.data$scenario_name, | ||
.data$lid_area_fraction) %>% | ||
dplyr::summarise(datetime_min = min(.data$tBeg), | ||
datetime_max = max(.data$tEnd), | ||
timeperiod_days = as.numeric(diff(c(datetime_min, datetime_max))), | ||
timeperiod_years = timeperiod_days/365, | ||
number_of_events = dplyr::n(), | ||
events_per_year = number_of_events / timeperiod_years, | ||
runoff_max_mmPerHour_q00 = quantile(.data$max_total_runoff_mmPerHour, probs = 0), | ||
runoff_max_mmPerHour_q01 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.01), | ||
runoff_max_mmPerHour_q05 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.05), | ||
runoff_max_mmPerHour_q10 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.10), | ||
runoff_max_mmPerHour_q25 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.25), | ||
runoff_max_mmPerHour_q50 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.5), | ||
runoff_max_mmPerHour_q75 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.75), | ||
runoff_max_mmPerHour_q90 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.9), | ||
runoff_max_mmPerHour_q95 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.95), | ||
runoff_max_mmPerHour_q99 = quantile(.data$max_total_runoff_mmPerHour, probs = 0.99), | ||
runoff_max_mmPerHour_q100 = quantile(.data$max_total_runoff_mmPerHour, probs = 1)) | ||
|
||
list(event_max_percentiles = peak_stats, | ||
event_sum_percentiles = volume_stats | ||
) | ||
} |
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
Oops, something went wrong.