diff --git a/loadDB.R b/loadDB.R index 3f188b24e547270baa4fb63ff77617621bb947d3..c254be388eb858206e7c95e7c0f08b670db4b76e 100644 --- a/loadDB.R +++ b/loadDB.R @@ -16,44 +16,44 @@ library(dplyr) -# Variant 1: create a single dataframe for each SQL Database (selected columns of table UNIT) -# Dataframes are given the names of the DB and column "test" is added with the name of the DB - -for (name in db_names){ - - # name = "MV_Hartola" - db <- dbConnect(dbDriver("SQLite"), dbname = paste0(path,"input_data/simulated_", sim_variant, "_", name, "_rsu.db")) - rsl <- dbGetQuery( db, paste0("select ", columns, " from UNIT")) - rsl$gpkg <- name - dbDisconnect(db) - - ### Add the abbreviation of the regimes - rsl <- rsl %>% - left_join(regime, by = "branching_group", all.x = TRUE) - - ### Filter those stands that caused errors during the simulation with SIMO - # import csv file that contains the error stands - error_stands <- read.csv(paste0(path, "params/errors_watersheds.csv"), sep = ",", header = TRUE, stringsAsFactors = FALSE) - error_stands$id <- as.character(error_stands$id) - - rsl <- rsl %>% - anti_join(error_stands, by = c("id", "gpkg")) - - - ### Rename set aside scenario if it considers deadwood extraction - if(sim_variant %in% c("CC45", "CC85", "without", "CC45_p", "CC85_p", "CC26_p", "CC0_p", "CC45_p_canesm", "CC85_p_canesm", "CC26_p_canesm", "CC0_p_canesm")) { - - rsl <- rsl %>% mutate(regime = ifelse(regime %in% "SA", "SA_DWextract", regime)) - - } - - - write.table(rsl, paste0(path, "output/rsl_",sim_variant,"_",name,".csv" ), sep = ";", row.names = F, col.names = TRUE) - - assign( paste("rsl", name, sep="_"), rsl) - rm(db, rsl) - -} +# # Variant 1: create a single dataframe for each SQL Database (selected columns of table UNIT) +# # Dataframes are given the names of the DB and column "test" is added with the name of the DB +# +# for (name in db_names){ +# +# # name = "MV_Hartola" +# db <- dbConnect(dbDriver("SQLite"), dbname = paste0(path,"input_data/simulated_", sim_variant, "_", name, "_rsu.db")) +# rsl <- dbGetQuery( db, paste0("select ", columns, " from UNIT")) +# rsl$gpkg <- name +# dbDisconnect(db) +# +# ### Add the abbreviation of the regimes +# rsl <- rsl %>% +# left_join(regime, by = "branching_group", all.x = TRUE) +# +# ### Filter those stands that caused errors during the simulation with SIMO +# # import csv file that contains the error stands +# error_stands <- read.csv(paste0(path, "params/errors_watersheds.csv"), sep = ",", header = TRUE, stringsAsFactors = FALSE) +# error_stands$id <- as.character(error_stands$id) +# +# rsl <- rsl %>% +# anti_join(error_stands, by = c("id", "gpkg")) +# +# +# ### Rename set aside scenario if it considers deadwood extraction +# if(sim_variant %in% c("CC45", "CC85", "without", "CC45_p", "CC85_p", "CC26_p", "CC0_p", "CC45_p_canesm", "CC85_p_canesm", "CC26_p_canesm", "CC0_p_canesm")) { +# +# rsl <- rsl %>% mutate(regime = ifelse(regime %in% "SA", "SA_DWextract", regime)) +# +# } +# +# +# write.table(rsl, paste0(path, "output/rsl_",sim_variant,"_",name,".csv" ), sep = ";", row.names = F, col.names = TRUE) +# +# assign( paste("rsl", name, sep="_"), rsl) +# rm(db, rsl) +# +# } # Variant 2: create one hughe dataframe combining all SQL databases (selected columns of table UNIT)