Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SIMO_output
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clblatte
SIMO_output
Commits
8c45028c
Commit
8c45028c
authored
4 years ago
by
clblatte
Browse files
Options
Downloads
Patches
Plain Diff
comment out creating individual csv files for wathersheds
parent
cf5a68f2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
loadDB.R
+38
-38
38 additions, 38 deletions
loadDB.R
with
38 additions
and
38 deletions
loadDB.R
+
38
−
38
View file @
8c45028c
...
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment