Skip to content

Commit 84d62aa

Browse files
committed
Prepare release v0.2.0
1 parent ee4b889 commit 84d62aa

39 files changed

Lines changed: 311 additions & 170 deletions

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Package: kwb.BerlinWaterModel.public
22
Title: R Package of Berlin Water Model
3-
Version: 0.1.0
3+
Version: 0.2.0
44
Authors@R: c(
5-
person("Daniel", "Wicke", , "daniel.wicke@kompetenz-wasser.de", role = "aut",
6-
comment = c(ORCID = "0000-0002-5722-5433")),
75
person("Michael", "Rustler", , "michael.rustler@kompetenz-wasser.de", role = c("aut", "cre"),
86
comment = c(ORCID = "0000-0003-0647-7726")),
7+
person("Daniel", "Wicke", , "daniel.wicke@kompetenz-wasser.de", role = "aut",
8+
comment = c(ORCID = "0000-0002-5722-5433")),
99
person("IMPETUS", role = "fnd"),
1010
person("Kompetenzzentrum Wasser Berlin gGmbH (KWB)", role = "cph")
1111
)
@@ -36,7 +36,9 @@ Imports:
3636
units
3737
Suggests:
3838
covr,
39+
DT,
3940
knitr,
41+
openxlsx,
4042
rmarkdown
4143
VignetteBuilder:
4244
knitr

NEWS.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# [kwb.BerlinWaterModel.public 0.2.0](https://github.com/KWB-R/kwb.BerlinWaterModel.public/releases/tag/v0.2.0) <small>2026-03-20</small>
2+
3+
* Finalisation of example input dataset for year 2019 (including WW/WWTP flows)
4+
5+
16
# [kwb.BerlinWaterModel.public 0.1.0](https://github.com/KWB-R/kwb.BerlinWaterModel.public/releases/tag/v0.1.0) <small>2025-12-17</small>
27

