| Title: | R Package of Berlin Water Model |
|---|---|
| Description: | R Package of Berlin Water Model. |
| Authors: | Michael Rustler [aut, cre] (ORCID: <https://orcid.org/0000-0003-0647-7726>), Daniel Wicke [aut] (ORCID: <https://orcid.org/0000-0002-5722-5433>), IMPETUS [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
| Maintainer: | Michael Rustler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-19 09:43:03 UTC |
| Source: | https://github.com/KWB-R/kwb.BerlinWaterModel.public |
Add Direct Rain and Evaporation to flows_in_out config for sections with defined area_m2
add_rain_direct_and_evaporation(config)add_rain_direct_and_evaporation(config)
config |
config object as retrieved by |
config with added flows_in_out for sections with defined area_m2, in case none area_m2 is defined the original config is returned
Add scenario
add_scenario(config, use_scenario = FALSE, debug = TRUE)add_scenario(config, use_scenario = FALSE, debug = TRUE)
config |
config as retrieved by |
use_scenario |
use scenario (default: FALSE) |
debug |
print debug messages (default: TRUE) |
list with input parameters required for function prepare_input
Add substances
add_substances(config)add_substances(config)
config |
config as retrieved by |
adds new columns 'conc_<substance-name.kg.m3' and re-calculates input concentrations from (ng|ug|mg|g)/L to kg/m3
Add tracers
add_tracers(config)add_tracers(config)
config |
config object as retrieved by |
adds new columns 'conc_tracer.xxx' for four tracers ('CSO', 'inlet', 'rain_runoff' and 'WWTP') to flows_in_out for tracking sources withint the water cycle
Aggregate Flows Monthly
aggregate_flows_monthly(flows, aggregation_function = median)aggregate_flows_monthly(flows, aggregation_function = median)
flows |
flows as retrieved by |
aggregation_function |
function used for aggregation (default: median) |
tibble with monthly aggregated flows data
Aggregate Qualities Monthly
aggregate_qualities_monthly( qualities, aggregation_function = median, minimum_tracer_sum = 0.999 )aggregate_qualities_monthly( qualities, aggregation_function = median, minimum_tracer_sum = 0.999 )
qualities |
list as retrieved by |
aggregation_function |
function used for aggregation (default: median) |
minimum_tracer_sum |
minimum tracer sum (default: 0.999 i.e. 99.9 percent) for filtering out results for with tracer has not reached almost 100 percent |
list with sublist "conc" with monthly aggregated concentrations data
Bank Filtration Share: convert equation
bfs_convert_equation( df, col_equation_a = "equation_a", col_equation_b = "equation_b" )bfs_convert_equation( df, col_equation_a = "equation_a", col_equation_b = "equation_b" )
df |
data frame with bank filtration share equations, defined in sublist
config$bfstypes_equations as retrieved by |
col_equation_a |
column name of equation parameter a (default: "equation_a") |
col_equation_b |
column name of equation parameter b (default: "equation_b") |
adds "equation_function" to data frame
Calculate Concentration
calc_conc(c_in, c_0, Q, V, k, t)calc_conc(c_in, c_0, Q, V, k, t)
c_in |
c_in concentration of inflow |
c_0 |
c_0 concentration in section at t = 0 |
Q |
total inflow rate into section (m3/s) |
V |
volume of section (m3) |
k |
degradation parameter |
t |
time in seconds (s) |
concentration of substance at specific time
calc_conc(c_in = 10, c_0 = 0, Q = 40000, V = 300000, k = 0, t = 1)calc_conc(c_in = 10, c_0 = 0, Q = 40000, V = 300000, k = 0, t = 1)
Calculate Flow
calculate_flow( df, input, shares_timeseries_wide = NULL, config, use_dynamic = FALSE, return_inputs = FALSE, debug = TRUE )calculate_flow( df, input, shares_timeseries_wide = NULL, config, use_dynamic = FALSE, return_inputs = FALSE, debug = TRUE )
df |
data frame with model as retrieved by |
input |
input flows as retrieved by |
shares_timeseries_wide |
shares timeseries in wide formate, as retrieved
by |
config |
list with config as imported with |
use_dynamic |
for multiple outputs only: should static shares (as defined in column "section_out_share" of "outflows_multiple.csv") be used for separating the flow within a section or a function (as defined in column "section_out_function" of "outflows_multiple.csv")), (default: FALSE) |
return_inputs |
should also input data be returned in result dataset (default: FALSE) |
debug |
print debug messages (default: TRUE) |
tibble with Urban Water Model results
Computes discharge statistics from a daily or hourly flow dataset
for each river section. The function supports both daily data
(using a date column) and hourly data (using a datetime column),
depending on the "temporal_resolution" attribute of the input.
calculate_flow_stats(flows)calculate_flow_stats(flows)
flows |
A data frame containing a date or datetime column
(depending on |
The returned statistics include:
MQ Mean discharge
MNQ_years Mean of yearly minimum values (yearly low flows)
MHQ_years Mean of yearly maximum values (yearly high flows)
NNQ Overall minimum discharge (absolute low flow)
HHQ Overall maximum discharge (absolute high flow)
Additional tables contain statistics per year and per month, including monthly mean, monthly minimum, and monthly maximum discharges.
A list with three elements:
A tibble with discharge statistics per section (MQ, MNQ_years, MHQ_years, NNQ, HHQ).
A tibble with statistics per section and year (MQ, MNQ_months, MHQ_months, NQ, HQ).
A tibble with statistics per section and month (MQ, MNQ_same_months, MHQ_same_months, NQ, HQ).
Calculate Flowpath
calculate_flowpath(flow_name, links, nodes, backward = FALSE)calculate_flowpath(flow_name, links, nodes, backward = FALSE)
flow_name |
flow name (as named in nodes) where calculation should start |
links |
links |
nodes |
nodes |
backward |
should flowpath be calculated backwards? (default: FALSE) |
data frame with column "order" indicating the flow path order
Calculate Flows
calculate_flows( df_order, input, shares_timeseries_wide = NULL, config, use_dynamic = FALSE, return_inputs = FALSE, debug = TRUE )calculate_flows( df_order, input, shares_timeseries_wide = NULL, config, use_dynamic = FALSE, return_inputs = FALSE, debug = TRUE )
df_order |
list for each order id (corresponding to same level of distance of section from selected outflow) |
input |
input flows as retrieved by |
shares_timeseries_wide |
shares timeseries in wide format, as retrieved
by |
config |
list with config as imported with |
use_dynamic |
for multiple outputs only: should static shares (as defined in column "section_out_share" of "outflows_multiple.csv") be used for separating the flow within a section or a function (as defined in column "section_out_function" of "outflows_multiple.csv")), (default: FALSE) |
return_inputs |
should also input data be returned in result dataset (default: FALSE) |
debug |
print debug messages (default: TRUE) |
returns modelled flows in tibble format
Calculate Flows Automatically
calculate_flows_auto( config, input_list, network, use_dynamic = FALSE, debug = FALSE )calculate_flows_auto( config, input_list, network, use_dynamic = FALSE, debug = FALSE )
config |
list with config as imported with |
input_list |
input_list as retrieved by |
network |
tibble with water cycle flow network data, as retrieved by
|
use_dynamic |
for multiple outputs only: should static shares (as defined in column "section_out_share" of "outflows_multiple.csv") be used for separating the flow within a section or a function (as defined in column "section_out_function" of "outflows_multiple.csv")), (default: FALSE) |
debug |
print debug messages (default: FALSE) |
tibble with flows
Calculate Outflows
calculate_outflows( list_order, input, config, use_dynamic = TRUE, return_inputs )calculate_outflows( list_order, input, config, use_dynamic = TRUE, return_inputs )
list_order |
list for each order id (corresponding to same level of distance of section from selected outflow) |
input |
input as retrieved by |
config |
list with config as imported with |
use_dynamic |
for multiple outputs only: should static shares (as defined in column "section_out_share" of "outflows_multiple.csv") be used for separating the flow within a section or a function (as defined in column "section_out_function" of "outflows_multiple.csv")), (default: TRUE) |
return_inputs |
should also input data be returned in result dataset (default: FALSE) |
tibble with outflows added to provided dataset
Calculate Qualities
calculate_qualities( input_list, flows, network, config, reverse_flow = FALSE, branchwise = TRUE, max_sections = NULL, debug = TRUE )calculate_qualities( input_list, flows, network, config, reverse_flow = FALSE, branchwise = TRUE, max_sections = NULL, debug = TRUE )
input_list |
input_list as retrieved by |
flows |
tibble with (modelled) flows for the network (e.g. precomputed upstream by the user) |
network |
tibble with water cycle flow network data, as retrieved by
|
config |
list with config as imported with |
reverse_flow |
calculate reverse flow (default: FALSE) |
branchwise |
improved calculation workflow minimising unneeded section calculations (default: TRUE) |
max_sections |
restrict number of calculated sections in case problems occur. Provide a number <= number of sections to be calculated. If NULL, all sections will be calculated (default: NULL). Only used if reverse_flow = FALSE |
debug |
print debug messages (default: TRUE) |
returns modelled qualities in tibble format
Calculate Qualities Backward
calculate_qualities_backward(input_list, flows, network, config, debug = TRUE)calculate_qualities_backward(input_list, flows, network, config, debug = TRUE)
input_list |
input_list as retrieved by |
flows |
flows as retrieved by xxxx |
network |
tibble with water cycle flow network data, as retrieved by
|
config |
list with config as imported with |
debug |
print debug messages (default: TRUE) |
returns modelled flows in tibble format
Calculate Qualities Backward Branchwise
calculate_qualities_backward_branchwise( input_list, flows, network, config, debug = TRUE )calculate_qualities_backward_branchwise( input_list, flows, network, config, debug = TRUE )
input_list |
input_list as retrieved by |
flows |
flows as retrieved by xxxx |
network |
tibble with water cycle flow network data, as retrieved by
|
config |
list with config as imported with |
debug |
print debug messages (default: TRUE) |
returns modelled flows in tibble format
Calculate Qualities Forward
calculate_qualities_forward( input_list, flows, network, config, max_sections = NULL, debug = TRUE )calculate_qualities_forward( input_list, flows, network, config, max_sections = NULL, debug = TRUE )
input_list |
input_list as retrieved by |
flows |
tibble with (modelled) flows for the network (e.g. precomputed upstream by the user) |
network |
tibble with water cycle flow network data, as retrieved by
|
config |
list with config as imported with |
max_sections |
restrict number of calculated sections in case problems occur. Provide a number <= number of sections to be calculated. If NULL, all sections will be calculated (default: NULL). Only used if reverse_flow = FALSE |
debug |
print debug messages (default: TRUE) |
returns modelled flows in tibble format
Calculate Quality in Section
calculate_quality( df, input, shares_timeseries_wide = NULL, flows, quality = NULL, config, reverse_flow = FALSE, result_type = "list", debug = FALSE )calculate_quality( df, input, shares_timeseries_wide = NULL, flows, quality = NULL, config, reverse_flow = FALSE, result_type = "list", debug = FALSE )
df |
data frame with model as retrieved by |
input |
model input data flows as retrieved by |
shares_timeseries_wide |
shares timeseries in wide format, as retrieved
by |
flows |
flows as retrieved by |
quality |
list with sublist "conc" and "load" for all sections (default: NULL) |
config |
list with config as imported with |
reverse_flow |
calculate reverse flow (default: FALSE) |
result_type |
define how the results should be returned. either a tibble with loads and concentrations in long format.(if result_type == "tibble"), a list with concentrations in wide format (result_type == "list") or a list with loads in wide format (result_type == "load") |
debug |
print debug messages (default: FALSE) |
tibble with Urban Water Model results with loads and concentrations (if result_type == "raw"), a list with concentrations (result_type == "conc" or "load") or a list with loads, default: "list"
Check backflows multiple
check_backflows_multiple(config)check_backflows_multiple(config)
config |
list with config as imported with |
nothing besides stops the code in case checks do not pass or message in case no config file configs/backflows_multiple.csv is provided
Check if function and calculate flow
check_if_function_and_calculate_flow(df, q)check_if_function_and_calculate_flow(df, q)
df |
data frame with one row containing column 'section_out_function_parsed' with function for calculating flow |
q |
flow vector |
if function: calculated flow vector, if not: NA_real
Check Network Errors
check_network_errors(network)check_network_errors(network)
network |
tibble with water cycle flow network network, as retrieved by
|
list with information on network errors
Check outflow multiple dynamic functions
check_outflow_multiple_dynamic_functions( config, q = 1, allowed_relative_offset_percent = 0.001 )check_outflow_multiple_dynamic_functions( config, q = 1, allowed_relative_offset_percent = 0.001 )
config |
list with config as imported with |
q |
total section flow used for testing, needs to be a scalar! (default: 1) |
allowed_relative_offset_percent |
maximum allowed percental offset for sum of all section outflows compared to section inflow (i.e. parameter q), default: 0.0001) |
nothingt if check passes for all outflow_id s with defined functions, otherwise error
Combine and clean dataframe
combine_and_clean_dfs(list)combine_and_clean_dfs(list)
list |
list miwth Urban Water Model results |
tibble with Urban Water Model results
Computes yearly, monthly and aggregated abstraction metrics for a single gallery (Brunnengalerie).
compute_gallery_kpis( df, gallery_col = "gallery", date_col = "date", q_col = "cbm_per_day", temporal_resolution = c("auto", "daily", "monthly"), date_min = NULL, date_max = NULL )compute_gallery_kpis( df, gallery_col = "gallery", date_col = "date", q_col = "cbm_per_day", temporal_resolution = c("auto", "daily", "monthly"), date_min = NULL, date_max = NULL )
df |
A |
gallery_col |
Name of the gallery column (default: |
date_col |
Name of the date column (default: |
q_col |
Name of the abstraction column (e.g. |
temporal_resolution |
Character string specifying the temporal
resolution, one of |
date_min |
Optional start date of the observation period. If
|
date_max |
Optional end date of the observation period. If
|
The function automatically detects whether daily values were synthetically
generated from monthly data, e.g. by completing a daily grid and applying
tidyr::fill(direction = "up"). In that case, all volume-based yearly
and monthly metrics are computed, but daily extreme metrics
(Q1Ist, MQ1Ist, Q30, MQ30) are suppressed and
returned as NA, because they would not represent real daily extremes.
Months with NA or zero abstraction are excluded from the calculation
of monthly-based KPIs (e.g. NQMonat, HQMonat, MQMonat). Additional size
indicators are provided: n_months_with_data,
n_months_in_operation and n_months_observation_period per
gallery, as well as two percentage indicators describing the share of
operational months within the observed data and within the full observation
period.
A named list with the following elements:
per_year |
A tibble of yearly metrics per gallery and year, including
yearly volumes (e.g. |
per_gallery |
A tibble of aggregated metrics per gallery over the full
observation period (e.g. |
per_month |
A tibble of monthly metrics per gallery and calendar
month aggregated over all years (e.g. |
meta |
A named list with meta information such as
|
Configuration: Read
config_read( config_dir = system.file("extdata/config/network_complete_mean-start-conc", package = "kwb.BerlinWaterModel.public"), file_encoding = "UTF-8" )config_read( config_dir = system.file("extdata/config/network_complete_mean-start-conc", package = "kwb.BerlinWaterModel.public"), file_encoding = "UTF-8" )
config_dir |
directory with configuration files (default: system.file("extdata/config/network_complete_mean-start-conc", package = "kwb.BerlinWaterModel")). It is mandatory that there are three files within this folder: "flows_in_out.csv", "outflows_multiple.csv" and "sections.csv" |
file_encoding |
encoding for reading the files (default: "UTF-8") |
list with three sublists "flows_in_out", "outflows_multiple" and "sections
## Not run: config <- kwb.BerlinWaterModel.public::config_read() config ## End(Not run)## Not run: config <- kwb.BerlinWaterModel.public::config_read() config ## End(Not run)
Convert concentration units to kg/m3
convert_concentration_units(df, return_inputs = FALSE)convert_concentration_units(df, return_inputs = FALSE)
df |
data frame with "conc_ |
return_inputs |
should input data frame also be returned (default: FALSE) or only newly calculated columns? |
tibble with "conc_
df <- data.frame( conc_As.ng.L = c(10, 50, 100), # Nanogramm pro Liter conc_Zn.ug.L = c(500, 1000, 2000), # Mikrogramm pro Liter conc_Fe.mg.L = c(0.1, 0.2, 0.3), # Milligramm pro Liter conc_Cu.g.L = c(0.005, 0.01, 0.02) # Gramm pro Liter ) convert_concentration_units(df, return_inputs = TRUE)df <- data.frame( conc_As.ng.L = c(10, 50, 100), # Nanogramm pro Liter conc_Zn.ug.L = c(500, 1000, 2000), # Mikrogramm pro Liter conc_Fe.mg.L = c(0.1, 0.2, 0.3), # Milligramm pro Liter conc_Cu.g.L = c(0.005, 0.01, 0.02) # Gramm pro Liter ) convert_concentration_units(df, return_inputs = TRUE)
Dataset with combined sewer overflow events for one rainfall rainfall event simulated with Infoworks in 2019
csocso
A tibble with 12,096 rows and five columns
filename of data origin
datetime
seconds
CSO_id
flow (cbm per second)
Daily potential evaporation based on DWD 1x1 km raster data.
evapo_pevapo_p
A tibble with 365 rows and 10 columns:
Name of the file from the DWD https/ftp server
Date
Year
Month
Day
Mean (mm/d) for n raster cells (defined in n_values)
Standard deviation (mm/d) for n raster cells (defined in n_values)
Minimum (mm/d) for n raster cells (defined in n_values)
Maximum (mm/d) for n raster cells (defined in n_values)
Number of selected raster cells
https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/evapo_p/DESCRIPTION_gridsgermany_daily_evapo_p_en.pdf https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/evapo_p/
For each row in df, this function assumes that the time column
contains a monthly value at (or near) the end of a month
(e.g. "2002-01-31" or "2002-01-31 23:00:00") and expands it backwards
to all days or all hours from the 1st of that month up to the given
timestamp.
fill_month_to_start( df, date_col = "date", datetime_col = "datetime", temporal_res = c("auto", "days", "hours"), date_min = NULL, date_max = NULL )fill_month_to_start( df, date_col = "date", datetime_col = "datetime", temporal_res = c("auto", "days", "hours"), date_min = NULL, date_max = NULL )
df |
A data frame or tibble. |
date_col |
Name of the daily date column (default: "date"). |
datetime_col |
Name of the hourly datetime column (default: "datetime"). |
temporal_res |
One of "auto", "days", "hours". If "auto",
the presence of |
date_min |
Optional lower bound of the output time window. For
daily mode this is interpreted as |
date_max |
Optional upper bound of the output time window.
Same interpretation as |
If temporal_res = "auto" (default), the function chooses
daily expansion when a column date is present and hourly expansion
when a column datetime is present.
The resulting series can optionally be cropped to a user-defined time
window via date_min and date_max.
A tibble where each original row is expanded so that all days (for
"days") or all hours (for "hours") from the 1st of the respective
month up to the original timestamp are present. All other columns
are copied to the created rows. The result is then cropped to
[date_min, date_max] if those are supplied. The name of the time
column is preserved ("date" or "datetime").
Fill Timeseries based on User Defined Intervall (days, hours, minutes or seconds)
fill_timeseries( df, col_datetime = "date", temporal_resolution = "days", direction = "up" )fill_timeseries( df, col_datetime = "date", temporal_resolution = "days", direction = "up" )
df |
data frame with data |
col_datetime |
column of date or datetime |
temporal_resolution |
select one of ("days", "hours", "minutes", "seconds"), (default: "days") |
direction |
in which direction should the parameter be filled ("up" or "down"), default: "up" |
tibble with filled dates. Note that if min(daste) == "xxxx-xx-end-of-month-day" the min(date) is set to "xxxx-xx-01", as monthly measured (originally summed) values were set to the last day of the month, but are valid for the whole month
Helper function: find node order
find_node_orders(links, nodes, start_node, reverse = FALSE, mode = "out")find_node_orders(links, nodes, start_node, reverse = FALSE, mode = "out")
links |
links |
nodes |
nodes |
start_node |
start node |
reverse |
should network direction be reversed? (default: FALSE) |
mode |
Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If out then the shortest paths from the vertex, if in then to it will be considered. If all, the default, then the graph is treated as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs (default: "out") |
data frame with additional column "order"
Get Flowpath Table
get_flowpath_table(outflow_id, network, config)get_flowpath_table(outflow_id, network, config)
outflow_id |
id of outflow section |
network |
tibble with water cycle flow network data, as retrieved by
|
config |
config |
list for each order id containing tibble with all sections of same order id
Helper to flatten the meta entries from the kpis list-column
in ww_galleries_lookup (or a similar lookup table). Each gallery gets
one row with all meta fields as columns.
get_gallery_kpis_meta(lookup)get_gallery_kpis_meta(lookup)
lookup |
A tibble with columns |
A tibble with one row per gallery and all meta information expanded
into regular columns (e.g. temporal_resolution,
synthetic_daily_from_month, has_daily_extremes, ...),
including waterworks and gallery.
Helper to flatten the nested kpis$per_gallery entries from
ww_galleries_lookup (or a similar lookup table) into a single tibble.
get_gallery_kpis_per_gallery(lookup)get_gallery_kpis_per_gallery(lookup)
lookup |
A tibble with columns |
This returns one row per gallery with all aggregated KPIs that were computed
over the full observation period (e.g. MQA, NQA, HQA,
MNQA, NNQA, MHQA, HHQA, MQ365,
HQ365, MQ1Ist, MQ30, ...).
Any waterworks or gallery columns inside per_gallery
are dropped to avoid name clashes; the outer ID columns are kept.
A tibble with one row per gallery, containing all aggregated KPIs
from kpis$per_gallery and the identifying columns
waterworks and gallery.
Helper to flatten the nested kpis$per_month entries from
ww_galleries_lookup (or a similar lookup table) into a single tibble.
get_gallery_kpis_per_month(lookup)get_gallery_kpis_per_month(lookup)
lookup |
A tibble with columns |
A tibble with monthly KPIs (gallery × calendar month), including
the columns waterworks and gallery.
Helper to flatten the nested kpis$per_year entries from
ww_galleries_lookup (or a similar lookup table) into a single tibble.
get_gallery_kpis_per_year(lookup)get_gallery_kpis_per_year(lookup)
lookup |
A tibble with columns |
A tibble with yearly KPIs, one row per gallery and year, including
the columns waterworks and gallery.
Helper function: get ids from names
get_ids_from_names(vector, config)get_ids_from_names(vector, config)
vector |
vector with names |
config |
config as retrieved by |
tibble with section names and ids contained in configuration
Helper function: get link names
get_link_names(network)get_link_names(network)
network |
tibble with water cycle flow network data, as retrieved by
|
tibble with link names and columns source and target
Helper function: get names from ids
get_names_from_ids(vector, config)get_names_from_ids(vector, config)
vector |
vector with ids |
config |
config as retrieved by |
tibble with section names and ids contained in configuration
Helper function: get nodes
get_nodes(network, config)get_nodes(network, config)
network |
tibble with water cycle flow network data, as retrieved by
|
config |
config as retrieved by |
tibble with columns name (from_name) and group (source_group)
Get Reverse Flows Per Section
get_reverse_flows_per_section(flows)get_reverse_flows_per_section(flows)
flows |
flows |
tibble with sections ordered decreasing by number of data points below zero and date_min (first neg. flow) and date_max (last neg. flow) within dataset
Helper function: get section idnames
get_section_idnames(config)get_section_idnames(config)
config |
config as retrieved by |
tibble with section names and ids contained in configuration
Dataset with inflows
inflowsinflows
A tibble with 21,170 rows and three columns
date
id of inflow station
daily average flow in cubicmeter per second
This function formats numeric values to a specified number of significant digits, avoiding scientific notation and unnecessary trailing zeros. Useful for plotting labels where readability is important across varying numeric magnitudes.
label_signif_clean(x, digits = 2)label_signif_clean(x, digits = 2)
x |
Numeric vector of values to be formatted. |
digits |
Integer. Number of significant digits to retain (default is 2). |
A character vector of formatted numbers.
label_signif_clean(c(0.0001234, 0.0456, 1.23, 12.3, 123.4))label_signif_clean(c(0.0001234, 0.0456, 1.23, 12.3, 123.4))
Returns a function that computes minor tick positions for a log10-scaled axis.
This is useful in conjunction with scale_y_log10() or scale_x_log10() in ggplot2,
where minor breaks are not added by default.
log10_minor_breaks(minor_base = 1:9)log10_minor_breaks(minor_base = 1:9)
minor_base |
A numeric vector of factors (default is 1:9) to be multiplied by each power of 10. This defines which intermediate ticks (e.g., 2, 3, ..., 9) are included between each decade (e.g., between 0.1 and 1). |
A function that takes a numeric range and returns a numeric vector of minor tick positions.
## Not run: ggplot2::scale_y_log10( limits = c(0.01, 100), breaks = c(0.01, 0.1, 1, 10, 100), minor_breaks = kwb.BerlinWaterModel.public::log10_minor_breaks() ) ## End(Not run)## Not run: ggplot2::scale_y_log10( limits = c(0.01, 100), breaks = c(0.01, 0.1, 1, 10, 100), minor_breaks = kwb.BerlinWaterModel.public::log10_minor_breaks() ) ## End(Not run)
This function merges two nested lists of the form
list(top_id = list(sub_id = tibble)), as used in the
BerlinWaterModel package. The structure (top-level and sub-level keys)
is preserved, and missing elements are added. If the same element exists
in both lists, the preferred side can be chosen.
merge_two_level_lists(x, y, prefer = c("left", "right"))merge_two_level_lists(x, y, prefer = c("left", "right"))
x |
A nested list with structure |
y |
A nested list with the same structure as |
prefer |
Character string, either |
A nested list with the same two-level structure containing the
union of all elements from x and y.
library(tibble) a <- list("S03" = list("S21" = tibble(a = 1, b = 2))) b <- list("S03" = list("S07" = tibble(a = 3, b = 4))) c <- list("S01" = list("S02" = tibble(a = 5, b = 6))) # Default: prefer = "left" merge_two_level_lists(a, b) # Right side overwrites in case of duplicates merge_two_level_lists(a, b, prefer = "right") # Merge more than two lists using purrr::reduce purrr::reduce(list(a, b, c), merge_two_level_lists)library(tibble) a <- list("S03" = list("S21" = tibble(a = 1, b = 2))) b <- list("S03" = list("S07" = tibble(a = 3, b = 4))) c <- list("S01" = list("S02" = tibble(a = 5, b = 6))) # Default: prefer = "left" merge_two_level_lists(a, b) # Right side overwrites in case of duplicates merge_two_level_lists(a, b, prefer = "right") # Merge more than two lists using purrr::reduce purrr::reduce(list(a, b, c), merge_two_level_lists)
Helper function: parse a and
parse_a_and_b(a, b)parse_a_and_b(a, b)
a |
parameter a |
b |
parameter b |
R function of parsed equation
a <- 1 b <- 2 parse_a_and_b(a, b)a <- 1 b <- 2 parse_a_and_b(a, b)
Helper function: parse equation
parse_equation(equation)parse_equation(equation)
equation |
equation in text form (either "constant" -> y = c or "ln" -> y = a * ln(x) + b) |
R function of parsed equation
Plot Network: complex
plot_network_complex(network, config, show_labels = FALSE)plot_network_complex(network, config, show_labels = FALSE)
network |
tibble with water cycle flow network data, as retrieved by
|
config |
list with config as imported with |
show_labels |
show labels (default: FALSE) |
complex network graph
Plot Network: simple
plot_network_simple(network)plot_network_simple(network)
network |
tibble with water cycle flow network data, as retrieved by
|
simple network graph
Prepare Model input
prepare_input( temporal_resolution = "days", config = config_read(), cso = kwb.BerlinWaterModel.public::cso, inflows = kwb.BerlinWaterModel.public::inflows, rain = kwb.BerlinWaterModel.public::rain, evapo_p = kwb.BerlinWaterModel.public::evapo_p, shares_timeseries = kwb.BerlinWaterModel.public::shares_timeseries, ww = kwb.BerlinWaterModel.public::ww, wwtp = kwb.BerlinWaterModel.public::wwtp, bfshare_dynamic = FALSE, share_wwtp_sch_to_nordgraben_timeseries = TRUE, share_wwtp_sch_panke_1 = 0.1, date_separation_panke_1_2 = "2015-04-15", share_wwtp_sch_panke_2 = 0.9, col_wwtp_sch = "Q_KW_SCH", col_wwtp_sch_nordgraben = "Q_KW_SCH_Nordgraben", col_wwtp_sch_panke = "Q_KW_SCH_Panke", col_panke_baseflow_no_Q_wwtp = "Panke_baseflow_no_Q_KW_SCH_Panke", date_min = "2002-01-01", date_max = "2022-12-31", debug = TRUE )prepare_input( temporal_resolution = "days", config = config_read(), cso = kwb.BerlinWaterModel.public::cso, inflows = kwb.BerlinWaterModel.public::inflows, rain = kwb.BerlinWaterModel.public::rain, evapo_p = kwb.BerlinWaterModel.public::evapo_p, shares_timeseries = kwb.BerlinWaterModel.public::shares_timeseries, ww = kwb.BerlinWaterModel.public::ww, wwtp = kwb.BerlinWaterModel.public::wwtp, bfshare_dynamic = FALSE, share_wwtp_sch_to_nordgraben_timeseries = TRUE, share_wwtp_sch_panke_1 = 0.1, date_separation_panke_1_2 = "2015-04-15", share_wwtp_sch_panke_2 = 0.9, col_wwtp_sch = "Q_KW_SCH", col_wwtp_sch_nordgraben = "Q_KW_SCH_Nordgraben", col_wwtp_sch_panke = "Q_KW_SCH_Panke", col_panke_baseflow_no_Q_wwtp = "Panke_baseflow_no_Q_KW_SCH_Panke", date_min = "2002-01-01", date_max = "2022-12-31", debug = TRUE )
temporal_resolution |
specify temporal resolution of model input dataset. (default: "days"). Valid options are: "days" or "hours" |
config |
model network configuration (as retrieved by |
cso |
cso dataset (default: kwb.BerlinWaterModel.public::cso) |
inflows |
inflows dataset (default: kwb.BerlinWaterModel.public::inflows) |
rain |
rain dataset (default: kwb.BerlinWaterModel.public::rain) |
evapo_p |
evaporation dataset (default: kwb.BerlinWaterModel.public::evapo_p) |
shares_timeseries |
shares timeseries dataset (default: kwb.BerlinWaterModel.public::shares_timeseries) |
ww |
waterworks dataset (default: kwb.BerlinWaterModel.public::ww) |
wwtp |
wastewater treatment plant dataset (default: kwb.BerlinWaterModel.public::wwtp) |
bfshare_dynamic |
should dynamic bankfiltration shares be used or the static ones contained in column "bank_filtration_share" of config$flows_in_out |
share_wwtp_sch_to_nordgraben_timeseries |
if TRUE time series to "Nordgraben" is used (column name defined in parameter "col_wwtp_sch_nordgraben") and remaining water is transfered to "Panke" (column name defined in parameter "col_wwtp_sch_panke") |
share_wwtp_sch_panke_1 |
share of WWTP Schoenerlinde to Panke before (default: 0.1) date_separation_panke_1_2; only used if share_wwtp_sch_to_nordgraben_timeseries == FALSE |
date_separation_panke_1_2 |
date to separate shares before (i.e. share_wwtp_sch_panke_1) and after (share_wwtp_sch_panke_2) given date (default: "2025-04-15") (default: 1 - share_wwtp_sch_panke); only used if share_wwtp_sch_to_nordgraben_timeseries == FALSE |
share_wwtp_sch_panke_2 |
share of WWTP Schoenerlinde to Panke before (default: 0.9) date_separation_panke_1_2; only used if share_wwtp_sch_to_nordgraben_timeseries == FALSE |
col_wwtp_sch |
column name of WWTP Schoenerlinde (default: "Q_KW_SCH") |
col_wwtp_sch_nordgraben |
column name of WWTP Schoenerlinde outflow to Nordgraben (default: "Q_KW_SCH_Nordgraben") |
col_wwtp_sch_panke |
column name of WWTP Schoenerlinde outflow to Panke (default: "Q_KW_SCH_Panke") |
col_panke_baseflow_no_Q_wwtp |
(default: "Panke_baseflow_no_Q_KW_SCH_Panke") |
date_min |
minimum date, i.e. start of simulation (default: "2002-01-01) |
date_max |
maximum date, i.e. end of simulation (default: "2022-12-31) |
debug |
print debug messages (default: TRUE) |
input dataset, will be filled in case temporal resolution in increased
Prepare Network Data
prepare_network(config)prepare_network(config)
config |
config as retrieved by |
data structure for plot_network functions and for further calculations
Preparew QsimVis Input
prepare_qsimVis_input(config, flows, qualities, rounding_digits = 3)prepare_qsimVis_input(config, flows, qualities, rounding_digits = 3)
config |
config list as retrieved by |
flows |
flows input data frame in "wide" format |
qualities |
qualities list input data structure for each section in wide format |
rounding_digits |
digits used for result data rounding (default: 3) |
data frame with flow data in long format joined with config$qsimVis data frame
Dataset with rainfall data (based on DWD station 0433)
rainrain
A tibble with 8,721 rows and two columns
datetime
hourly rainfall in mm for DWD rainstation 0433
Set Tracer Starting Concentrations To Final Modelling Results
set_tracer_starting_conc(config, qualities)set_tracer_starting_conc(config, qualities)
config |
config list structure as retrieved by |
qualities |
qualities list result structure |
config list with starting concentrations (defined in config$sections) based on qualities. The last time step is used as starting concentration
Set Tracer Starting Concentrations Statistics
set_tracer_starting_conc_stats( config, qualities, aggregation_function = median, minimum_tracer_sum = 0.999 )set_tracer_starting_conc_stats( config, qualities, aggregation_function = median, minimum_tracer_sum = 0.999 )
config |
config list structure as retrieved by |
qualities |
qualities list result structure |
aggregation_function |
function used for data aggregation (default: median) |
minimum_tracer_sum |
minimum tracer sum (default: 0.999 i.e. 99.9 percent) for filtering out results for with tracer has not reached almost 100 percent |
config list with starting concentrations (defined in config$sections) based on qualities
Helper: shorten WW flow id
shorten_ww_flow_id(df, col_flow_id = "flow_id")shorten_ww_flow_id(df, col_flow_id = "flow_id")
df |
df with WW flow data andf flow ids as columns |
col_flow_id |
column name with flow id (default: "flow_id") |
vector with shortened WW flow ids
Dataset with waterworks abstractions per gallery
wwww
A tibble with 828 rows and three columns
date
id of WW gallery
measured flow in cubicmeter per second, backcalculated from monthly abstraction sums by dividing through number of days in month
Dataset with WWTP inflows
wwtpwwtp
A tibble with 4015 rows and three columns
date
id of WWTP
measured flow in cubicmeter per second, backcalculated from monthly effluent sums by dividing through number of days in month