-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalc_Mu_Transpiration.r
384 lines (341 loc) · 11 KB
/
Calc_Mu_Transpiration.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
rm(list=ls())
source("/Volumes/LabShare/SMAP/ESMAP_for_Ronnie/Calc_Roots.r")
library(MASS)
library(ncdf4)
library(fields)
library(maps)
library(hydroGOF)
#library(plotrix)
library(rworldmap)
library(RColorBrewer)
library(humidity)
esmap.dir = "/Volumes/LabShare/SMAP/Gridded_ESMAP/"
print(esmap.dir)
smap.lat = list.files(esmap.dir)
smap.lat = as.numeric(smap.lat)
nlat = length(smap.lat)
for(i in 1:nlat){
smap.lon = list.files(paste(esmap.dir,smap.lat[i],"/",sep=''))
nlon = length(smap.lon)
smap.lon = as.numeric(smap.lon)
for(j in 1:nlon){
working.dir = paste(esmap.dir,smap.lat[i],"/",smap.lon[j],"/",sep='')
evi.file = paste(working.dir,"EVI_raw",sep='')
for.file = paste(working.dir,"NLDAS_Forcing_raw",sep='')
noah.file = paste(working.dir,"NLDAS_NOAH_raw",sep='')
smap.file = paste(working.dir,"SMAP_raw",sep='')
veg.file = paste(working.dir,"Vegetation_raw",sep='')
soil.file = paste(working.dir,"Soil_raw",sep='')
evi.raw = read.table(evi.file)
for.raw = read.table(for.file)
noah.raw = read.table(noah.file)
smap.raw = read.table(smap.file)
veg.raw = read.table(veg.file)
soil.raw = read.table(soil.file)
d.years = smap.raw[,1]
d.months = smap.raw[,2]
d.days = smap.raw[,3]
d.smap = smap.raw[,4]
n.d = length(d.days)
h.years = noah.raw[,1]
h.months = noah.raw[,2]
h.days = noah.raw[,3]
h.hours = noah.raw[,4]
h.sw = noah.raw[,5]
h.lw = noah.raw[,6]
n.h = length(h.days)
h.pres = for.raw[,5]
h.temp = for.raw[,6]
h.sh = for.raw[,7]
tmp.smap = na.approx(d.smap)
d.smap[which(is.na(d.smap) == FALSE)[1]:tail(which(is.na(d.smap) == FALSE),1)] = tmp.smap
beg.delta = d.smap[which(is.na(d.smap) == FALSE)[2]] - d.smap[which(is.na(d.smap) == FALSE)[1]]
beg.missing = which(is.na(d.smap) == TRUE)[which(which(is.na(d.smap) == TRUE) < which(is.na(d.smap) == FALSE)[1])]
beg.smap = d.smap[which(is.na(d.smap) == FALSE)[1]] - (which(is.na(d.smap) == FALSE)[1] - beg.missing)*beg.delta
d.smap[beg.missing] = beg.smap
end.delta = d.smap[tail(which(is.na(d.smap) == FALSE),1)] - d.smap[tail(which(is.na(d.smap) == FALSE),2)[1]]
end.missing = which(is.na(d.smap) == TRUE)
end.smap = d.smap[tail(which(is.na(d.smap) == FALSE),1)] + (end.missing - tail(which(is.na(d.smap) == FALSE),1))*end.delta
d.smap[end.missing] = end.smap
d.evi = evi.raw[,4]
tmp.evi = na.approx(d.evi)
d.evi[which(is.na(d.evi) == FALSE)[1]:tail(which(is.na(d.evi) == FALSE),1)] = tmp.evi
beg.delta = d.evi[which(is.na(d.evi) == FALSE)[2]] - d.evi[which(is.na(d.evi) == FALSE)[1]]
beg.missing = which(is.na(d.evi) == TRUE)[which(which(is.na(d.evi) == TRUE) < which(is.na(d.evi) == FALSE)[1])]
beg.evi = d.evi[which(is.na(d.evi) == FALSE)[1]] - (which(is.na(d.evi) == FALSE)[1] - beg.missing)*beg.delta
d.evi[beg.missing] = beg.evi
end.delta = d.evi[tail(which(is.na(d.evi) == FALSE),1)] - d.evi[tail(which(is.na(d.evi) == FALSE),2)[1]]
end.missing = which(is.na(d.evi) == TRUE)
end.evi = d.evi[tail(which(is.na(d.evi) == FALSE),1)] + (end.missing - tail(which(is.na(d.evi) == FALSE),1))*end.delta
d.evi[end.missing] = end.evi
if((smap.lon[j]-360) <= -67.5 & (smap.lon[j]-360) > -82.5) offset = 5
if((smap.lon[j]-360) <= -82.5 & (smap.lon[j]-360) > -97.5) offset = 6
if((smap.lon[j]-360) <= -97.5 & (smap.lon[j]-360) > -112.5) offset = 7
if((smap.lon[j]-360) <= -112.5 & (smap.lon[j]-360) > -127.5) offset = 8
t.min = array(NA, c(n.d))
t.mean = array(NA, c(n.d))
sh.mean = array(NA, c(n.d))
p.mean = array(NA, c(n.d))
evi.val = array(NA, c(n.d))
vpd.val = array(NA, c(n.d))
rh.val = array(NA, c(n.d))
ra.val = array(NA, c(n.d))
m.t = array(NA, c(n.d))
m.vpd = array(NA, c(n.d))
svp.list = array(NA, c(n.d))
e.list = array(NA, c(n.d))
pe.list = array(NA, c(n.d))
d.sw = array(NA, c(n.d))
d.lw = array(NA, c(n.d))
if(veg.raw == 1){ # Evergreen Needleleaf Forest
t.open = 8.31 + 273.15
t.close = -8 + 273.15
v.close = 3000
v.open = 650
cl = 0.0032
roots = Calc_Roots(7,2,5)
}
if(veg.raw == 2){ # Evergreen Broadleaf Forest
t.open = 9.09 + 273.15
t.close = -8 + 273.15
v.close = 4000
v.open = 1000
cl = 0.0025
roots = Calc_Roots(7,1,5)
}
if(veg.raw == 3){ # Deciduous Needleleaf Forest
t.open = 10.44 + 273.15
t.close = -8 + 273.15
v.close = 3500
v.open = 650
cl = 0.0032
roots = Calc_Roots(7,2,5)
}
if(veg.raw == 4){ # Deciduous Broadleaf Forest
t.open = 9.94 + 273.15
t.close = -6 + 273.15
v.close = 2900
v.open = 650
cl = 0.0028
roots = Calc_Roots(6,2,5)
}
if(veg.raw == 5){ # Mixed Forest
t.open = 9.5 + 273.15
t.close = -7 + 273.15
v.close = 2900
v.open = 650
cl = 0.0025
roots = Calc_Roots(7,1.5,5)
}
if(veg.raw == 6){ # Woodland
t.open = 11.39 + 273.15
t.close = -8 + 273.15
v.close = 3500
v.open = 650
cl = 0.0065
roots = Calc_Roots(7,1.5,5)
}
if(veg.raw == 7){ # Wooded Grassland
t.open = 11.39 + 273.15
t.close = -8 + 273.15
v.close = 3500
v.open = 650
cl = 0.0065
roots = Calc_Roots(7,1.5,5)
}
if(veg.raw == 8){ # Closed Shrubland
t.open = 8.61 + 273.15
t.close = -8 + 273.15
v.close = 4300
v.open = 650
cl = 0.0065
roots = Calc_Roots(7,1.5,5)
}
if(veg.raw == 9){ # Open Shrubland
t.open = 8.8 + 273.15
t.close = -8 + 273.15
v.close = 4400
v.open = 650
cl = 0.0065
roots = Calc_Roots(7,1.5,5)
}
if(veg.raw == 10){ # Grassland
t.open = 12.02 + 273.15
t.close = -8 + 273.15
v.close = 4200
v.open = 650
cl = 0.007
roots = Calc_Roots(11,2,5)
}
if(veg.raw == 11){ # Cropland
t.open = 12.02 + 273.15
t.close = -8 + 273.15
v.close = 4500
v.open = 650
cl = 0.007
roots = Calc_Roots(6,3,5)
}
if(veg.raw == 12){ # Bare Ground
t.open = 12.02 + 273.15
t.close = -8 + 273.15
v.close = 4200
v.open = 650
cl = 0.007
roots = Calc_Roots(1,1,5)
}
for(k in 1:n.d){
chosen = which(h.years == d.years[k] & h.months == d.months[k] & h.days == d.days[k])
t.min[k] = min(h.temp[chosen + offset],na.rm=TRUE)
t.mean[k] = mean(h.temp[chosen + offset],na.rm=TRUE)
sh.mean[k] = mean(h.sh[chosen + offset],na.rm=TRUE)
p.mean[k] = mean(h.pres[chosen + offset],na.rm=TRUE)
d.sw[k] = sum(h.sw[chosen + offset],na.rm=TRUE)
d.lw[k] = sum(h.lw[chosen + offset],na.rm=TRUE)
tmpk = t.mean[k]
tmpmin = t.min[k]
svp = SVP.ClaCla((tmpk))*100
svp.list[k] = svp
tmpsh = sh.mean[k]
tmpp = p.mean[k]
e = tmpp*tmpsh/0.622
e.list[k] = e
rh = 100*e/svp
vpd.val[k] = (1 - rh/100)*svp
rh.val[k] = rh
tmpvpd = vpd.val[k]
if(tmpmin >= t.open) m.t[k] = 1
if(tmpmin < t.open & tmpmin > t.close) m.t[k] = (tmpmin - t.close)/(t.open - t.close)
if(tmpmin < t.close) m.t[k] = 0.1
if(tmpvpd <= v.open) m.vpd[k] = 1
if(tmpvpd > v.open & tmpvpd < v.close) m.vpd[k] = (v.close - tmpvpd)/(v.close - v.open)
if(tmpvpd >= v.close) m.vpd[k] = 0.1
}
lai.val = d.evi/1000
resistance = 1/(cl * m.t * m.vpd * lai.val)
if(soil.raw == 1){ # Sand
REFSMC = 0.236
WLTSMC = 0.010
}
if(soil.raw == 2){ # Loamy sand
REFSMC = 0.383
WLTSMC = 0.028
}
if(soil.raw == 3){ # Sandy loam
REFSMC = 0.383
WLTSMC = 0.047
}
if(soil.raw == 4){ # Silt loam
REFSMC = 0.360
WLTSMC = 0.084
}
if(soil.raw == 5){ # Silt
REFSMC = 0.383
WLTSMC = 0.084
}
if(soil.raw == 6){ # Loam
REFSMC = 0.329
WLTSMC = 0.066
}
if(soil.raw == 7){ # Sandy clay loam
REFSMC = 0.314
WLTSMC = 0.067
}
if(soil.raw == 8){ # Silty clay loam
REFSMC = 0.387
WLTSMC = 0.120
}
if(soil.raw == 9){ # Clay loam
REFSMC = 0.382
WLTSMC = 0.103
}
if(soil.raw == 10){ # Sandy clay
REFSMC = 0.338
WLTSMC = 0.100
}
if(soil.raw == 11){ # Silty clay
REFSMC = 0.404
WLTSMC = 0.126
}
if(soil.raw == 12){ # Clay
REFSMC = 0.412
WLTSMC = 0.138
}
if(soil.raw == 13){ # Organic materials
REFSMC = 0.329
WLTSMC = 0.066
}
if(soil.raw == 15){ # Bedrock
REFSMC = 0.17
WLTSMC = 0.006
}
if(soil.raw == 16){ # Other
REFSMC = 0.283
WLTSMC = 0.028
}
A = d.sw + d.lw
# To calculate Penman Monteith
# ET = (s * A + rho * cp * (esat - e) / ra) / (s + gamma * (1 + rs / ra))
# s = d(esat)/dT, the slope of the curve relating saturated water vapor pressure (esat) to temperature (Pa/K) - CALCULATED
# s = 4098 * 0.6108 * exp((17.27 + T)/(T + 237.3)) / ((T + 237.3)^2)
# T = Temperature (C) - FROM NLDAS FORCING
# A = net radiation (W/m2) - SOLAR NET AND LONGWAVE NET IN NLDAS NOAH
# rho = air density (kg/m3) - 1.225
# cp = specific heat capacity of air (J/kg/K) - 1005
# ra = aerodynamic resistance (s/m) - CALCULATE
# ra = (rc * rr) / (rc + rr)
# rc = resistance to convective heat transfer (s/m) - CALUCLATE
# rc = 107 / (((273.15 + T)/393.15)^1.75 * 101300/P)
# T = degrees (C) - FROM NLDAS FORCING
# P = Pressure (Pa) - FROM NLDAS FORCING
# rr = resistance to radiative heat transfer (s/m)
# rr = (rho * cp) / (4 * sigma * T^3)
# sigma = Stefan Boltzmann - 5.670 * 10^-8
# T = Temperature (K) - - FROM NLDAS FORCING (CONVERT TO K)
# gamma = psychometric constant (Pa/K)
# gamma = (Ma / Mw) * (cp * P / lambda)
# Ma = molecular masses of dry air (kg/mol) - 0.02897
# Mw = molecular masses of wet air (kg/mol) - 0.01802
# cp = specific heat capacity of air (J/kg/K) - 1005
# P = atmospheric pressure (Pa) - FROM NLDAS FORCING
# lambda = latent heat of evaporation (J/kg) - 2501000
# rs = surface resistance (s/m) - CALCULLATED VIA MODIS
# e = water vapor pressure (Pa) - CALCULATED
# esat = staturation vapor pressure (Pa) - CALCULATED
rho = 1.225
cp = 1005
Ma = 0.02897
Mw = 0.01802
lambda = 2501000
sigma = 5.670 * 10^-8
T.c = t.mean - 273.15
s = 4098 * 0.6108 * exp((17.27 + T.c)/(T.c + 237.3)) / ((T.c + 237.3)^2)
rc = 107 / (((273.15 + T.c)/393.15)^1.75 * 101300/p.mean)
rr = (rho * cp) / (4 * sigma * t.mean^3)
ra = (rc * rr) / (rc + rr)
gamma = (Ma / Mw) * (cp * p.mean / lambda)
lai.min = min(lai.val)
lai.max = max(lai.val)
Fc = (lai.val - lai.min)/(lai.max - lai.min)
RH = rh.val/100
tmp = which(RH < 0.7)
if(length(tmp) >= 1) RH[tmp] = 0
Fwet = RH^4
Ac = A*Fc
PM.ET = (s * A + rho * cp * (svp.list - e.list) / ra) / (s + gamma * (1 + resistance / ra))
PM.ET.22 = (s * Ac * Fc + rho * cp * (svp.list - e.list) * Fc / ra)*(1 - Fwet) / (s + gamma * (1 + resistance / ra))
PM.ET.s = PM.ET / lambda
PM.ET.day = PM.ET.s * 60 * 60 * 24
PM.ET.22.s = PM.ET.22 / lambda
PM.ET.22.day = PM.ET.22.s * 60 * 60 * 24
PM.ET.22.day.roots = PM.ET.22.day * roots
gx = (d.smap - WLTSMC) / (REFSMC - WLTSMC)
tmp = which(gx <= 0)
gx[tmp] = 0
tmp = which(gx >= 1)
gx[tmp] = 1
PM.ET.22.day.roots.sm = PM.ET.22.day.roots * gx
new.file = paste(working.dir,"Transpiration_Estimates",sep='')
to.write = cbind(d.years, d.months, d.days, PM.ET.day, PM.ET.22.day, PM.ET.22.day.roots, PM.ET.22.day.roots.sm)
write.table(to.write,new.file,sep="\t", col.names = F, row.names = F)
}
}