/inbobosvitaliteit

R package with functions used for the forest vitality analysis specific for INBO (not useful from outside)

Primary LanguageRGNU General Public License v3.0GPL-3.0

inbobosvitaliteit

R package with functions used for the forest vitality analysis specific for INBO (not useful from outside)

#Usage

Make a new R project for the current year

Install the package with following code:

if (!"remotes" %in% rownames(installed.packages())) install.packages("remotes")
remotes::install_github("inbo/inbobosvitaliteit@main", dependencies = TRUE)

The @main is optional, and refers to the main branch, with @other_branch_name another branch of the repository can be installed.

All necessary scripts are in the repository, but it can be useful to copy the master script that calls all other scripts to your local project with following code (this code copies it to your current work directory:

library(inbobosvitaliteit)
install_base_script()

Now you can run the 00_base_scripts line per line, only the most upper block of code should be updated to use the script

For use with R 4.2, the rstan package of the stan website must be used (>=2.26), because the cran version 2.18 does not work properly

The script generated by install_base_script is the only script that is needed, but when errors, the other scripts may be used seperately and can be copied by copy_scripts_and_sql_to(target_directory). After running the header of 00_base_script all other scripts should run.

If recalc_sen and recalc_lmer are FALSE previously saved models are used. Of course these have to be calculated once for each reporting cycle, qnd this takes several hours to complete, and are calculated when recalc_sen and recalc_lmer are TRUE.

### DOOR GEBRUIKER TE WIJZIGEN: configuration variables

#Maak eerst een R project aan voor het rapportagejaar
#Open Rstudio via het .Rproj bestandje

#check de werkdirectory
getwd()

last_year <- 2022       #laatst gebruikte jaar in de dataset
years_2 <- c(last_year - 1, last_year)
years_3 <- c(last_year - 2, last_year - 1, last_year)
years_trend <- 1995:last_year
years_indicator <- 1987:last_year
setwd(getwd())    #locatie waar de bestanden moeten komen
cat_base_script() #maak een lokale kopie van het basissscript

plot_base_size <- 10    #standaard tekstgrootte in figuren
use_local_db_export <- FALSE #gebruik reeds ingeladen data voor dit jaar
copy_local <- FALSE #optioneel: kopieer alles naar de lokale structuur

#Berekening ootstrap op sen-slope
#Eenmalig uitvoeren, duurt enkele uren
#alles wordt bewaard in de output/interim directory, dus eenmalig is genoeg
recalc_sen <- FALSE #eenmalig wel op TRUE, duurt lang
sem_boot <- 200 #hoeveelheid samples voor sen-bootstrap

###Berekening mixed effect modellen
#Eenmalig uitvoeren, duurt ongeveer 3 uur
#alles wordt bewaard in de output/interim directory, dus eenmalig is genoeg
recalc_lmer <- FALSE #eenmalig wel op TRUE, duurt een hele poos
lmer_samples <- 10000 #hoeveelheid iteratiestappen brm

Aanmaken van de indicator beschadigde bosbomen

In het script 08_indicator_beschadigde_bosbomen wordt de data gegenereerd voor de natuurindicatoren website van het INBO, alsook worden de figuren gemaakt die ook worden gemaakt op de website. Enkel het stuk rond de data is belangrijk.

Je hebt een databestandje vlaanderen_europa.csv nodig die een kommagescheiden tekstbestand is in de volgende vorm:

Jaar,niveau,Aandeel
1990,Europa,19.5
1990,Vlaanderen,8.3
1991,Europa,20.7
1991,Vlaanderen,12.9
...
...
...
2020,Europa,28.2
2020,Vlaanderen,25.3
2021,Europa,28.6
2021,Vlaanderen,19.9
2022,Europa,NA
2022,Vlaanderen,26.6

Het script zal 4 files genereren, welke moeten gekopieerd worden naar de private github repository github.com/inbo/indicatoren/source/beschadigde_bosbomen

  • beschadigde_bosbomen.csv
  • beschadigde_bosbomen.yml
  • vlaanderen_europa.csv
  • vlaanderen_europa.yml