Skip to contents

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 = file.path(paths$cleaned_data_rds))

foerdermengen_ww <- kwb.geosalz::get_foerdermengen(paths$foerdermengen)

foerdermengen_fri_gal <- kwb.geosalz::get_foerdermengen_gal_fri(
  path = paths$foerdermengen
) %>% 
  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.2.3 (2023-03-15 ucrt)
os Windows Server x64 (build 20348)
system x86_64, mingw32
ui RTerm
language en
collate English_United States.utf8
ctype English_United States.utf8
tz UTC
date 2023-04-15
pandoc 2.19.2 @ C:/HOSTED1/windows/pandoc/2191.2/x64/PANDOC~1.2/ (via rmarkdown)

Packages

#>  package     * version date (UTC) lib source
#>  bslib         0.4.2   2022-12-16 [1] RSPM (R 4.2.0)
#>  cachem        1.0.7   2023-02-24 [1] RSPM (R 4.2.0)
#>  cli           3.6.1   2023-03-23 [1] RSPM (R 4.2.0)
#>  desc          1.4.2   2022-09-08 [1] RSPM (R 4.2.0)
#>  digest        0.6.31  2022-12-11 [1] RSPM (R 4.2.0)
#>  dplyr       * 1.1.1   2023-03-22 [1] RSPM (R 4.2.0)
#>  evaluate      0.20    2023-01-17 [1] RSPM (R 4.2.0)
#>  fansi         1.0.4   2023-01-22 [1] RSPM (R 4.2.0)
#>  fastmap       1.1.1   2023-02-24 [1] RSPM (R 4.2.0)
#>  fs            1.6.1   2023-02-06 [1] RSPM (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [1] RSPM (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] RSPM (R 4.2.0)
#>  htmltools     0.5.5   2023-03-23 [1] RSPM (R 4.2.0)
#>  jquerylib     0.1.4   2021-04-26 [1] RSPM (R 4.2.0)
#>  jsonlite      1.8.4   2022-12-06 [1] RSPM (R 4.2.0)
#>  knitr         1.42    2023-01-25 [1] RSPM (R 4.2.0)
#>  kwb.utils     0.14.0  2023-04-15 [1] Github (KWB-R/kwb.utils@56518c7)
#>  lifecycle     1.0.3   2022-10-07 [1] RSPM (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] RSPM (R 4.2.0)
#>  memoise       2.0.1   2021-11-26 [1] RSPM (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [1] RSPM (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] RSPM (R 4.2.0)
#>  pkgdown       2.0.7   2022-12-14 [1] RSPM (R 4.2.0)
#>  purrr         1.0.1   2023-01-10 [1] RSPM (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] RSPM (R 4.2.0)
#>  ragg          1.2.5   2023-01-12 [1] RSPM (R 4.2.0)
#>  rlang         1.1.0   2023-03-14 [1] RSPM (R 4.2.0)
#>  rmarkdown     2.21    2023-03-26 [1] RSPM (R 4.2.0)
#>  rprojroot     2.0.3   2022-04-02 [1] RSPM (R 4.2.0)
#>  sass          0.4.5   2023-01-24 [1] RSPM (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] RSPM (R 4.2.0)
#>  stringi       1.7.12  2023-01-11 [1] RSPM (R 4.2.0)
#>  stringr       1.5.0   2022-12-02 [1] RSPM (R 4.2.0)
#>  systemfonts   1.0.4   2022-02-11 [1] RSPM (R 4.2.0)
#>  textshaping   0.3.6   2021-10-13 [1] RSPM (R 4.2.0)
#>  tibble        3.2.1   2023-03-20 [1] RSPM (R 4.2.0)
#>  tidyr       * 1.3.0   2023-01-24 [1] RSPM (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] RSPM (R 4.2.0)
#>  utf8          1.2.3   2023-01-31 [1] RSPM (R 4.2.0)
#>  vctrs         0.6.1   2023-03-22 [1] RSPM (R 4.2.0)
#>  xfun          0.38    2023-03-24 [1] RSPM (R 4.2.0)
#>  yaml          2.3.7   2023-01-23 [1] RSPM (R 4.2.0)
#> 
#>  [1] D:/a/_temp/Library
#>  [2] C:/R/library

Pandoc

#>                                           pandoc_directory pandoc_version
#> 1 C:/HOSTED~1/windows/pandoc/219~1.2/x64/PANDOC~1.2/pandoc         2.19.2