-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulation Experiments.R
203 lines (173 loc) · 6.73 KB
/
Simulation Experiments.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
n.iter <- 1000#plots to check
Y <- 120
Weather <- Weather
Latitude_s <- matrix(0,n.iter,Y,byrow=T)
Longitude_s <- matrix(0,n.iter,Y,byrow=T)
MFRI_s <- matrix(0,n.iter,Y,byrow=T)
#stand dynamics
Ba_s <- matrix(0,n.iter,Y,byrow=T)
Size_list <- vector("list", n.iter) # create list
PreFireStand_s <-vector("list", n.iter)
Transition_list <- vector("list", n.iter)
Structure_s <- matrix(0,n.iter,Y,byrow=T)
Recruits_s <- matrix(0,n.iter,Y,byrow=T)
Heights_list <- vector("list", n.iter)
CR_list <- vector("list", n.iter)
GrowthIndex_list <- vector ("list", n.iter)
DiameterGrowth_list<- vector("list", n.iter)
DecayRates_list<-vector("list", n.iter)
DOM_Pool_list <- vector("list", n.iter)
DOM_Inputs_list <- vector("list", n.iter)
DOM_Flux_s <- matrix(0,n.iter,Y,byrow=T)
PrimaryProductivity_s <- matrix(0,n.iter,Y,byrow=T)
NetEcosystemProduction_s <- matrix(0,n.iter,Y,byrow=T)
Rh_s <- matrix(0,n.iter,Y,byrow=T)
NetBiomeProduction_s <- matrix(0,n.iter,Y,byrow=T)
Turnover_s <- matrix(0,n.iter,Y,byrow=T)
TotalLiveBiomass_s <- matrix(0,n.iter,Y,byrow=T)
EmpiricalTemperature_s <- matrix(0,n.iter,Y,byrow=T)
DroughtCodes_s <- matrix(0,n.iter,Y,byrow=T)
SnagCProduction_s <- matrix(0,n.iter,Y,byrow=T)
Severity_s <- matrix(0,n.iter,Y,byrow=T)
InitialIntensity_s <- matrix(0,n.iter,Y,byrow=T)
NF_s <- numeric(n.iter)
Emissions_s <- matrix(0,n.iter,Y,byrow=T)
for(i in 1:n.iter){
Size_list[[i]] <- matrix(0,Y,15,byrow=T)
DiameterGrowth_list[[i]]<- matrix(0,Y,15,byrow=T)
PreFireStand_s[[i]]<-matrix(0,Y,15,byrow=T)
Transition_list[[i]]<-matrix(0,Y,15,byrow=T)
Heights_list[[i]]<-matrix(0,Y,15,byrow=T)
CR_list[[i]]<-matrix(0,Y,15,byrow=T)
DOM_Pool_list[[i]]<- matrix(0,Y,9,byrow=T)
DOM_Inputs_list[[i]]<- matrix(0,Y,9,byrow=T)
DecayRates_list[[i]]<- matrix(0,Y,9,byrow=T)
}
do.call(rbind, Size_list)
do.call(rbind, Transition_list)
do.call(rbind, DiameterGrowth_list)
do.call(rbind, Heights_list)
do.call(rbind, CR_list)
do.call(rbind, DOM_Pool_list)
do.call(rbind, DOM_Inputs_list)
do.call(rbind, DecayRates_list)
for (i in 1:n.iter){
CarbonModel <- exe(stand,Y,Weather)
Latitude_s [i,] <- CarbonModel$Latitudes
Longitude_s [i,] <- CarbonModel$Longitudes
MFRI_s [i,] <- CarbonModel$MFRI
Ba_s[i,]<-CarbonModel$BA
Structure_s[i,]<-CarbonModel$Structure
Recruits_s[i,]<-CarbonModel$Recruits
Size_list[[i]]<-CarbonModel$Size
DiameterGrowth_list[[i]] <-CarbonModel$DiameterGrowth
PreFireStand_s[[i]] <-CarbonModel$PreFireStand
Transition_list[[i]]<-CarbonModel$Transition
Heights_list[[i]]<-CarbonModel$Heights
GrowthIndex_list [[i]] <- CarbonModel$CCGrowthIndex
CR_list[[i]] <- CarbonModel$CR
TotalLiveBiomass_s[i,] <- CarbonModel$TotalLiveBiomass
EmpiricalTemperature_s[i,] <-CarbonModel$EmpiricalTemperature
DroughtCodes_s[i,] <- CarbonModel$DroughtCode
SnagCProduction_s[i,] <- CarbonModel$SnagCProduction
PrimaryProductivity_s[i,] <- CarbonModel$NetPrimaryProductivity
NetEcosystemProduction_s[i,] <- CarbonModel$NetEcosystemProduction
NetBiomeProduction_s[i,] <- CarbonModel$NetBiomeProduction
Rh_s[i,] <- CarbonModel$Rh
Turnover_s[i,] <- CarbonModel$Turnover
DOM_Pool_list[[i]] <- CarbonModel$DOMC_Pool
DecayRates_list[[i]] <- CarbonModel$AppliedDecayRates
DOM_Flux_s[i,] <- CarbonModel$DOM_Flux
DOM_Inputs_list[[i]] <- CarbonModel$DOM_Inputs
Severity_s[i,] <- CarbonModel$BALost
InitialIntensity_s[i,] <- CarbonModel$InitialIntensity
Emissions_s[i,] <- CarbonModel$CarbonEmissions3
NF_s[i] <- CarbonModel$NF
print(i)
}
Year <- 1:120
plots <- n.iter
BasalArea <- Ba_s[, Year]
BiomassLiveCStock <- TotalLiveBiomass_s[1:plots, Year]
NPP <- PrimaryProductivity_s[1:plots, Year]
SoilRespiration <- Rh_s[1:plots, Year]
NEP <- NetEcosystemProduction_s[1:plots, Year]
NBP <- NetBiomeProduction_s[1:plots, Year]
Lat <- Latitude_s[,1]
Lon <- Longitude_s[,1]
Snags <- sapply(DOM_Pool_list, function(m) m[1:120,1]) #
SnagBranch <- sapply(DOM_Pool_list, function(m) m[1:120,2])
AGMedium <- sapply(DOM_Pool_list, function(m) m[1:120,3])
AGfast <- sapply(DOM_Pool_list, function(m) m[1:120,4])
AGveryfast <- sapply(DOM_Pool_list, function(m) m[1:120,5])
AGslow <- sapply(DOM_Pool_list, function(m) m[1:120,6])
BGveryfast <- sapply(DOM_Pool_list, function(m) m[1:120,7])
BGfast <- sapply(DOM_Pool_list, function(m) m[1:120,8])
BGslow <- sapply(DOM_Pool_list, function(m) m[1:120,9])
SoilCStock1 <- Snags+SnagBranch+AGMedium+AGfast+AGveryfast+AGslow+BGveryfast+BGfast+BGslow
SoilCStock <- t(SoilCStock1)
EcosystemCStock <- BiomassLiveCStock + SoilCStock
MineralSoil <- t(BGveryfast+BGslow)
Organic <- t(AGveryfast+AGslow)
WoodyDebris <- t(Snags+SnagBranch+AGfast+AGMedium)
sn <- t(Snags)
sb <- t(SnagBranch)
am <-t(AGMedium)
af <- t(AGfast)
avf <- t(AGveryfast)
asl <- t(AGslow)
bgvf <- t(BGveryfast)
bgf <- t(BGfast)
bgs <- t(BGslow)
intensities <- rep(0, 120)
for (i in 1:120){
I <- InitialIntensity_s[,i]
I2 <- mean(I[I!=0])
intensities[i] <- I2
intensities <- replace(intensities,is.na(intensities),0)
}
droughts <- rep(0, 120)
for (i in 1:120){
D <- DroughtCodes_s[,i]
D2 <- mean(D[D!=0])
droughts[i] <- D2
droughts<- replace(droughts,is.na(droughts),0)
}
seve <- rep(0, 120)
for (i in 1:120){
S <- Severity_s[,i]
S2 <- mean(S[S!=0])
seve[i] <- S2
seve <- replace(seve,is.na(seve),0)
}
emi <- rep(0, 120)
for (i in 1:120){
E <- Emissions_s[,i]
E2 <- mean(E[E!=0])
emi[i] <- E2
emi <- replace(emi,is.na(emi),0)
}
GIs <- rowMeans(sapply(GrowthIndex_list, function(m) m[]))
AnnTemp <- colMeans(EmpiricalTemperature_s)
##DecompositionratesCarbonPools
SnagsDecorate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,1]))
SnagsBranchDecorate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,2]))
MediumDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,3]))
agfastDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,4]))
agvfDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,5]))
agsDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,6]))
bgvfDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,7]))
bgfDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,8]))
bgsDecRate <- rowMeans(sapply(DecayRates_list, function(m) m[1:120,9]))
fireregime <- cbind(intensities,droughts,seve,emi)
goann <- cbind(GIs,AnnTemp)
ApDecRates <- cbind(SnagsDecorate,SnagsBranchDecorate,MediumDecRate,agfastDecRate,
agvfDecRate,bgvfDecRate,bgfDecRate,bgsDecRate)
Path5<- list(NPP,NEP,NBP,SoilRespiration,BiomassLiveCStock,SoilCStock,EcosystemCStock,MineralSoil,Organic,WoodyDebris,
sn,sb,am,af,avf,asl,bgvf,bgf,bgs)
Path5Coor <- cbind(Lat,Lon)
save("ApDecRates", file="DecayRatePath5.RData")
save("fireregime", file="FireregimePath5.RData")
save("goann", file="GrowthTemp5.RData")
save("Path5", file="Path5.RData")
save("Path5Coor", file="Path5Coor.RData")