Skip to content

Commit

Permalink
Improve descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
heleenderoo committed Dec 7, 2023
1 parent b8021be commit 9891639
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/functions/apply_additional_manual_corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ apply_additional_manual_corr <- function(survey_form,
# To do: systematically implement these issues in
# ./src/functions/get_layer_inconsistencies.R
filter(parameter != "layer_number") %>%
# Remove records related to "code_layer"
# To do: systematically implement these issues in
# ./src/functions/get_layer_inconsistencies.R
filter(parameter != "code_layer") %>%
# Filter for inconsistencies of the given survey form
filter(.data$survey_form == name_survey_form) %>%
# Create column "unique_inconsistency_id"
Expand Down
80 changes: 60 additions & 20 deletions src/stock_calculations/carbon_stock_calculations.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@

# Calculate carbon stocks until 100 cm of depth
# Using a mass-preserving spline function of soil layers/horizons
# Calculate carbon stocks until 100 cm (or until the effective soil depth
# if shallower)
# ---------------------------------------------------------------------------

# Details: In this script, validated and gap-filled "layer 1" solid soil data
# are processed to calculate soil carbon stocks using different functions.
# The detailed steps taken in each function can be found within the "Roxygen"
# documentation of the function, i.e. on top of the function scripts
# (in "./src/stock_calculations/functions/" folder).

# Show "document outline" window of this script in R Studio
# using Ctrl + Shift + O

# Input data: "./data/layer1_data/"
# Output data: "./output/stocks/"



# 1. Load packages and functions ----

stopifnot(require("tidyverse"),
Expand All @@ -13,15 +25,14 @@ stopifnot(require("tidyverse"),
require("mpspline2"),
require("ggplot2"))

source("./src/stock_calculations/functions/soilspline.R")
source("./src/stock_calculations/functions/spline2stock.R")

source("./src/functions/get_env.R")


# 2. Specify level ----

level <- "LII"


# 3. Calculate stocks ----


Expand All @@ -47,19 +58,23 @@ if (level == "LII") {

source("./src/stock_calculations/functions/get_stocks.R")

get_stocks(survey_form = "so_som",
data_frame = so_som,
graph = FALSE,
density_per_three_cm = TRUE)
get_stocks(survey_form = "so_som",
data_frame = so_som,
graph = FALSE,
density_per_three_cm = TRUE)


get_stocks(survey_form = "so_pfh",
data_frame = so_pfh,
graph = FALSE,
density_per_three_cm = TRUE)
get_stocks(survey_form = "so_pfh",
data_frame = so_pfh,
graph = FALSE,
density_per_three_cm = TRUE)

}





# 4. Compile data per level ----

if (level == "LI") {
Expand Down Expand Up @@ -228,10 +243,17 @@ df_stocks_plot_lii <-

}





# 5. Add stratifiers ----
# (For statistics/visualisation purposes)

if (level == "LI") {

# Note: expert harmonisation of the LI WRB soil groups are still ongoing

source("./src/functions/get_stratifiers.R")
s1_strat <- get_stratifiers(level = "LI")

Expand All @@ -244,8 +266,6 @@ if (level == "LI") {
wrb_soil_group, forest_type, humus_type, biogeo,
main_tree_species, bs_class)



}


Expand All @@ -264,15 +284,15 @@ if (level == "LII") {
wrb_soil_group, forest_type, humus_type, biogeo,
main_tree_species, bs_class)

df_layer <- df_layer %>%
df_layer_lii <- df_layer_lii %>%
left_join(so_strat,
by = "plot_id")

df_stocks <- df_stocks %>%
df_stocks_lii <- df_stocks_lii %>%
left_join(so_strat,
by = "plot_id")

# Add colours
# Add colours (for visualisation)

df_layer <- df_layer %>%
mutate(unique_layer_repetition =
Expand Down Expand Up @@ -308,7 +328,7 @@ if (level == "LII") {
dir <- "./output/stocks/20231207_to_share_with_partners/"

# Some German plot_ids need to be excluded in LI because
# they concern different plots
# they concern different non-unique plots across different Länder

german_plot_ids_exclude <-
c("4_259", "4_260", "4_266", "4_267", "4_283", "4_284", "4_285",
Expand Down Expand Up @@ -413,6 +433,18 @@ write.table(so_som_output,
dec = ".")


# Format and print the names for attribute catalogue:

names_list <-
sort(unique(c(names(s1_som_output), names(so_som_output),
names(s1_pfh_output), names(so_pfh_output))))

cat(paste0("- **", names_list, "** - "), sep = "\n")






## 6.3. s1_pfh ----

Expand Down Expand Up @@ -591,7 +623,15 @@ save_excel(df_to_correct %>%



# 7. Make a graph per plot_id ----
# 7. Statistics ----





# 8. Data visualisation ----

## 8.1. Make a graph per plot_id ----

plot_ids <- unique(df_layer$plot_ids)

Expand Down
3 changes: 3 additions & 0 deletions src/stock_calculations/functions/get_stocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ get_stocks <- function(survey_form,
source("./src/functions/assign_env.R")
source("./src/functions/save_to_google_drive.R")

cat(paste0(" \nCalculate '", parameter, "' stocks for '",
survey_form, "'.\n \n"))

## 1.2. Retrieve data ----

if (is.null(data_frame)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# Status:
# - Almost complete for Level II (so) (complete for variables required
# for carbon stock calculations)
# - Not yet complete for Level I (s1), but the steps should be roughly
# the same
# - Almost complete for Level I (s1) (complete for variables required
# for carbon stock calculations)



Expand Down

0 comments on commit 9891639

Please sign in to comment.