3-
* first public version of kwb.BerlinWaterMode.public for data management plan of IMPETUS EU project (flow data for gallery abstraction
8+
* First public version of kwb.BerlinWaterMode.public for data management plan of IMPETUS EU project (flow data for gallery abstraction
49
of water works and wastewater treatment plants preliminary set to 0, public data set in coordination by BWB and will be available soon)
510

611
* Added a `NEWS.md` file to track changes to the package.
712

8-
* see https://style.tidyverse.org/news.html for writing a good `NEWS.md`
13+
* See https://style.tidyverse.org/news.html for writing a good `NEWS.md`
914

1015

R/dataset_cso.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#' Dataset: Combined Sewer Overflows (cso) for a few rainfall events simulated with Infoworks
1+
#' Dataset: Combined Sewer Overflows (cso) for one rainfall event simulated with Infoworks in 2019
22
#'
3-
#' Dataset with combined sewer overflow events for a few rainfall events simulated with Infoworks
3+
#' Dataset with combined sewer overflow events for one rainfall rainfall event simulated with Infoworks
4+
#' in 2019
45
#'
5-
#' @format A tibble with 336,672 rows and five columns
6+
#' @format A tibble with 12,096 rows and five columns
67
#' \describe{
78
#' \item{file_name}{filename of data origin}
89
#' \item{datetime}{datetime}

R/dataset_evapo_p.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Daily potential evaporation based on DWD 1x1 km raster data.
44
#'
5-
#' @format A tibble with 7,670 rows and 10 columns:
5+
#' @format A tibble with 365 rows and 10 columns:
66
#' \describe{
77
#' \item{file}{Name of the file from the DWD https/ftp server}
88
#' \item{date}{Date}

R/dataset_inflows.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#' Dataset: Inflows
1+
load#' Dataset: Inflows
22
#'
33
#' Dataset with inflows
44
#'
5-
#' @format A tibble with 398,840 rows and three columns
5+
#' @format A tibble with 21,170 rows and three columns
66
#' \describe{
77
#' \item{date}{date}
88
#' \item{id}{id of inflow station}

R/dataset_rain.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Dataset with rainfall data (based on DWD station 0433)
44
#'
5-
#' @format A tibble with 247,076 rows and two columns
5+
#' @format A tibble with 8,721 rows and two columns
66
#' \describe{
77
#' \item{datetime}{datetime}
88
#' \item{DWD_0433}{hourly rainfall in mm for DWD rainstation 0433}

R/dataset_ww.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Dataset with waterworks abstractions per gallery
44
#'
5-
#' @format A tibble with 17,141 rows and three columns
5+
#' @format A tibble with 828 rows and three columns
66
#' \describe{
77
#' \item{date}{date}
88
#' \item{id}{id of WW gallery}

R/dataset_wwtp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Dataset with WWTP inflows
44
#'
5-
#' @format A tibble with 1,152 rows and three columns
5+
#' @format A tibble with 4015 rows and three columns
66
#' \describe{
77
#' \item{date}{date}
88
#' \item{id}{id of WWTP}

data-raw/config_complete.R

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ config <- kwb.BerlinWaterModel.public::add_rain_direct_and_evaporation(config)
99

1010
config <- kwb.BerlinWaterModel.public::add_tracers(config)
1111

12-
config <- kwb.BerlinWaterModel.public::add_substances(config)
12+
#config <- kwb.BerlinWaterModel.public::add_substances(config)
1313

1414
network <- kwb.BerlinWaterModel.public::prepare_network(config)
1515

1616

1717
# plot interactive network map ###############################################
1818

1919
### Network graph
20-
#net_complex <- kwb.BerlinWaterModel.public::plot_network_complex(network,
21-
# config,
22-
# show_labels = TRUE)
20+
net_complex <- kwb.BerlinWaterModel.public::plot_network_complex(
21+
network,
22+
config,
23+
show_labels = TRUE)
2324

24-
#htmlwidgets::saveWidget(net_complex, file = "water-cycle_complex.html")
25-
#zip(zipfile = "water-cycle_complex.zip", files = "water-cycle_complex.html")
25+
htmlwidgets::saveWidget(net_complex, file = "water-cycle_complex.html")
2626

2727

2828
# data preparation ###########################################################
@@ -48,30 +48,33 @@ input_list <- kwb.BerlinWaterModel.public::prepare_input(temporal_resolution = t
4848
ww = inputs$ww,
4949
wwtp = inputs$wwtp,
5050
bfshare_dynamic = FALSE, # use TRUE for dynamic bank filtration share (depending on Q)
51-
date_min = "2002-01-01",
52-
date_max = "2022-12-31")
51+
date_min = "2019-01-01",
52+
date_max = "2019-12-31")
5353

5454
################################################################################################
5555
### Calculate flows ############################################################################
5656
################################################################################################
5757

5858
system.time(
59-
flows_dynamic <- kwb.BerlinWaterModel.public::calculate_flows_auto(config = config,
60-
input_list = input_list,
61-
network = network,
62-
use_dynamic = TRUE, # FALSE: static values for flow shares at river branchings
63-
debug = TRUE)
59+
flows_dynamic <- kwb.BerlinWaterModel.public::calculate_flows_auto(
60+
config = config,
61+
input_list = input_list,
62+
network = network,
63+
use_dynamic = TRUE, # FALSE: static values for flow shares at river branchings
64+
debug = TRUE)
6465
)
6566

66-
flows_stats <- kwb.BerlinWaterModel.public::calculate_flow_stats(flows = flows_dynamic)
67+
flows_stats <- kwb.BerlinWaterModel.public::calculate_flow_stats(
68+
flows = flows_dynamic)
6769

68-
flows_dynamic_neg_flows_stat <- kwb.BerlinWaterModel.public::get_reverse_flows_per_section(flows = flows_dynamic)
69-
#openxlsx::write.xlsx(x = flows_neg_stat_evap_30, file = "flows_neg_stat_evap30_2019.xlsx")
70+
DT::datatable(flows_stats$per_section, caption = "Flow stats (per section)")
71+
DT::datatable(flows_stats$per_year, caption = "Flow stats (per year)")
72+
DT::datatable(flows_stats$per_month, caption = "Flow stats (per month)")
7073

