Skip to content
Snippets Groups Projects
Commit 48744c8e authored by clblatte's avatar clblatte
Browse files

new MF simo outcome prepare script

parent becc9910
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,29 @@ knitr::opts_chunk$set(echo = TRUE)
```
README:
This script prepares the simulated output of SIMO for the national scenario optimization: Jupyter notebook FinOpt. </br>
https://github.com/maeehart/multiforestOptimizationNotebook </br>
Input is the extracted SIMO database information, run script Main.R and define the necessary columns to extract (here: ...MutliForest/ColumnsMF.R). </br>
https://gitlab.jyu.fi/clblatte/simo_output </br>
Column "name" indicates simulated region OR stand frequence and special simulation runs: </br>
- set aside without deadwood extraction "_SA" </br>
- inital stand condition "_initial" </br>
- regimes for promoting broadleaves "_BL" </br>
- regimes with fertilization "_FERT" </br>
Examples: </br>
- "RCP0_p_1-150" - no climate change (RCP0 or else) for stand 1-150 (alternative region names) </br>
- "RCP0_p_SA_1-150" - set aside without deadwood extraction (no other regimes) </br>
- "RCP0_p_initial_1-150" - set aside for only 1 year time-step </br>
- "RCP0_p_FERT_1-150" - intensive management regimes with fertilization </br>
- "RCP0_p_BL_1-150" - extensive management regimes with promoting broadleaves </br>
```{r , include= FALSE, }
# set path
......@@ -21,7 +44,7 @@ path_project <- paste0(path, "MultiForest/")
# Define name of generated CSV file
outp_name <- "rslt_RCP0_Keski_Suomi_V6_150"
outp_name <- "rslt_RCP0_Keski_Suomi_V6"
# Libraries
......@@ -34,16 +57,12 @@ library(kableExtra)
This script prepares the simulated output of SIMO for the national scenario optimization: Jupyter notebook FinnOPt. </br>
https://github.com/maeehart/multiforestOptimizationNotebook
### Load and modify data
```{r , echo=TRUE}
rslt.all <- read.csv(paste0(path_project, "rslt_all_RCP0_V6_150.csv" ), sep = ";", header = TRUE, stringsAsFactors = FALSE)
rslt.all <- read.csv(paste0(path_project, "rslt_all_RCP0_V6.csv" ), sep = ";", header = TRUE, stringsAsFactors = FALSE)
# rslt.all <- rslt.all[rslt.all$id == c(10012874), ]
......@@ -77,8 +96,9 @@ rslt <- rslt %>%
# number of stands with year 2016 -> should be same as number of importat stands
length(unique(rslt[rslt$year %in% 2016,]$id))
# maximum year
# maximum year before
max(rslt.all$year)
# maximim year after
max(rslt$year)
```
......@@ -244,9 +264,9 @@ rslt <- rslt %>%
### Add XY-coordinates, region (provinces)
### Add XY-coordinates and region (provinces)
Merge the XY-coordinates of NFI plots also adds the stand-replicates - NFI plots falling into the same forest stand of Metsään.fi and which where simulated only once!!! </br>
Merging the XY-coordinates of NFI plots also adds the stand-replicates - NFI plots falling into the same forest stand of Metsään.fi that were simulated only once!!! </br>
Inclued "NEW UNIQUE ID" since the stand id can now be represented multiple times, important for optimization.
......@@ -275,7 +295,7 @@ NFIxy <- NFIxy.t
rm(df, NFIxy.t)
# create a unique id
NFIxy <- NFIxy %>% mutate(unique_id = 900000 + 1:nrow(NFIxy))
NFIxy <- NFIxy %>% mutate(unique_id = 99000000 + 1:nrow(NFIxy))
length(unique(NFIxy$unique_id))
......@@ -284,7 +304,7 @@ length(unique(NFIxy$unique_id))
Check: according to SIMO input preparation, the lenght of all NFI plots should be: 39448 </br>
```{r, echo = TRUE }
# Merge the province and XY coordinates by stand id
# Merge the province and XY coordinates by stand id !!
rslt <- rslt %>%
left_join(NFIxy, by = "id" )
......@@ -323,7 +343,7 @@ rslt <- rslt %>%
Add columns indicating the protection status of each selected forest stand from Metsään.fi. </br>
Protection categories follwo the finnish (column: Luokka, TyyppiLyhe) and IUCN classification (see word and excel for definition /MultiForest/NFI_protection_status/...):</br>
Protection categories follow the finnish (column: Luokka, TyyppiLyhe) and IUCN classification (see word & excel for definition /MultiForest/NFI_protection_status/...):</br>
- commercial: all regimes are allowed </br>
- landscape: landscape level protection (Luokka - likely biodiversity, extensive management in commercial forests ???) </br>
- strict: statutory protection (TyyppiLyhe & IUCN: Ia, Ib, II, III, IV, V - no categorie VI in data!) </br>
......@@ -355,12 +375,12 @@ for (i in NFIconserve.files) {
NFIconserve <- NFIconserve.t
rm(df, NFIconserve.t)
length(NFIconserve$standid)
# catStrict <- NFIconserve[NFIconserve$protection %in% "strict",]
# catlandscape <- NFIconserve[NFIconserve$protection %in% "landscape",]
# catcommercial <- NFIconserve[NFIconserve$protection %in% "commercial",]
length(NFIconserve$standid)
```
According to SImo input data, the length of all selected "forest stands" from Metsään.fi should be: 38526 </br>
......@@ -380,14 +400,10 @@ rslt <- rslt %>% merge(NFIconserve[,c("standid", "protection")], by.x = "id", b
#
# rslt.tt <- rslt %>% merge(NFIconserve[,c("standid", "protection")], by.x = "id", by.y = "standid")
#
#
# strict <- rslt.tt[rslt.tt$protection %in% "strict",]
#
# length(unique(strict$unique_id))
#
#
# strict <- strict %>% filter(regime %in% c("initial_state" , "SA"))
#
# length(unique(strict$unique_id))
# unique(strict$regime)
#
......@@ -395,8 +411,7 @@ rslt <- rslt %>% merge(NFIconserve[,c("standid", "protection")], by.x = "id", b
#
# commercial <- rslt.tt[rslt.tt$protection %in% c("commercial", "landscape"),]
# length(unique(commercial$unique_id))
#
#
# #
# #### bind
#
# test1 <- rbind(strict, commercial)
......@@ -416,31 +431,49 @@ Total forest area per region comes from: Finish Forest Statistics 2018, page 21.
# load data
forest_area <- read.csv(paste0(path_project,"provinceInfo/forest_land.csv"), sep = ";", header = TRUE, stringsAsFactors = FALSE)
areabyregion <- NFIxy %>%
# number of plots by region
group_by(region) %>%
summarise(nr_plots = n_distinct(unique_id)) %>%
# merge total forest area by region
merge(forest_area[,c("province_name", "forest_land")], by.x = "region", by.y = "province_name") %>%
# are by NFI plot
mutate(represented_area_by_NFIplot = round(forest_land / nr_plots))
kable(areabyregion, caption = "Region of FIN, # of NFI plots in Forest, total forest area (ha), represented are of each plot (ha-1)") %>% kable_styling()
```
```{r , echo=TRUE}
# Merge the represented are by region.
rslt <- rslt %>%
# TODO !!!
# MERGE area by province OR region
# FIRST calculate the representative area by NFI plot in different regions: whole forest ares / number of plots
# Total Forest area -> Finish forst statistic
mutate(represented_area_by_NFIplot = 338) # %>%
merge(areabyregion[,c("region", "represented_area_by_NFIplot")], by = "region")
```
### Order Columns
- Start with Stand ID, year and management regime. They are "indexing" the data for the optimisation.</br>
- List the indicators</br>
### Create final data set (order columns ..)
ATTENTION !!!: "unique_id" becomes "id" and "id" becomes "standID" since id of stand is not unique anymore due to including replicates (stand with multiple NFI plots in it) </br>
The new id starts with: 990.... </br>
Data has kind of three sections: </br>
- Start with id, year and management regime. They are "indexing" the data for the optimisation.</br>
- different columns with the indicators</br>
- End with represented area of the NFI-plot, regionm, NUTS2-region, coordinates, ... </br>
```{r, echo=TRUE}
rslt.final <- rslt %>%
mutate(standid = id,
id = unique_id) %>%
select(id, year, regime,
# wood
V, i_Vm3, Harvested_V, Harvested_V_log_under_bark, Harvested_V_pulp_under_bark, Harvested_V_under_bark, DEVEL_CLASS,
......@@ -459,10 +492,10 @@ rslt.final <- rslt %>%
# Recreation
Recreation, Scenic,
# Additional
scenario, represented_area_by_NFIplot, region, NUTS2, X, Y, unique_id, protection)
scenario, represented_area_by_NFIplot, region, NUTS2, X, Y, standid, protection)
length(unique(rslt.final$unique_id))
length(unique(rslt.final$id))
```
......@@ -471,7 +504,7 @@ length(unique(rslt.final$unique_id))
### Save as data set for the Optimization framework
For the Optimization / Jupyter Notebook the data can be further ZIP compressed.
For the Optimization (Jupyter Notebook) the data can be further ZIP compressed.
```{r,echo=TRUE}
write.table(rslt.final, paste0(path_project, outp_name,".csv" ),
......
"code_metsatilastot"; "province_name"; "forest_land"
1; "Helsinki-Uusimaa"; 518000
2; "Varsinais-Suomi"; 569000
4; "Satakunta"; 517000
5; "Kanta-Hme"; 347000
6; "Pirkanmaa"; 912000
7; "Pijt-Hme"; 359000
8; "Kymenlaakso"; 334000
9; "Etel-Karjala"; 402000
10; "Etel-Savo"; 1212000
11; "Pohjois-Savo"; 1325000
12; "Pohjois-Karjala"; 1486000
13; "Keski-Suomi"; 1369000
14; "Etel-Pohjanmaa"; 905000
15; "Pohjanmaa"; 508000
16; "Keski-Pohjanmaa"; 336000
17; "Pohjois-Pohjanmaa"; 2480000
18; "Kainuu"; 1630000
19; "Lappi"; 4998000
21; "Ahvenanmaa"; 69000
\ No newline at end of file
"code_metsatilastot";"province_name";"forest_land"
1;"Helsinki-Uusimaa";518000
2;"Varsinais-Suomi";569000
4;"Satakunta";517000
5;"Kanta-Hme";347000
6;"Pirkanmaa";912000
7;"Pijt-Hme";359000
8;"Kymenlaakso";334000
9;"Etel-Karjala";402000
10;"Etel-Savo";1212000
11;"Pohjois-Savo";1325000
12;"Pohjois-Karjala";1486000
13;"Keski-Suomi";1369000
14;"Etel-Pohjanmaa";905000
15;"Pohjanmaa";508000
16;"Keski-Pohjanmaa";336000
17;"Pohjois-Pohjanmaa";2480000
18;"Kainuu";1630000
19;"Lappi";4998000
21;"Ahvenanmaa";69000
\ No newline at end of file
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