Data Availability Waterworks Friedrichshagen
Michael Rustler
2024-12-23
Source:vignettes/data-availability_fri.Rmd
data-availability_fri.Rmd
1 Install R packages
if (! require("remotes")) {
install.packages("remotes", repos = "https://cloud.r-project.org")
}
remotes::install_github("kwb-r/kwb.geosalz", dependencies = TRUE)
2 Define paths
# Define paths and resolve placeholders
paths <- kwb.utils::resolve(list(
servername = Sys.getenv("servername"),
root_server = "//<servername>",
project = "geosalz",
rawdata = "<root_server>/rawdata/<project>/BWB_labor",
processing = "<root_server>/processing/<project>",
cleaned_data_dir = "<processing>/labor/cleaned-data",
cleaned_data_rds = "<cleaned_data_dir>/cleaned-data.Rds",
foerdermengen = "<rawdata>/2018-04-27 Rohwasser Bericht - Galeriefördermengen.xlsx",
parameters = "<rawdata>/2018-06-01 Lab Parameter.xlsx",
figures_dir = "<processing>/figures"
))
3 Input data
Checkout the Workflow vignette for
reproducing the creation of cleaned-data.Rds
.
library(kwb.geosalz)
## Load water quality data (<= 2000, prepared within first phase of Geosalz
## project!); for creation see the "workflow.Rmd" vignette
load(file = paths$cleaned_data_rds)
foerdermengen_ww <- kwb.geosalz::get_foerdermengen(paths$foerdermengen)
foerdermengen_fri_gal <- paths$foerdermengen %>%
kwb.geosalz::get_foerdermengen_gal_fri() %>%
dplyr::filter(!is.na(!.data$foerdermenge_m3))
readr::write_csv2(
foerdermengen_fri_gal,
file = file.path(paths$figures_dir, "foerdermengen_fri_gal.csv")
)
para_info <- kwb.geosalz::get_parameters_meta(paths$parameters)
labordaten_ww_timeseries <- labordaten_ww %>%
dplyr::filter(
prufgegenstand == "Rohwasser",
werk == "FRI"
)
readr::write_csv2(
labordaten_ww_timeseries,
file = file.path(paths$figures_dir, "Zeitreihen_FRI_Guete_Rohwasser.csv")
)
labordaten_ww_stats <- labordaten_ww_timeseries %>%
dplyr::group_by(
.data$para_id,
.data$para_kuerzel,
.data$para_kurzname,
.data$werk,
.data$galerie
) %>%
dplyr::summarise(
date_min = as.Date(min(.data$Date)),
date_max = as.Date(max(.data$Date)),
period_days = diff(c(.data$date_min, .data$date_max)),
number_of_samples = dplyr::n(),
mean_sampling_intervall_days = round(
.data$period_days/.data$number_of_samples
)
) %>%
dplyr::arrange(.data$para_id, .data$galerie)
readr::write_csv2(
labordaten_ww_stats,
file = file.path(paths$figures_dir, "Stats_FRI_Guete_Rohwasser.csv")
)
4 Visualisation
4.1 Water quality
#Check and in case the export directory is not available create it:
fs::dir_create(paths$figures_dir, recurse = TRUE)
print(sprintf("Export figures/plots to: %s", paths$figures_dir))
water_types <- c("Rohwasser")
for (water_type in water_types) {
pdf_file <- file.path(
paths$figures_dir,
sprintf("Zeitreihen_FRI_%s_Guete.pdf", water_type)
)
cat(sprintf("Creating plot:\n%s\n", pdf_file))
pdf(file = pdf_file, width = 14, height = 9)
for (sel_para_id in unique(labordaten_ww$para_id)) {
my_selection <- sprintf(
"%s (%s)",
para_info$para_kurzname[para_info$para_id == sel_para_id],
water_type
)
tmp <- labordaten_ww %>%
dplyr::filter(
prufgegenstand == water_type,
para_id == sel_para_id,
werk == "FRI"
) %>%
dplyr::filter(
stringr::str_detect(.data$galerie, pattern = "GWW", negate = TRUE)
)
y_label <- sprintf(
"%s (%s)",
para_info$para_kurzname[para_info$para_id == sel_para_id],
paste0(unique(tmp$UnitName_org), collapse = ", ")
)
if (nrow(tmp) > 0) {
cat(sprintf("for %s\n", my_selection))
g <- ggplot2::ggplot(tmp, mapping = ggplot2::aes_string(
x = "Date",
y = "DataValue",
col = "galerie"
)) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::theme_bw() +
ggplot2::ggtitle(label = my_selection) +
ggplot2::labs(x = "", y = y_label)
print(g)
} else {
cat(sprintf("not data availabe for %s\n", my_selection))
}
}
dev.off()
}
4.2 Yearly Abstraction Volume
4.2.1 Total
pdf_file <- file.path(
paths$figures_dir,
"Zeitreihen_FRI_Gesamt_Jahresfoerdermengen.pdf"
)
pdf(file = pdf_file, width = 14, height = 9)
foerdermengen_ww %>%
dplyr::filter(.data$Wasserwerk == "Friedrichshagen") %>%
ggplot2::ggplot(mapping = ggplot2::aes_string(
x = "year",
y = "Foerdermenge_m3",
col = "werk"
)) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::theme_bw() +
ggplot2::ggtitle(label = "Wasserwerk Friedrichshagen") +
ggplot2::labs(x = "Datum", y = "Jahresf\u00F6rdermenge (m3)")
dev.off()
4.2.2 By Well Galeries
pdf_file <- file.path(
paths$figures_dir,
"Zeitreihen_FRI_Galerien_Jahresfoerdermengen.pdf"
)
pdf(file = pdf_file, width = 14, height = 9)
foerdermengen_fri_gal %>%
ggplot2::ggplot(mapping = ggplot2::aes_string(
x = "date",
y = "foerdermenge_m3",
col = "galerie"
)) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::theme_bw() +
ggplot2::ggtitle(label = "Brunnengalerien FRI") +
ggplot2::labs(x = "Datum", y = "Jahresf\u00F6rdermenge (m3)")
dev.off()
pdf_file <- file.path(
paths$figures_dir,
"Zeitreihen_FRI_Galerien_Jahresfoerdermengen_multipage.pdf"
)
pdf(file = pdf_file, width = 14, height = 9)
tmp <- foerdermengen_fri_gal %>%
dplyr::mutate(foerdermenge_million_m3 = .data$foerdermenge_m3/1000000)
n_pages <- tmp %>%
dplyr::count(.data$galerie) %>%
dplyr::pull(.data$galerie) %>%
length()
for (page in seq_len(n_pages)) {
print(
tmp %>%
ggplot2::ggplot(mapping = ggplot2::aes_string(
x = "date",
y = "foerdermenge_million_m3"
)) +
ggforce::facet_wrap_paginate(~ galerie, ncol = 1, nrow = 1, page = page) +
#ggplot2::facet_wrap(~ galerie, ncol = 1) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::labs(x = "Datum", y = "Foerdermenge (m3/Jahr)") +
ggplot2::theme_bw()
)
}
#dev.off()
kwb.utils::finishAndShowPdf(PDF = pdf_file)
5 Session Info
Plattform
name | value |
---|---|
version | R version 4.4.2 (2024-10-31 ucrt) |
os | Windows Server 2022 x64 (build 20348) |
system | x86_64, mingw32 |
ui | RTerm |
language | en |
collate | English_United States.utf8 |
ctype | English_United States.utf8 |
tz | UTC |
date | 2024-12-23 |
pandoc | 3.1.11 @ C:/HOSTED1/windows/pandoc/31F3871.11/x64/PANDOC~1.11/ (via rmarkdown) |
Packages
#> package * version date (UTC) lib source
#> bslib 0.8.0 2024-07-29 [1] CRAN (R 4.4.1)
#> cachem 1.1.0 2024-05-16 [1] CRAN (R 4.4.0)
#> cli 3.6.3 2024-06-21 [1] RSPM (R 4.4.0)
#> desc 1.4.3 2023-12-10 [1] CRAN (R 4.4.0)
#> digest 0.6.37 2024-08-19 [1] RSPM (R 4.4.0)
#> dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.4.0)
#> evaluate 1.0.1 2024-10-10 [1] CRAN (R 4.4.1)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.0)
#> fs 1.6.5 2024-10-30 [1] CRAN (R 4.4.1)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.0)
#> glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.1)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
#> htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.4.0)
#> jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.4.0)
#> jsonlite 1.8.9 2024-09-20 [1] RSPM (R 4.4.0)
#> knitr 1.49 2024-11-08 [1] RSPM (R 4.4.0)
#> kwb.utils 0.15.0 2024-04-25 [1] Github (kwb-r/kwb.utils@4415aa2)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0)
#> pillar 1.10.0 2024-12-17 [1] CRAN (R 4.4.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0)
#> pkgdown 2.1.1 2024-09-17 [1] RSPM (R 4.4.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.0)
#> ragg 1.3.0 2024-03-13 [1] CRAN (R 4.4.0)
#> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.0)
#> rmarkdown 2.29 2024-11-04 [1] CRAN (R 4.4.2)
#> sass 0.4.9 2024-03-15 [1] CRAN (R 4.4.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0)
#> systemfonts 1.1.0 2024-05-15 [1] CRAN (R 4.4.0)
#> textshaping 0.3.7 2023-10-09 [1] CRAN (R 4.4.0)
#> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.0)
#> tidyr * 1.3.1 2024-01-24 [1] CRAN (R 4.4.0)
#> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.4.0)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0)
#> xfun 0.49 2024-10-31 [1] CRAN (R 4.4.1)
#> yaml 2.3.10 2024-07-26 [1] RSPM (R 4.4.0)
#>
#> [1] D:/a/_temp/Library
#> [2] C:/R/library