-
Notifications
You must be signed in to change notification settings - Fork 1
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 #91 from inbo/060_sedimentkenmerken
060 sedimentkenmerken
- Loading branch information
Showing
3 changed files
with
2,009 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
--- | ||
params: | ||
hoofdstuk: "060_sedimentkenmerken" | ||
knit: (function(inputFile, ...) { | ||
rmarkdown::render(inputFile, | ||
output_dir = paste0(rmarkdown::yaml_front_matter(inputFile)$params$hoofdstuk, "/output"))}) | ||
title: "Sediment MONEOS data" | ||
output: word_document | ||
editor_options: | ||
chunk_output_type: console | ||
--- | ||
|
||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = FALSE, error=FALSE, warning=FALSE, message=FALSE, cache=FALSE, fig.showtext = TRUE, dpi = 300) | ||
``` | ||
|
||
|
||
|
||
```{r libraries} | ||
library(tidyverse) | ||
library(lubridate) | ||
library(readxl) | ||
library(INBOtheme) | ||
library(rprojroot) | ||
``` | ||
|
||
|
||
```{r pad} | ||
# inlezen van variabelen | ||
# pad naar data : pad_data | ||
# pad naar tabellen : pad_tabellen | ||
# pad naar figuren : pad_figuren | ||
# source("../pad.R") | ||
source(find_root_file("../pad.R", criterion = is_rstudio_project)) | ||
pad_data <- maak_pad(params$hoofdstuk, "data") | ||
pad_figuren <- maak_pad(params$hoofdstuk, "figuren") | ||
pad_tabellen <- maak_pad(params$hoofdstuk, "tabellen") | ||
``` | ||
|
||
|
||
```{r data} | ||
# OPGELET!!! | ||
# Dit script start met de afgewerkte data-aanlevering. | ||
# Om te starten met extractie van de gegevens uit de databank zie script 2017 | ||
##datavoorbereiding 2024 | ||
##koppelen van sedimentdata met locatiegegevens | ||
data2022loc <- read_excel(paste0(pad_data, "Locaties2022.xlsx")) | ||
data2022sed <- read_excel(paste0(pad_data, "Sediment2022_spatial.xlsx")) | ||
data2022loc <- data2022loc %>% | ||
dplyr::filter(CampagneCode == "Spatial2022") %>% | ||
rename_with(tolower) %>% | ||
rename(X = x) %>% | ||
rename(Y = y) | ||
data2022sed <- data2022sed %>% | ||
rename_with(tolower) %>% | ||
rename (OM = om) | ||
data2022 <- data2022loc %>% | ||
left_join(data2022sed, by = "locatiecode") %>% | ||
rename(locatie = locatiecode) | ||
data2023loc <- read_excel(paste0(pad_data, "Locaties2023_ONAF.xlsx")) | ||
data2023sed <- read_excel(paste0(pad_data, "Sediment2023_spatial.xlsx")) | ||
data2023loc <- data2023loc %>% | ||
dplyr::filter(CampagneCode == "Spatial2023") %>% | ||
rename_with(tolower) %>% | ||
rename(X = x) %>% | ||
rename(Y = y) | ||
data2023sed <- data2023sed %>% | ||
rename_with(tolower) %>% | ||
rename (OM = om) | ||
data2023 <- data2023loc %>% | ||
left_join(data2023sed, by = "locatiecode") %>% | ||
rename(locatie = locatiecode) | ||
##selectie variabelen en omzetten lang formaat | ||
data2022 <- data2022 %>% | ||
select(jaar, campagne, waterloop, tidaal, fysiotoop, locatie, X, Y, mediaan, OM, slib) %>% | ||
gather("mediaan", "OM", "slib", key = variabele, value = waarde, na.rm = TRUE) | ||
data2023 <- data2023 %>% | ||
select(jaar, campagne, waterloop, tidaal, fysiotoop, locatie, X, Y, mediaan, OM, slib) %>% | ||
gather("mediaan", "OM", "slib", key = variabele, value = waarde, na.rm = TRUE) | ||
##check op dubbels | ||
dubbel <-data2023 %>% | ||
dplyr::group_by(jaar, campagne, waterloop, tidaal, fysiotoop, locatie, X, Y, variabele) %>% | ||
dplyr::summarise(n = dplyr::n(), .groups = "drop") %>% | ||
dplyr::filter(n > 1L) | ||
##data toevoegen aan dataset vorige rapportage | ||
data <- read_excel(paste0(pad_data, "S_DS_V_004a_sediment_data2008_2021_rapportage2023.xlsx")) | ||
data <- data %>% | ||
select(jaar, campagne, waterloop, tidaal, fysiotoop, locatie, X, Y, variabele, waarde) | ||
##promemory uit de dataset/databank zijn volgende data verwijderd bij de aanlevering naar VLIZ omdat ze foutief zijn gemeten: | ||
# foute data van GK 2015 intertidaal verwijderen | ||
#subset(data, !(tidaal=="intertidaal" & jaar==2015 & waterloop=="Zeeschelde IV" & | ||
# variabele %in% c("mediaan","slib") )) | ||
# foute data ZSIV 2013 intertidaal verwijderen | ||
# subset(data, !(tidaal == "intertidaal" & jaar ==2013 & waterloop == "Zeeschelde IV" & | ||
# variabele %in% c("mediaan","slib") )) | ||
# data ZSI subtidaal 2013 is ook verdacht en werd verwijderd | ||
# subset(data, !(tidaal == "subtidaal" & jaar ==2013 & waterloop == "Zeeschelde I" & | ||
# variabele %in% c("mediaan","slib") )) | ||
data <- data %>% | ||
rbind (data2022, data2023) %>% | ||
na.omit(TRUE) | ||
# template_data <- | ||
# data.frame(x = sample(seq(0,10,0.05), 100, replace = TRUE)) %>% | ||
# mutate(y = 0.5 + 2*x + rnorm(n())) | ||
``` | ||
|
||
|
||
data gecreëerd op `r Sys.time()` | ||
|
||
data weggeschreven naar `r paste0(pad_data, "template_data.csv")` | ||
|
||
|
||
```{r wegschrijven-data} | ||
file <- paste0(pad_data, "S_DS_V_004a_sediment_data2008_",(year(Sys.Date())-1),"_rapportage",year(Sys.Date()),".xlsx") | ||
openxlsx::write.xlsx(data, file, rowNames = FALSE, overwrite = TRUE) | ||
data %>% | ||
write_delim(paste0(pad_data, "sediment_data.csv"), | ||
delim = ";") | ||
``` | ||
|
||
|
||
|
||
|
Oops, something went wrong.