74+
flows_dynamic_neg_flows_stat <- kwb.BerlinWaterModel.public::get_reverse_flows_per_section(
75+
flows = flows_dynamic)
7176

72-
# Save flows of one or all sections to xls
73-
openxlsx::write.xlsx(x = flows_dynamic, file = "flows_days_2019_start-con-2019.xlsx")
74-
# openxlsx::write.xlsx(x = flows_dynamic[c("date", "H03")], file = "flows_H03_days.xlsx")
77+
DT::datatable(flows_dynamic_neg_flows_stat, caption = "Sections with negative flows in 2019")
7578

7679

7780
################################################################################################
@@ -88,60 +91,13 @@ system.time(
8891
debug = FALSE)
8992
)
9093

91-
### Save qualities for one or all sections in XLSX
92-
#openxlsx::write.xlsx(x = qualities$conc$S21, file = "qualities_S21_days_dynamic_branching_fixJOH.xlsx")
93-
openxlsx::write.xlsx(x = qualities_00_dynamic_reverse$conc, file = "qualities_hours_2017-2022_Fluoranthen_KW-0,0037_RW-0,22_MWÜ-0,2.xlsx")
94+
### Save qualities for all sections in XLSX
95+
openxlsx::write.xlsx(x = qualities_00_dynamic_reverse$conc, file = "qualities_00_dynamic_reverse_concentrations.xlsx")
9496

9597
# save RDS for flows and qualities
96-
#saveRDS(flows_dynamic, file = "flows_hours_2002-2022.Rds")
97-
saveRDS(qualities_00_dynamic_reverse, file = "qualities_hours_2016-2022_Fluoranthen_KW-0,0037_RW-0,22_MWÜ-0,20.Rds")
98-
99-
# Read RDS for flows and qualities
100-
qualities_00_dynamic_reverse <- readRDS(file = "qualities_hours_2016-2022_Fluoranthen_KW-0,0037_RW-0,22_MWÜ-0,20.Rds")
101-
flows_dynamic <- readRDS(file = "flows_hours_2002-2022.Rds")
10298

99+
saveRDS(qualities_00_dynamic_reverse, file = "qualities_00_dynamic_reverse_concentrations.Rds")
103100

104-
#############################################################################################
105-
### prepare qsimVis output for map visualisation ############################################
106-
#############################################################################################
107-
108-
if(FALSE) {
109-
110-
qsimVis_input <- kwb.BerlinWaterModel.public::prepare_qsimVis_input(
111-
config = config,
112-
flows = flows_dynamic,
113-
qualities = qualities_00_dynamic_reverse) %>%
114-
dplyr::select(GewaesserId,
115-
Strang = "section_id",
116-
Km,
117-
tidyselect::starts_with("date"),
118-
cbm_per_second,
119-
tracer.cso,
120-
tracer.rain_runoff,
121-
tracer.wwtp
122-
#, ValsartansaeureAeq.mg.m3
123-
#, Fluoranthen.mg.m3
124-
) %>%
125-
dplyr::rename(Q = cbm_per_second)
126-
127-
# add section name
128-
for(x in config$sections$section_id){
129-
qsimVis_input$Strang[qsimVis_input$Strang == x] <-
130-
paste(x,config$sections$section_name[config$sections$section_id == x], sep = ".")
131-
}
132-
133-
# qsimVis_input[is.na(qsimVis_input)] <- 0
134-
135-
col_date_time_idx <- stringr::str_detect(names(qsimVis_input), "^date")
136-
names(qsimVis_input)[col_date_time_idx] <- "Datum"
137-
138-
qsimVis_input <- qsimVis_input %>%
139-
dplyr::mutate(Datum = format(Datum, format = "%d.%m.%Y %H:%M", tz = "UTC"))
140-
141-
#readr::write_csv2(qsimVis_input,"qsimVis_input2.csv") takes much longer for big datasets
142-
system.time(data.table::fwrite(qsimVis_input, "qsimVis_input_hours_2017-2022_Fluoranthen_KW-0,0037_RW-0,22_MWÜ-0,20.csv", sep = ";", dec = ","))
143-
144-
}
145101

