-
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 #94 from inbo/090_vissen
090 vissen
- Loading branch information
Showing
14 changed files
with
9,181 additions
and
0 deletions.
There are no files selected for viewing
268 changes: 268 additions & 0 deletions
268
moneos_2024/090_vissen/10_moneos_visdata_VIS_fuiken.Rmd
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,268 @@ | ||
--- | ||
params: | ||
hoofdstuk: "090_vissen" | ||
knit: (function(inputFile, encoding) { | ||
rmarkdown::render(inputFile, | ||
encoding=encoding, | ||
output_dir = paste0(rmarkdown::yaml_front_matter(inputFile)$params$hoofdstuk, | ||
"/output") | ||
)}) | ||
|
||
title: "visdata fuiken" | ||
output: | ||
bookdown::word_document2: default | ||
--- | ||
|
||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = FALSE, error=FALSE, warning=FALSE, message=FALSE, cache=FALSE) | ||
``` | ||
|
||
|
||
```{r libraries} | ||
library(tidyverse) | ||
library(lubridate) | ||
library(readxl) | ||
library(writexl) | ||
library(inbodb) | ||
library(rprojroot) ## workaround pad | ||
``` | ||
|
||
|
||
```{r pad} | ||
# inlezen van variabelen | ||
# pad naar data : pad_data | ||
# pad naar tabellen : pad_tabellen | ||
# pad naar figuren : pad_figuren | ||
run_pad <- function() { | ||
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") | ||
# print(ls()) | ||
sapply(ls(), function(x) assign(x, get(x), .GlobalEnv)) | ||
} | ||
run_pad() | ||
``` | ||
|
||
|
||
```{r variabelen} | ||
run_variabelen <- | ||
function() { | ||
jaren <- as.numeric(jaar_moneos) - 1 | ||
vangstmethode <- c('Schietfuik') | ||
# Zeeschelde vissen | ||
locaties_name <- "fuikvangsten_Zeeschelde_locaties" | ||
metadata_name <- "fuikvangsten_Zeeschelde_metadata" | ||
filename <- "fuikdata_Zeeschelde" | ||
# zijrivieren vissen | ||
# locaties_name <- "fuikvangsten_zijrivieren_locaties" | ||
# metadata_name <- "fuikvangsten_zijrivieren_metadata" | ||
# filename <- "fuikdata_zijrivieren" | ||
locaties <- | ||
read_xlsx(str_c(pad_data, "metadata VLIZ/", locaties_name, ".xlsx")) | ||
locatie_nrs <- locaties$locatiecode %>% as.character() | ||
locatie_namen <- locaties$locatie | ||
# print(ls()) | ||
sapply(ls(), function(x) assign(x, get(x), .GlobalEnv)) | ||
} | ||
run_variabelen() | ||
``` | ||
|
||
|
||
```{r connectie met databank} | ||
VIS2 <- connect_inbo_dbase("D0147_00_Vis2") | ||
VIS <- connect_inbo_dbase("W0001_00_Vis") | ||
``` | ||
|
||
|
||
```{r bevragen databank} | ||
FactMeting_Pivot <- | ||
tbl(VIS, "FactMeting_Pivot") | ||
DimWaarneming <- | ||
tbl(VIS, "DimWaarneming") | ||
DimGebied <- | ||
tbl(VIS, "DimGebied") | ||
DimGebiedInfo <- | ||
tbl(VIS, "DimGebiedInfo") | ||
DimTaxon <- | ||
tbl(VIS, "DimTaxon") | ||
DimVisindexTaxon <- | ||
tbl(VIS, "DimVisindexTaxon") | ||
DimMethode <- | ||
tbl(VIS, "DimMethode") | ||
DimDate <- | ||
tbl(VIS, "DimDate") | ||
# Vispunten <- | ||
# tbl(VIS2, "Vispunten") | ||
# VHAVispunten <- | ||
# tbl(VIS2, "VHAVispunten") | ||
AbiotischeMeting <- | ||
tbl(VIS2, "AbiotischeMeting") | ||
tbl_campagnes <- | ||
DimWaarneming %>% | ||
inner_join(DimGebied, | ||
by = "GebiedKey") %>% | ||
inner_join(DimDate, by = c("BeginDatumKey" = "DateKey")) %>% | ||
inner_join(DimMethode, by = "MethodeKey") %>% | ||
filter(Year %in% jaren, | ||
Gebiedcode %in% locatie_nrs | ||
# , | ||
# Methodenaam %in% vangstmethode | ||
) %>% | ||
select(WaarnemingKey, WaarnemingID, GebiedKey, Gebiedcode, LambertX, LambertY, Lat, Long, Gebiednaam, Gemeentenaam, Begindatum, Month, Year, MethodeKey, Methodenaam, Methodegroepcode, AantalDagen, AantalFuiken) | ||
tbl_data <- | ||
FactMeting_Pivot %>% | ||
right_join(DimWaarneming %>% | ||
inner_join(DimGebied, | ||
by = "GebiedKey") %>% | ||
inner_join(DimDate, by = c("BeginDatumKey" = "DateKey")), | ||
by = "WaarnemingKey") %>% | ||
inner_join(DimTaxon %>% | ||
left_join(DimVisindexTaxon %>% select(TaxonKey, Exoot)), | ||
by = "TaxonKey") %>% | ||
inner_join(DimMethode, by = "MethodeKey") %>% | ||
select(MetingPivotKey, WaarnemingKey, WaarnemingID, | ||
GebiedKey, Gebiedcode, LambertX, LambertY, Lat, Long, Gebiednaam, Gemeentenaam, | ||
Begindatum, Month, Year, | ||
MethodeKey, Methodenaam, Methodegroepcode, AantalDagen, AantalFuiken, | ||
TaxonKey, Soort, WetenschappelijkeNaam, Exoot, | ||
TAXONAANTAL, TAXONGEW, TAXONTOTGEW, TAXONLEN, | ||
TEMPERATUUR, ZUURSTOF, TURBIDITEIT, CONDUCTIVITEIT, PH) %>% | ||
filter(Year %in% jaren, | ||
Gebiedcode %in% locatie_nrs | ||
# , | ||
# Methodenaam %in% vangstmethode | ||
) | ||
(gebied_codes <- | ||
tbl_data %>% | ||
distinct(Gebiedcode) %>% | ||
collect() %>% | ||
pull()) | ||
waarneming_IDs <- | ||
tbl_data %>% | ||
distinct(WaarnemingID) %>% | ||
collect() %>% | ||
pull() | ||
# tbl_locatie_gegevens <- | ||
# Vispunten %>% | ||
# inner_join(VHAVispunten, by = c("VIP_ID" = "VHP_VIP_ID")) %>% | ||
# select(VIP_CDE, VIP_Omschrijving, VHP_LOTIC_NAAM, VHP_LOTIC_BekNaam, VHP_LOTIC_STROOMGEBIED, VHP_GEMEENTE) %>% | ||
# filter(VIP_CDE %in% gebied_codes) | ||
tbl_abiotiek <- | ||
AbiotischeMeting %>% | ||
select(ABME_WRNG_ID, ABME_ZUURSTOF, ABME_ZUURSTOFPROCENT, ABME_TEMPERATUUR, ABME_PH, ABME_CONDUCTIVITEIT, ABME_TURBIDITEIT, ABME_SALINITEIT_PRM) %>% | ||
filter(ABME_WRNG_ID %in% waarneming_IDs) | ||
data <- | ||
tbl_data %>% | ||
collect() %>% | ||
# left_join(tbl_locatie_gegevens %>% collect(), by = c("Gebiedcode" = "VIP_CDE")) %>% | ||
left_join(tbl_abiotiek %>% collect(), by = c("WaarnemingID" = "ABME_WRNG_ID")) | ||
campagnes <- | ||
tbl_campagnes %>% | ||
collect() %>% | ||
# left_join(tbl_locatie_gegevens %>% collect(), by = c("Gebiedcode" = "VIP_CDE")) %>% | ||
left_join(tbl_abiotiek %>% collect(), by = c("WaarnemingID" = "ABME_WRNG_ID")) | ||
soorten <- | ||
data %>% | ||
distinct(Soort, WetenschappelijkeNaam, Exoot) | ||
data <- | ||
data %>% | ||
select(-WetenschappelijkeNaam) | ||
``` | ||
|
||
|
||
```{r sluiten databank} | ||
dbDisconnect(VIS) | ||
dbDisconnect(VIS2) | ||
``` | ||
|
||
|
||
```{r hervariabel, ref.label=c('pad', 'variabelen')} | ||
rm(list = ls()[-which(ls() %in% c("data", "campagnes", "soorten", "params", "run_pad", "run_variabelen"))]) | ||
run_pad() | ||
run_variabelen() | ||
``` | ||
|
||
|
||
```{r opslaan ruwe data fuiken} | ||
write_xlsx(list(campagnes = campagnes, | ||
soorten = soorten, | ||
data = data), | ||
path = str_c(pad_data, filename, "_ruw_VIS_", str_c(unique(range(jaren)), collapse = "_"), ".xlsx")) | ||
``` | ||
|
||
|
||
```{r check campagnes, eval=FALSE} | ||
campagnes <- | ||
read_xlsx(sheet = "campagnes", | ||
path = str_c(pad_data, filename, "_ruw_VIS_", str_c(unique(range(jaren)), collapse = "_"), ".xlsx")) | ||
data <- | ||
read_xlsx(sheet = "data", | ||
path = str_c(pad_data, filename, "_ruw_VIS_", str_c(unique(range(jaren)), collapse = "_"), ".xlsx")) | ||
campagnes_dstnct <- | ||
campagnes %>% | ||
distinct(Gebiedcode, Gebiednaam, Begindatum, Month, Year, Methodenaam) | ||
campagnes_dstnct2 <- | ||
data %>% | ||
distinct(Gebiedcode, Gebiednaam, Begindatum, Month, Year, Methodenaam) | ||
(sd <- setdiff(campagnes_dstnct, campagnes_dstnct2)) | ||
campagnes_dstnct %>% | ||
distinct(Gebiedcode, Gebiednaam) | ||
``` | ||
|
Oops, something went wrong.