-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_getStacksMap.r
77 lines (62 loc) · 2.17 KB
/
10_getStacksMap.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# libraries and source
source("./lib/convertStates.r")
library(raster)
library(plyr)
#clean wd
rm(list=ls())
grids_simus <- brick()
# LOCAL SIMU
#############################
ls <- list.files("./res/stacks",pattern="local-100.rda",full.names=TRUE)
# create empty stack
st_local_100_2000 <- stack()
st_local_100_2015 <- stack()
st_local_100_2045 <- stack()
st_local_100_2095 <- stack()
# fill stack by year
for(l in 1:length(ls)){
grids <- readRDS(ls[l])
st_local_100_2000 <- addLayer(st_local_100_2000,grids$X2000)
st_local_100_2015 <- addLayer(st_local_100_2015,grids$X2015)
st_local_100_2045 <- addLayer(st_local_100_2045,grids$X2045)
st_local_100_2095 <- addLayer(st_local_100_2095,grids$X2095)
}
# GLOBAL SIMU
#############################
ls <- list.files("./res/stacks",pattern="global-100.rda",full.names=TRUE)
# create empty stack
st_global_100_2000 <- stack()
st_global_100_2015 <- stack()
st_global_100_2045 <- stack()
st_global_100_2095 <- stack()
# fill stack by year
for(l in 1:length(ls)){
grids <- readRDS(ls[l])
st_global_100_2000 <- addLayer(st_global_100_2000,grids$X2000)
st_global_100_2015 <- addLayer(st_global_100_2015,grids$X2015)
st_global_100_2045 <- addLayer(st_global_100_2045,grids$X2045)
st_global_100_2095 <- addLayer(st_global_100_2095,grids$X2095)
}
##### set rasters stack by states
for(i in ls()[grep("st_",ls())]){
rs <- get(i)
rs[rs == 1] <- 0
rs[rs == 2 ] <- 1 # mixed and temperate
rs[rs == 3 ] <- 1 # mixed and temperate
rs[rs != 1 ] <- 0
rs <- sum(rs)/nlayers(rs)
names(rs) <- i
grids_simus <- addLayer(grids_simus,rs)
}
# SOLVED
#############################
st_solved_2000 <- mean(readRDS("./res/2000_tempProbSolved.rda"))
names(st_solved_2000) <- "st_solved_2000"
st_solved_2015 <- mean(readRDS("./res/2015_tempProbSolved.rda"))
names(st_solved_2015) <- "st_solved_2015"
st_solved_2045 <- mean(readRDS("./res/2045_tempProbSolved.rda"))
names(st_solved_2045) <- "st_solved_2045"
st_solved_2095 <- mean(readRDS("./res/2095_tempProbSolved.rda"))
names(st_solved_2095) <- "st_solved_2095"
grids_solved <- stack(st_solved_2000,st_solved_2015,st_solved_2045,st_solved_2095)
save(grids_solved,grids_simus,file="./res/prepGridsFigs.rda")