-
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 #40 from KWB-R/well_operation
Well operation
- Loading branch information
Showing
6 changed files
with
254 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
Package: kwb.geosalz | ||
Title: R Package for Documenting Workflow Used in Project "geosalz" | ||
Version: 0.6.0 | ||
Version: 0.7.0 | ||
Authors@R: c( | ||
person("Michael", "Rustler", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-0647-7726")), | ||
person("Hauke", "Sonnenberg", , "[email protected]", role = "ctb", | ||
comment = c(ORCID = "0000-0001-9134-2871")), | ||
person("Christoph", "Sprenger", , "[email protected]", role = "ctb", | ||
comment = c(ORCID = "0000-0002-0178-6645")), | ||
person("GeoSalz", role = "fnd"), | ||
person("Kompetenzzentrum Wasser Berlin gGmbH (KWB)", role = "cph") | ||
) | ||
|
@@ -36,6 +38,7 @@ Imports: | |
readODS, | ||
readr(>= 1.4.0), | ||
readxl (>= 1.2.0), | ||
RColorBrewer, | ||
rlang (>= 0.3.1), | ||
rmarkdown (>= 1.11), | ||
sf, | ||
|
@@ -44,7 +47,8 @@ Imports: | |
tibble (>= 2.0.1), | ||
tidyr (>= 0.8.2), | ||
tidyselect (>= 1.1.2), | ||
withr | ||
withr, | ||
zoo | ||
Suggests: | ||
covr (>= 3.2.1), | ||
DT, | ||
|
@@ -71,4 +75,4 @@ Remotes: | |
ByteCompile: true | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.1 |
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,113 @@ | ||
#' Plot measurementchain and well operation in combined plot | ||
#' | ||
#' @param mc_dat mc_dat | ||
#' @param well_op_data_meta well_op_data_meta | ||
#' @param brunnen_nr well id (default: 9) | ||
#' @param para parameter (either: "Leitfaehigkeit" or "Temperatur") | ||
#' @param y_label y label (default: "elektr. Leitfaehigkeit (µS/cm)") | ||
#' @param date_min minimum date for plotting (default: as.Date("2023-05-10")) | ||
#' @param date_max maximum date for plotting (default: Sys.Date()) | ||
#' @return combined plot | ||
#' @export | ||
#' @importFrom dplyr filter group_by summarize n | ||
#' @importFrom RColorBrewer brewer.pal | ||
#' @importFrom ggplot2 ggplot aes geom_line scale_color_manual labs theme_bw | ||
#' theme guides guide_legend element_blank geom_bar scale_x_date | ||
#' @importFrom zoo rollmean | ||
plot_measurementchain_and_well_operation <- function(mc_dat, | ||
well_op_data_meta, | ||
brunnen_nr = 9, | ||
para = "Leitfaehigkeit", | ||
y_label = "elektr. Leitf\u00E4higkeit (\u00B5S/cm)", | ||
date_min = as.Date("2023-05-10"), | ||
date_max = Sys.Date()) { | ||
|
||
well_ids <- c(9,10,13) | ||
|
||
if (! brunnen_nr %in% well_ids) { | ||
stop("'brunnen_nr' has to be one of: ", paste(well_ids, collapse = ", ")) | ||
} | ||
|
||
# plot time series Brunnen 9 | ||
selection <- mc_dat %>% | ||
dplyr::filter(.data[["parameter"]] == para, | ||
.data[["brunnen_nummer"]] == brunnen_nr) | ||
|
||
|
||
n_sensors <- length(unique(selection$einbau_sensor_muGOK)) | ||
|
||
custom_palette <- RColorBrewer::brewer.pal(n_sensors, | ||
"Dark2") | ||
|
||
p_well <- ggplot2::ggplot(selection, | ||
ggplot2::aes(x = datum_uhrzeit, | ||
y = messwert, | ||
group = einbau_sensor_muGOK, | ||
color = as.factor(einbau_sensor_muGOK))) + | ||
ggplot2::geom_line() + | ||
ggplot2::scale_color_manual(values = custom_palette) + | ||
ggplot2::labs(x="", y = y_label, color = "Sensor [muGOK]") + | ||
ggplot2::theme_bw() + | ||
ggplot2::xlim(as.POSIXct(date_min), as.POSIXct(date_max)) + | ||
#ggplot2::ylim(500,3000) + | ||
ggplot2::theme(legend.position = "top", | ||
axis.text.x = ggplot2::element_blank()) + | ||
ggplot2::guides(color = ggplot2::guide_legend(ncol = n_sensors)) | ||
|
||
#p_well | ||
|
||
dat_well <- well_op_data_meta %>% dplyr::filter(.data$brunnen_nummer == brunnen_nr) | ||
|
||
sum_well <- dat_well %>% | ||
dplyr::group_by(.data$bwb_datum) %>% | ||
dplyr::summarise(n = dplyr::n(), | ||
total_q = sum(.data$menge_summe_m3, na.rm = TRUE) ) | ||
|
||
sum_well$ma7 <- zoo::rollmean(sum_well$total_q, k = 7, fill = NA, align = "right") | ||
sum_well$ma10 <- zoo::rollmean(sum_well$total_q, k = 10, fill = NA, align = "right") | ||
|
||
plot_q_well <- ggplot2::ggplot(sum_well, ggplot2::aes(x = as.Date(bwb_datum), y = total_q)) + | ||
ggplot2::geom_bar(stat = "identity", width=1, color = "blue") + | ||
ggplot2::labs(x="", y = sprintf("Q, Brunnen %2d (m3/d)", brunnen_nr)) + | ||
ggplot2::theme_bw() + | ||
ggplot2::theme(axis.text.x = ggplot2::element_blank()) + | ||
ggplot2::xlim(date_min, date_max) | ||
# ggplot2::scale_x_date(date_breaks = "1 month", date_labels = "%b %Y") + | ||
# ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 0, | ||
# vjust = 0.5, | ||
# hjust = 1)) #+ | ||
|
||
|
||
sum_wellfield <- well_op_data_meta %>% | ||
dplyr::group_by(.data$bwb_datum) %>% | ||
dplyr::summarise(n = dplyr::n(), | ||
total_q = sum(.data$menge_summe_m3, na.rm = TRUE) ) | ||
|
||
sum_wellfield$ma7 <- zoo::rollmean(sum_well$total_q, k = 7, fill = NA, align = "right") | ||
sum_wellfield$ma10 <- zoo::rollmean(sum_well$total_q, k = 10, fill = NA, align = "right") | ||
|
||
plot_q_wellfield <- ggplot2::ggplot(sum_wellfield, ggplot2::aes(x = as.Date(bwb_datum), y = total_q)) + | ||
ggplot2::geom_bar(stat = "identity", width=1, color = "blue") + | ||
ggplot2::labs(x="Zeit", y = "Q, Brunnenfeld K-Galerie (m3/d)") + | ||
ggplot2::theme_bw() + | ||
ggplot2::xlim(date_min, date_max) + | ||
ggplot2::scale_x_date(date_breaks = "1 month", date_labels = "%b %Y") + | ||
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 0, | ||
vjust = 0.5, | ||
hjust = 1)) | ||
|
||
|
||
combined_plot <- cowplot::plot_grid(p_well, | ||
plot_q_well, | ||
plot_q_wellfield, | ||
ncol = 1, align = 'v') | ||
|
||
combined_plot_with_title <- cowplot::ggdraw() + | ||
cowplot::draw_plot(combined_plot, 0, 0, 1, 1) + | ||
cowplot::draw_label(sprintf("Brunnen %2d", brunnen_nr), x = 0.2, y = 0.8, size = 12, hjust = 0.5) | ||
|
||
combined_plot_with_title | ||
|
||
} | ||
|
||
|
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