-
Notifications
You must be signed in to change notification settings - Fork 1
/
modelFun.R
136 lines (92 loc) · 4.19 KB
/
modelFun.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
# ---------------------------------------------------------------------------- #
# model functions to be used within the model run
# ---------------------------------------------------------------------------- #
.modelPrimaryProduction = function(outvar, i, temp, par, fpar, lai, co2,
paramfile){
## data preparation
# load model parameters
if(is.null(paramfile)){
paramfile = system.file("data",mapping="input/model_parameters.YAML",
package="PhotoBioDynamics")
}
K = yaml::read_yaml(file=paramfile)
# possibility to return multi output variables ("GPP", "NPP", "NEP")
if (length(outvar) > 1) {
multivar = array(NA, dim = c(dim(temp)[1:2],1,length(outvar)))
j = 1
}
# subset of a month
temp_i = temp[,,i]
co2_i = co2[i]
# repeating index vector for input variables par, fpar and lai that only
# comprises 1 year/12 month
idseq = rep(1:12,times=dim(temp)[3]/12)
par_i = par[,,idseq[i]]
lai_i = lai[,,idseq[i]]
fpar_i = fpar[,,idseq[i]]
## GPP PART 1: PAR-limited photosynthesis
# Calculating APAR absorbed photosynthetic active ray (mol/d/m2) after
# Schaphoff et al. 2018
# while for fpar a remote sensing product is used
apar = par_i * fpar_i * K$alphaa
ko = K$ko25 * exp((log(K$q10ko)) * (temp_i - 25) * 0.1) # O2 (Pa)
kc = K$kc25 * exp((log(K$q10kc)) * (temp_i - 25) * 0.1) # CO2 (Pa)
# Calculating temperature dependance of CO2 / O2 specific ratio (Pa/Pa)
tau = K$tau25 * exp((log(K$q10tau)) * (temp_i - 25) * 0.1)
# internal partial pressure of CO2 (Pa) # CO2 partial pressure as average
pint = K$lambda * co2_i
# CO2 compensation point (Pa) - where Photosynthesis = Respiration
gammastar = K$po2 / (2 * tau)
# (Haxeltine and Prentice 1996)
phitemp = ((1 + exp(0.2*(10-temp_i)))^-1)#+(-1-exp(0.6*(30-temp_i)))^-1
c1 = K$alphac3 * phitemp * ((pint - gammastar) / (pint + gammastar))
# PAR-limited photosynthesis rate molC/m2/h
je = c1 * K$cmass * apar
## GPP PART 2: Rubisco limited rate of photosynthesis - dependence on
## photorespiration
fac = kc * (1 + K$po2/ ko)
c2 = (pint - gammastar)/(pint + fac)
# remove not needed objects since vectorized approach uses lot of memory
rm(gammastar, pint, fac, tau, par_i, fpar_i, ko, kc)
# Calculating maximum daily rate of net photosynthis with Rubisco capacity Vm
s = (24 / K$daylength) * K$bc3 # daily average Rd/Vm
sigma = 1 - (c2 - s) / (c2 - K$theta * s)
vm = (1.0 / K$bc3) * (c1 / c2) * ((2.0 * K$theta - 1.0) * s - (
2.0 * K$theta * s - c2) * sigma) * apar * K$cmass
# Calculation of rubisco-activity-limited photosynthesis rate JC, molC/m2/d
jc = c2 * vm
# Calculation of daily gross photosynthesis, gpp, gC/d/m2
gpp = (je+jc-sqrt((je+jc)*(je+jc)-4.0*K$theta*je*jc))/(2.0*K$theta)
gpp[gpp<0] = 0
# remove not needed objects since vectorized approach uses lot of memory
rm(je, jc, c1, c2, sigma, apar)
gc()
if ("GPP" %in% outvar && length(outvar) == 1) {
return(gpp * rep(K$months_length, dim(temp)[3]/12))
} else if ("GPP" %in% outvar && length(outvar) >1) {
multivar[,,,j] = gpp * rep(K$months_length, dim(temp)[3]/12)
j = j+1
}
## NET PRIMARY PRODUCTION (NPP) [gC/d/m2] (Haxeltine and Prentice 1996)
# Calculation of daily autotrophic respiration gC/d/m2
cs = lai_i * K$CONST_ATR$cn
rleaf = K$bc3 * vm
rtrans = K$CONST_ATR$kr * cs*exp(K$CONST_ATR$e0*((
(K$CONST_ATR$tref-K$CONST_ATR$t0)^-1)-(temp_i-K$CONST_ATR$t0)^-1))
rfine = K$CONST_ATR$aa * lai_i * K$CONST_ATR$ln
rgrowth = gpp * 0.2
rauto = rleaf + rtrans + rfine + rgrowth
# Daily net primary production (NPP), And, gC/d/m2
npp = gpp - rauto
npp[npp < 0] = 0
# remove not needed objects since vectorized approach uses lot of memory
rm(vm, cs, gpp, rleaf, rtrans, rfine, rgrowth, rauto, lai_i)
gc()
if ("NPP" %in% outvar && length(outvar) == 1){
return(npp * rep(K$months_length, dim(temp)[3]/12))
}else if("NPP" %in% outvar && length(outvar) >1) {
multivar[,,,j] = npp* rep(K$months_length, dim(temp)[3]/12)
j = j+1
}
if(exists("multivar")) return(multivar)
}