From 53fbe6408b1eb0d1da99e3ca7e9214fbf46805ca Mon Sep 17 00:00:00 2001 From: heleenderoo Date: Fri, 22 Mar 2024 21:36:35 +0100 Subject: [PATCH] Initiate transformation_to_layer1+.R --- .../transformation_to_layer1+.R | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/transformation_to_layer1/transformation_to_layer1+.R b/src/transformation_to_layer1/transformation_to_layer1+.R index e5db8cb..cddfd9f 100644 --- a/src/transformation_to_layer1/transformation_to_layer1+.R +++ b/src/transformation_to_layer1/transformation_to_layer1+.R @@ -46,16 +46,127 @@ read_processed(path_name = "./data/layer1_data/", +# Input level ---- + +level <- "LI" +level <- "LII" + + + # 3. Gap-fill bulk densities for mineral layers ---- +source("./src/functions/gapfill_with_predictions.R") + +if (level == "LI") { + + s1_som <- gapfill_with_predictions(survey_form = "s1_som", + data_frame = s1_som, + save_to_env = FALSE) + + s1_pfh <- gapfill_with_predictions(survey_form = "s1_pfh", + data_frame = s1_pfh, + save_to_env = FALSE) +} + + +if (level == "LII") { + + so_som <- gapfill_with_predictions(survey_form = "so_som", + data_frame = so_som, + save_to_env = FALSE) + + so_pfh <- gapfill_with_predictions(survey_form = "so_pfh", + data_frame = so_pfh, + save_to_env = FALSE) +} + + + + +# 4. Tidy up dataframes ---- + +source("./src/functions/tidy.R") + +if (level == "LI") { + + s1_som <- tidy(survey_form = "s1_som", + data_frame = s1_som, + save_to_env = FALSE) + + s1_pfh <- tidy(survey_form = "s1_pfh", + data_frame = s1_pfh, + save_to_env = FALSE) +} + + +if (level == "LII") { + + so_som <- tidy(survey_form = "so_som", + data_frame = so_som, + save_to_env = FALSE) + + so_pfh <- tidy(survey_form = "so_pfh", + data_frame = so_pfh, + save_to_env = FALSE) +} + + + + +# 5. Get stratifiers ---- + +source("./src/functions/get_stratifiers.R") + +if (level == "LI") { + + s1_strat <- get_stratifiers(level = "LI") + + write.table(s1_strat, + file = paste0("./data/additional_data/s1_strat.csv"), + row.names = FALSE, + na = "", + sep = ";", + dec = ".") +} + +if (level == "LII") { + + so_strat <- get_stratifiers(level = "LII") + + write.table(so_strat, + file = paste0("./data/additional_data/so_strat.csv"), + row.names = FALSE, + na = "", + sep = ";", + dec = ".") +} + + + + + +# 5. Export the processed survey forms ---- +## 5.1. Save processed survey forms to Google Drive (layer 1) ---- +source("./src/functions/save_to_google_drive.R") +save_to_google_drive(objects_to_save = c("si", "so", "sw"), + path_name = "layer1_data") +source("./src/functions/save_to_google_drive.R") +save_to_google_drive(objects_to_save = c("y1", "s1"), + path_name = "layer1_data") +source("./src/functions/save_to_google_drive.R") +save_to_google_drive(path_name = "layer1_data") +## 5.2. Sync local data with Google Drive ---- +source("./src/functions/sync_local_data.R") +sync_local_data(list_subfolders_data = "layer1_data", + list_subfolders_output = FALSE)