146102
#############################################################################################
147103
### Diverse checks ##########################################################################

data-raw/inputs_public.R

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
config <- kwb.BerlinWaterModel.public::config_read(config_dir = "inst/extdata/config/network_complete")
22

3-
datetime_min <- lubridate::as_datetime("2018-01-01 00:00:00", tz = "UTC")
4-
datetime_max <- lubridate::as_datetime("2018-12-31 23:59:59", tz = "UTC")
5-
reduce_temporal_coverage <- FALSE
6-
no_ww_and_wwtp <- TRUE
3+
datetime_min <- lubridate::as_datetime("2019-01-01 00:00:00", tz = "UTC")
4+
datetime_max <- lubridate::as_datetime("2019-12-31 23:59:59", tz = "UTC")
5+
reduce_temporal_coverage <- TRUE
6+
no_ww_and_wwtp <- FALSETRUE
77

88
################################################################################################
99
# CSO data #####################################################################################
1010
################################################################################################
1111

12-
unzip("inst/extdata/input_data/cso/cso.zip",
13-
exdir = "inst/extdata/input_data/cso/csv/")
12+
# unzip("inst/extdata/input_data/cso/cso.zip",
13+
# exdir = "inst/extdata/input_data/cso/csv/")
1414

1515
cso_files <- list.files("inst/extdata/input_data/cso/csv/",
1616
pattern = "\\.csv$",
@@ -347,3 +347,61 @@ rain <- if(reduce_temporal_coverage) {
347347

348348
usethis::use_data(rain, overwrite = TRUE)
349349

350+
351+
# 4. Wasserflächen vorbereiten
352+
url <- "https://fbinter.stadt-berlin.de/fb/atom/Gewaesserkarte/Gewaesserkarte.zip"
353+
tfile <- basename(url)
354+
355+
download.file(url, destfile = basename(url))
356+
357+
unzip(zipfile = tfile,
358+
exdir = "lakes_berlin")
359+
360+
361+
lakes_berlin <- sf::read_sf("lakes_berlin/Gewaesser_Berlin_Flaechen.shp",
362+
options = "ENCODING=WINDOWS-1252") %>%
363+
dplyr::mutate(area = sf::st_area(.) %>% as.numeric()) %>%
364+
dplyr::arrange(dplyr::desc(area)) %>%
365+
sf::st_transform(4326) %>%
366+
sf::st_make_valid()
367+
368+
369+
lakes_berlin_sel <- lakes_berlin %>%
370+
dplyr::filter(area > 150000)
371+
372+
373+
## DWD datasets
374+
remotes::install_github("kwb-r/kwb.dwd@get-rid-of-rgdal")
375+
376+
377+
sf::write_sf(lakes_berlin_sel, "lakes_berlin_selected.shp")
378+
shape_file <- "lakes_berlin_selected.shp"
379+
380+
381+
382+
# Only data of full months can currently be read!
383+
evapo_p_raw <- kwb.dwd::read_daily_data_over_shape(
384+
#file = shape_file,
385+
shape = lakes_berlin_sel,
386+
variable = "evapo_p",
387+
from = "201901",
388+
to = "201912"
389+
#to = "202212"
390+
)
391+
392+
393+
evapo_p <- evapo_p_raw %>%
394+
dplyr::mutate(date = sprintf("%02d-%02d-%02d", year, month, day) %>% as.Date()) %>%
395+
tibble::as_tibble()
396+
397+
398+
evapo_p <- if(reduce_temporal_coverage) {
399+
evapo_p %>%
400+
dplyr::filter(date >= lubridate::as_date(datetime_min),
401+
date <= lubridate::as_date(datetime_max))
402+
} else {
403+
evapo_p
404+
}
405+
406+
407+
usethis::use_data(evapo_p, overwrite = TRUE)

0 commit comments

Comments
 (0)