Skip to content
Snippets Groups Projects
Commit 8b29a32b authored by clblatte's avatar clblatte
Browse files

overcome mutatet vowels

parent 8b37f9c4
No related branches found
No related tags found
No related merge requests found
source diff could not be displayed: it is too large. Options to address this: view the blob.
"code_metsa";"forest_land";"NUTS2";"NFIGrid"
1;518000;"FI1B";"South"
2;569000;"FI1C";"South"
4;517000;"FI19";"South"
5;347000;"FI1C";"South"
6;912000;"FI19";"South"
7;359000;"FI1C";"South"
8;334000;"FI1C";"South"
9;402000;"FI1C";"South"
10;1212000;"FI1D";"South"
11;1325000;"FI1D";"Central"
12;1486000;"FI1D";"Central"
13;1369000;"FI19";"Central"
14;905000;"FI19";"Central"
15;508000;"FI19";"Central"
16;336000;"FI1D";"Central"
17;2480000;"FI1D";"North"
18;1630000;"FI1D";"North"
19;4998000;"FI1D";"Lapland"
21;69000;"XXXXX";"XXXXX"
......@@ -340,45 +340,67 @@ print("*** values rounded ***")
# NFI plots falling into the same forest stand of Metsään.fi that were simulated only once!!!
# Inclued "NEW UNIQUE ID" since the stand id can now be represented multiple times, important for optimization.
# List the csv files that are in the output folder
NFIxy.files <- list.files(paste0(path,"/params/NFI_xy/"), pattern = "_xy.csv")
# read and combine the files
read_data_NFIxy <- function (i) {
df <- read.csv(paste0(path,"/params/NFI_xy/", i ), sep = ";", header = TRUE, stringsAsFactors = FALSE, fileEncoding="UTF-8-BOM")
df <- df[, c("NUTS_NAME", "standid", "coords.x1", "coords.x2") ] %>%
rename(region = NUTS_NAME,
id = standid,
X = coords.x1,
Y = coords.x2)
return(df)
}
if(on_cPouta == TRUE) {
NFIxy.t <- mclapply(NFIxy.files, read_data_NFIxy, mc.cores = numCores)
} else {
NFIxy.t <- lapply(NFIxy.files, read_data_NFIxy)
}
NFIxy = NULL
for (part_data in NFIxy.t) {
NFIxy <- rbind(NFIxy,part_data)
}
rm(NFIxy.t)
# create a unique id
NFIxy <- NFIxy %>% mutate(unique_id = 99000000 + 1:nrow(NFIxy))
# Check: according to SIMO input preparation, the lenght of all NFI plots should be: 39445
length(unique(NFIxy$unique_id))
length(unique(NFIxy$id))
### SAVE EXTRA NEW FILE with code_metsa as identifier for merge
### mutated vowels cause problems on cPouta
# # List the csv files that are in the output folder
# NFIxy.files <- list.files(paste0(path,"/params/NFI_xy/"), pattern = "_xy.csv")
#
#
# # read and combine the files
# read_data_NFIxy <- function (i) {
# df <- read.csv(paste0(path,"/params/NFI_xy/", i ), sep = ";", header = TRUE, stringsAsFactors = FALSE, fileEncoding="UTF-8-BOM")
# df <- df[, c("NUTS_NAME", "standid", "coords.x1", "coords.x2") ] %>%
# rename(region = NUTS_NAME,
# id = standid,
# X = coords.x1,
# Y = coords.x2)
# return(df)
# }
#
#
# if(on_cPouta == TRUE) {
# NFIxy.t <- mclapply(NFIxy.files, read_data_NFIxy, mc.cores = numCores)
# } else {
# NFIxy.t <- lapply(NFIxy.files, read_data_NFIxy)
# }
#
# NFIxy = NULL
#
# for (part_data in NFIxy.t) {
#
# NFIxy <- rbind(NFIxy,part_data)
#
# }
#
# rm(NFIxy.t)
#
#
# # create a unique id
# NFIxy <- NFIxy %>% mutate(unique_id = 99000000 + 1:nrow(NFIxy))
#
#
# province <- read.csv(paste0(path,"/params/provinceInfo/provinces.csv"), sep = ";", header = TRUE, stringsAsFactors = FALSE)
# province <- province %>% rename(region = province_name)
# head(province)
#
#
# NFIxy <- NFIxy %>%
# left_join(province[,c("code_metsa", "region")], by = "region") %>%
# select(!region)
#
# # check quickly - compare with SImO input data analysis
# head(NFIxy)
# length(unique(NFIxy$id))
# length(unique(NFIxy$unique_id))
#
# write.table(NFIxy,paste0(path, "/params/NFI_xy_tot/tot_NFI_xy.csv"), sep = ";", row.names = F, col.names = TRUE)
### READ THE NEW FILE code_metsa as identifier for merge
NFIxy <- read.csv(paste0(path,"/params/NFI_xy_tot/tot_NFI_xy.csv"), sep = ";", header = TRUE, stringsAsFactors = FALSE)
# Merge the province and XY coordinates by stand id !!
rslt <- rslt %>%
......@@ -387,14 +409,15 @@ rslt <- rslt %>%
# check quickly - compare with SImO input data analysis
length(unique(rslt$id))
length(unique(rslt$unique_id))
unique(rslt$region) # GIVES for region NA ???
unique(rslt$code_metsa) # GIVES for region NA ???
stand_NA <- rslt %>%
filter(is.na(region)) # NA for 23968059
filter(is.na(code_metsa)) # NA for 23968059
cat("NAs by XYmerge, for standid:", unique(stand_NA$id))
cat("NUmber of rows removed:", nrow(stand_NA))
# filter NA regions
rslt <- rslt %>%
filter(id != unique(stand_NA$id))
rm(stand_NA)
......@@ -404,26 +427,6 @@ print("*** XY-coordinates added ***")
# -------------------
# Switch region name by code metsatilastot
# -------------------
province <- read.csv(paste0(path,"/params/provinceInfo/provinces.csv"), sep = ";", header = TRUE, stringsAsFactors = FALSE)
province <- province %>% rename(region = province_name)
rslt <- rslt %>%
left_join(province[,c("code_metsa", "region")], by = "region")
# check quickly - compare with SImO input data analysis
length(unique(rslt$id))
length(unique(rslt$unique_id))
print("*** region code metsatilastot added ***")
# ---------------
# Add NUTs 2 region
# ---------------
......@@ -431,6 +434,8 @@ print("*** region code metsatilastot added ***")
# This information might be required if results are optimized for certain regions.
# https://en.wikipedia.org/wiki/NUTS_statistical_regions_of_Finland
province <- read.csv(paste0(path,"/params/provinceInfo/provinces2.csv"), sep = ";", header = TRUE, stringsAsFactors = FALSE)
rslt <- rslt %>%
left_join(province[,c("code_metsa", "NUTS2")], by= "code_metsa")
......@@ -524,10 +529,10 @@ cat("Number of stands status commercial:" , length(unique(rslt[rslt$protection %
areabyregion <- NFIxy %>%
# number of plots by region
group_by(region) %>%
group_by(code_metsa) %>%
summarise(nr_plots = n_distinct(unique_id)) %>%
# merge total forest area by region
left_join(province[,c("region", "code_metsa","forest_land")], by="region") %>%
left_join(province[,c("code_metsa","forest_land")], by="code_metsa") %>%
# are by NFI plot
mutate(represented_area_by_NFIplot = round(forest_land / nr_plots))
......@@ -556,14 +561,15 @@ print("*** represented forest area added ***")
rslt <- rslt %>%
rename(standid = id,
id = unique_id)
id = unique_id,
region = code_metsa)
### NOT needed for Optimization
# the output can be used to merge standid and XY coordinates after optimization
# use id (unique_ID) for merge
rslt.xy_no <- rslt %>%
select(id, year, regime, X, Y, standid, ES_GAME, CARBON_STORAGE, scenario, region, code_metsa)
select(id, year, regime, X, Y, standid, ES_GAME, CARBON_STORAGE, scenario, region)
### Data for Optimization
......@@ -586,12 +592,11 @@ rslt.final <- rslt %>%
# Recreation
Recreation, Scenic,
# Additional
scenario, represented_area_by_NFIplot, code_metsa ,NUTS2, protection)
cat("Output contains all 39445 stand:", 39445 == length(unique(rslt.final$id)))
scenario, represented_area_by_NFIplot, region ,NUTS2, protection)
print("*** rslt.final created ***")
cat("Output contains all 39445 stand:", 39445 == length(unique(rslt.final$id)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment