-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.R
2100 lines (1832 loc) · 58.2 KB
/
utilities.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
is_leap_year <- function (yr) {
return (yr %% 400 == 0 || (yr %% 100 != 0 && yr %% 4 == 0))
}
round_to_value <- function(number, roundto) {
return (round(number / roundto) * roundto)
}
DEG2RAD <- function(DEG) {
return (DEG * pi / 180.0)
}
RAD2DEG <- function(RAD) {
return (180.0 * RAD / pi)
}
float_eq <- function(a, b) {
# Are two floats approximately equal...?
#
# Reference:
# ----------
# D. E. Knuth. The Art of Computer Programming. Sec. 4.2.2 pp. 217-8.
return (abs(a - b) <= EPSILON * abs(a))
}
alloc_goal_seek <- function (simulated, target, alloc_max, sensitivity) {
# Sensitivity parameter characterises how allocation fraction respond
# when the leaf:sapwood area ratio departs from the target value
# If sensitivity close to 0 then the simulated leaf:sapwood area ratio
# will closely track the target value
frac <- 0.5 + 0.5 * (1.0 - simulated / target) / sensitivity
return (max(0.0, alloc_max * min(1.0, frac)))
}
time_till_next_disturbance <- function() {
# calculate the number of years until a disturbance event occurs
# assuming a return interval of X years
#
# - section 3.4.1 D. Knuth, The Art of Computer Programming.
#
# Parameters
# ----------
# return_interval : int/float
# interval disturbance return at in years
# rate = 1.0 / return_interval
#return int(-log(1.0 - random.random()) / rate)
return (11)
}
calc_warmest_quarter_temp <- function(yr) {
# calculate mean temperature of the warmest quarter
# Ref: Atkin et al. (2015) New Phytologist
# Table 6 best model for area-based broadleaved tree leaf respiration
#
# Parameters:
# ----------
# TWQ: float
# mean temperature of the warmest quarter
# q1 - q4: float
# quarterly-based mean air temperature
t1 <- 0
t2 <- 0
t3 <- 0
t4 <- 0
if (is_leap_year(yr)) {
for (doy in 1:366) {
if (doy >= 1 && doy <= 91) {
t1 <- t1 + ma$tair[doy]
} else if (doy >= 92 && doy <= 182) {
t2 <- t2 + ma$tair[doy]
} else if (doy >= 183 && doy <= 274) {
t3 <- t3 + ma$tair[doy]
} else if (doy >= 275 && doy <= 366) {
t4 <- t4 + ma$tair[doy]
}
}
} else {
for (doy in 1:365) {
if (doy >= 1 && doy <= 90) {
t1 <- t1 + ma$tair[doy]
} else if (doy >= 91 && doy <= 181) {
t2 <- t2 + ma$tair[doy]
} else if (doy >= 182 && doy <= 273) {
t3 <- t3 + ma$tair[doy]
} else if (doy >= 274 && doy <= 365) {
t4 <- t4 + ma$tair[doy]
}
}
}
# compute quarterly mean temperature
if (is_leap_year(yr)) {
q1 <- t1 / 91.0
} else {
q1 <- t1 / 90.0
}
q2 <- t2 / 91.0
q3 <- t3 / 92.0
q4 <- t4 / 92.0
TWQ <- max(q1, q2, q3, q4)
twq <<- TWQ
}
calc_day_length <- function(doy, num_days, latitude) {
# Daylength in hours
#
# Eqns come from Leuning A4, A5 and A6, pg. 1196
#
# Reference:
# ----------
# Leuning et al (1995) Plant, Cell and Environment, 18, 1183-1200.
#
# Parameters:
# -----------
# doy : int
# day of year, 1=jan 1
# yr_days : int
# number of days in a year, 365 or 366
# latitude : float
# latitude [degrees]
#
# Returns:
# --------
# dayl : float
# daylength [hrs]
deg2rad <- pi / 180.0
latr <- latitude * deg2rad
sindec <- -sin(23.5 * deg2rad) * cos(2.0 * pi * (doy + 10.0) / num_days)
a <- sin(latr) * sindec
b <- cos(latr) * cos(asin(sindec))
return (12.0 * (1.0 + (2.0 / pi) * asin(a / b)))
}
calculate_daylength <- function(num_days, latitude) {
# wrapper to put the day length into an array
for (i in 1:num_days) {
day_length[i] <<- calc_day_length(i, num_days, latitude)
}
}
gdd_chill_thresh <- function(pa, pb, pc, ncd) {
# Leaf out has a chilling requirement, num chill days reduces the GDD
# requirement
return (pa + pb * exp(pc * ncd))
}
calc_gdd <- function(Tavg) {
# calculate the number of growing degree days, hypothesis is that
# leaves appear after a threshold has been passed.
Tbase <- 5.0 # degC
return (max(0.0, Tavg - Tbase))
}
leaf_drop <- function(daylen, Tsoil, Tsoil_next_3days) {
# Thresholds to drop leaves come from White et al.
# Note 655 minutes = 10.916 hrs.
#
# - Dependance on daylength means that this is only valid outside of the
# tropics.
#
# References:
# -----------
# White, M. A. et al. (1997) GBC, 11, 217-234.
if ((daylen <= 10.9166667 && Tsoil <= 11.15) || Tsoil_next_3days < 2.0) {
return (TRUE)
} else {
return (FALSE)
}
}
calc_ncd <- function(Tmean) {
# Calculate the number of chilling days from fixed dates (1 Nov),
# following Murray et al. 1989, same as Botta does. """
if (Tmean < 5.0) {
return (1.0)
} else {
return (0.0)
}
}
decay_in_dry_soils <- function(decay_rate, decay_rate_dry) {
# Decay rates (e.g. leaf litterfall) can increase in dry soil, adjust
# decay param. This is based on field measurements by F. J. Hingston
# (unpublished) cited in Corbeels.
#
# Parameters:
# -----------
# decay_rate : float
# default model parameter decay rate [tonnes C/ha/day]
# decay_rate_dry : float
# default model parameter dry deacy rate [tonnes C/ha/day]
#
# Returns:
# --------
# decay_rate : float
# adjusted deacy rate if the soil is dry [tonnes C/ha/day]
#
# Reference:
# ----------
# Corbeels et al. (2005) Ecological Modelling, 187, 449-474.
# turn into fraction...
smc_root <- pawater_root / wcapac_root
new_decay_rate <- (decay_rate_dry - (decay_rate_dry - decay_rate) *
(smc_root - watdecaydry) /
(watdecaywet - watdecaydry))
if (new_decay_rate < decay_rate)
new_decay_rate <- decay_rate
if (new_decay_rate > decay_rate_dry)
new_decay_rate <- decay_rate_dry
return (new_decay_rate)
}
daily_grazing_calc <- function(fdecay) {
# daily grass grazing...
#
# Parameters:
# -----------
# fdecay : float
# foliage decay rate
#
# Returns:
# --------
# ceaten : float
# C consumed by grazers [tonnes C/ha/day]
# neaten : float
# N consumed by grazers [tonnes N/ha/day]
# peaten : float
# P consumed by grazers [tonnes P/ha/day]
ceaten <<- fdecay * fracteaten / (1.0 - fracteaten) * shoot
neaten <<- fdecay * fracteaten / (1.0 - fracteaten) * shootn
peaten <<- fdecay * fracteaten / (1.0 - fracteaten) * shootp
}
annual_grazing_calc <- function() {
# Annual grass grazing...single one off event
#
#
# Returns:
# --------
# ceaten : float
# C consumed by grazers [tonnes C/ha/day]
# neaten : float
# N consumed by grazers [tonnes N/ha/day]
# peaten : float
# P consumed by grazers [tonnes P/ha/day]
ceaten <<- shoot * fracteaten
neaten <<- shootn * fracteaten
peaten <<- shootp * fracteaten
}
calc_beta <- function(paw, depth, fc, wp, exponent) {
# Soil water modifier, standard JULES/CABLE type approach
#
# equation 16 in Egea
#
# Note: we don't need to subtract the wp in the denominator here
# because our plant available water (paw) isn't bounded by
# the wilting point, it reaches zero
#
# Reference:
# ----------
# * Egea et al. (2011) Agricultural and Forest Meteorology.
theta <- paw / depth
beta <- (theta / (fc - wp)) ^ exponent
if (beta > fc) {
beta <- 1.0
} else if (beta <= wp) {
beta <- 0.0
}
return (beta)
}
calc_sw_modifier <- function(theta, c_theta, n_theta) {
# Soil water modifier, equation 2 in Landsberg and Waring.
# Note: "The values of c_theta and n_theta are, nevertheless, chosen
# without specific empirical justification" :)
#
# Reference:
# ----------
# * Landsberg and Waring (1997) Forest Ecology and Management 95, 209-228.
return (1.0 / (1.0 + ((1.0 - theta) / c_theta) ^ n_theta))
}
calculate_top_of_canopy_n <- function(ncontent) {
# Calculate the canopy N at the top of the canopy (g N m-2), N0.
# Assuming an exponentially decreasing N distribution within the canopy:
#
# Note: swapped kext with kn
#
# Returns:
# -------
# N0 : float (g N m-2)
# Top of the canopy N
#
# References:
# -----------
# * Chen et al 93, Oecologia, 93,63-69.
if (lai > 0.0) {
# calculation for canopy N content at the top of the canopy
N0 <- ncontent * kn / (1.0 - exp(-kn * lai))
} else {
N0 <- 0.0
}
return (N0)
}
calculate_top_of_canopy_p <- function(pcontent) {
# Calculate the canopy P at the top of the canopy (g P m-2), P0.
# Assuming an exponentially decreasing P distribution within the canopy:
#
# Note: swapped kext with kp
#
# Returns:
# -------
# P0 : float (g P m-2)
# Top of the canopy P
if (lai > 0.0) {
# calculation for canopy P content at the top of the canopy
P0 <- pcontent * kp / (1.0 - exp(-kp * lai))
} else {
P0 <- 0.0
}
return (P0)
}
arrh <- function(mt, k25, Ea, Tk) {
# Temperature dependence of kinetic parameters is described by an
# Arrhenius function
#
# Parameters:
# ----------
# k25 : float
# rate parameter value at 25 degC
# Ea : float
# activation energy for the parameter [J mol-1]
# Tk : float
# leaf temperature [deg K]
#
# Returns:
# -------
# kt : float
# temperature dependence on parameter
#
# References:
# -----------
# * Medlyn et al. 2002, PCE, 25, 1167-1179.
return (k25 * exp((Ea * (Tk - mt)) / (mt * RGAS * Tk)))
}
calculate_co2_compensation_point <- function(Tk, mt) {
# CO2 compensation point in the absence of mitochondrial respiration
# Rate of photosynthesis matches the rate of respiration and the net CO2
# assimilation is zero.
#
# Parameters:
# ----------
# Tk : float
# air temperature (Kelvin)
#
# Returns:
# -------
# gamma_star : float
# CO2 compensation point in the abscence of mitochondrial respiration
return (arrh(mt, gamstar25, eag, Tk))
}
calculate_michaelis_menten_parameter <- function(Tk, mt) {
# Effective Michaelis-Menten coefficent of Rubisco activity
#
# Parameters:
# ----------
# Tk : float
# air temperature (Kelvin)
#
# Returns:
# -------
# Km : float
# Effective Michaelis-Menten constant for Rubisco catalytic activity
#
# References:
# -----------
# Rubisco kinetic parameter values are from:
# * Bernacchi et al. (2001) PCE, 24, 253-259.
# * Medlyn et al. (2002) PCE, 25, 1167-1179, see pg. 1170.
# Michaelis-Menten coefficents for carboxylation by Rubisco
Kc <- arrh(mt, kc25, eac, Tk)
# Michaelis-Menten coefficents for oxygenation by Rubisco
Ko <- arrh(mt, ko25, eao, Tk)
# return effective Michaelis-Menten coefficient for CO2
return ( Kc * (1.0 + oi / Ko) )
}
peaked_arrh <- function(mt, k25, Ea, Tk, deltaS, Hd) {
# Temperature dependancy approximated by peaked Arrhenius eqn,
# accounting for the rate of inhibition at higher temperatures.
#
# Parameters:
# ----------
# k25 : float
# rate parameter value at 25 degC
# Ea : float
# activation energy for the parameter [J mol-1]
# Tk : float
# leaf temperature [deg K]
# deltaS : float
# entropy factor [J mol-1 K-1)
# Hd : float
# describes rate of decrease about the optimum temp [J mol-1]
#
# Returns:
# -------
# kt : float
# temperature dependence on parameter
#
# References:
# -----------
# * Medlyn et al. 2002, PCE, 25, 1167-1179.
arg1 <- arrh(mt, k25, Ea, Tk)
arg2 <- 1.0 + exp((mt * deltaS - Hd) / (mt * RGAS))
arg3 <- 1.0 + exp((Tk * deltaS - Hd) / (Tk * RGAS))
return (arg1 * arg2 / arg3)
}
adj_for_low_temp <- function(param, Tk) {
# Function allowing Jmax/Vcmax to be forced linearly to zero at low T
#
# Parameters:
# ----------
# Tk : float
# air temperature (Kelvin)
lower_bound <- 0.0
upper_bound <- 10.0
Tc <- Tk - DEG_TO_KELVIN
if (Tc < lower_bound)
param <- 0.0
else if (Tc < upper_bound)
param <- param * (Tc - lower_bound) / (upper_bound - lower_bound)
return (param)
}
calculate_ci <- function(vpd, Ca) {
# Calculate the intercellular (Ci) concentration
#
# Formed by substituting gs = g0 + 1.6 * (1 + (g1/sqrt(D))) * A/Ca into
# A = gs / 1.6 * (Ca - Ci) and assuming intercept (g0) = 0.
#
# Parameters:
# ----------
# vpd : float
# vapour pressure deficit [Pa]
# Ca : float
# ambient co2 concentration
#
# Returns:
# -------
# ci:ca : float
# ratio of intercellular to atmospheric CO2 concentration
#
# References:
# -----------
# * Medlyn, B. E. et al (2011) Global Change Biology, 17, 2134-2144.
ci <- 0.0
if (gs_model == MEDLYN) {
g1w <- g1 * wtfac_root
cica <- g1w / (g1w + sqrt(vpd * PA_2_KPA))
ci <- cica * Ca
} else {
stop("Only Belindas gs model is implemented")
}
return (ci)
}
assim <- function(ci, gamma_star, a1, a2) {
# Morning and afternoon calcultion of photosynthesis with the
# limitation defined by the variables passed as a1 and a2, i.e. if we
# are calculating vcmax or jmax limited.
#
# Parameters:
# ----------
# ci : float
# intercellular CO2 concentration.
# gamma_star : float
# CO2 compensation point in the abscence of mitochondrial respiration
# a1 : float
# variable depends on whether the calculation is light or rubisco
# limited.
# a2 : float
# variable depends on whether the calculation is light or rubisco
# limited.
#
# Returns:
# -------
# assimilation_rate : float
# assimilation rate assuming either light or rubisco limitation.
if (ci < gamma_star) {
return (0.0)
} else {
return (a1 * (ci - gamma_star) / (a2 + ci))
}
}
calculate_quantum_efficiency <- function(ci, gamma_star) {
# Quantum efficiency for AM/PM periods replacing Sands 1996
# temperature dependancy function with eqn. from Medlyn, 2000 which is
# based on McMurtrie and Wang 1993.
#
# Parameters:
# ----------
# ci : float
# intercellular CO2 concentration.
# gamma_star : float [am/pm]
# CO2 compensation point in the abscence of mitochondrial respiration
#
# Returns:
# -------
# alpha : float
# Quantum efficiency
#
# References:
# -----------
# * Medlyn et al. (2000) Can. J. For. Res, 30, 873-888
# * McMurtrie and Wang (1993) PCE, 16, 1-13.
return (assim(ci, gamma_star, alpha_j / 4.0, 2.0 * gamma_star))
}
assim_p <- function(P0) {
# // Calculate photosynthesis assimilation rate based on P limitation
# // Ref: Ellsworth et al., 2015, Plant, Cell and Environment, able 2
# //
# // Returns:
# // -------
# // ap: float
# // assimilation rate assuming P limitation
conv <- MMOL_2_MOL * 31.0
tp <- 6.51 + 14.64 * (P0 * conv)
ap <- 3.0 * tp
return(ap)
}
epsilon <- function(asat, par, alpha, daylen) {
# Canopy scale LUE using method from Sands 1995, 1996.
#
# Sands derived daily canopy LUE from Asat by modelling the light response
# of photosysnthesis as a non-rectangular hyperbola with a curvature
# (theta) and a quantum efficiency (alpha).
#
# Assumptions of the approach are:
# - horizontally uniform canopy
# - PAR varies sinusoidally during daylight hours
# - extinction coefficient is constant all day
# - Asat and incident radiation decline through the canopy following
# Beer's Law.
# - leaf transmission is assumed to be zero.
#
# * Numerical integration of "g" is simplified to 6 intervals.
#
# Parameters:
# ----------
# asat : float
# Light-saturated photosynthetic rate at the top of the canopy
# par : float
# photosyntetically active radiation (umol m-2 d-1)
# theta : float
# curvature of photosynthetic light response curve
# alpha : float
# quantum yield of photosynthesis (mol mol-1)
#
# Returns:
# -------
# lue : float
# integrated light use efficiency over the canopy (umol C umol-1 PAR)
#
# Notes:
# ------
# NB. I've removed solar irradiance to PAR conversion. Sands had
# gamma = 2000000 to convert from SW radiation in MJ m-2 day-1 to
# umol PAR on the basis that 1 MJ m-2 = 2.08 mol m-2 & mol to umol = 1E6.
# We are passing PAR in umol m-2 d-1, thus avoiding the above.
#
# References:
# -----------
# See assumptions above...
# * Sands, P. J. (1995) Australian Journal of Plant Physiology,
# 22, 601-14.
# subintervals scalar, i.e. 6 intervals
delta <- 0.16666666667
# number of seconds of daylight
h <- daylen * SECS_IN_HOUR
if (asat > 0.0) {
# normalised daily irradiance
q <- pi * kext * alpha * par / (2.0 * h * asat)
integral_g <- 0.0
for (i in seq(1, 12, by=2)) {
sinx <- sin(pi * i / 24)
arg1 <- sinx
arg2 <- 1.0 + q * sinx
arg3 <- (sqrt((1.0 + q * sinx) ^ 2 - 4.0 * theta * q * sinx))
integral_g <- integral_g + arg1 / (arg2 + arg3)
}
integral_g <- integral_g * delta
lue <- alpha * integral_g * pi
} else {
lue <- 0.0
}
return (lue)
}
quadratic <- function(a, b, c) {
# minimilist quadratic solution
#
# Parameters:
# ----------
# a : float
# co-efficient
# b : float
# co-efficient
# c : float
# co-efficient
#
# Returns:
# -------
# root : float
# discriminant
d <- b ^ 2.0 - 4.0 * a * c
# Negative quadratic equation
root <- (-b - sqrt(d)) / (2.0 * a)
return (root)
}
calc_respiration <- function(Tk, vcmax25) {
# Mitochondrial respiration may occur in the mesophyll as well as in the
# bundle sheath. As rubisco may more readily refix CO2 released in the
# bundle sheath, Rd is described by its mesophyll and bundle-sheath
# components: Rd = Rm + Rs
#
# Parameters:
# ----------
# Tk : float
# air temperature (kelvin)
# vcmax25 : float, list
#
# Returns:
# -------
# Rd : float, list [am, pm]
# (respiration in the light) 'day' respiration (umol m-2 s-1)
#
# References:
# -----------
# Tjoelker et al (2001) GCB, 7, 223-230.
Tref <- 25.0
# ratio between respiration rate at one temperature and the respiration
# rate at a temperature 10 deg C lower
Q10 <- 2.0
# scaling constant to Vcmax25, value = 0.015 after Collatz et al 1991.
# Agricultural and Forest Meteorology, 54, 107-136. But this if for C3
# Value used in JULES for C4 is 0.025, using that one, see Clark et al.
# 2011, Geosci. Model Dev, 4, 701-722.
fdr <- 0.025
# specific respiration at a reference temperature (25 deg C)
Rd25 <- fdr * vcmax25
return (Rd25 * (Q10 ^ (((Tk - DEG_TO_KELVIN) - Tref) / 10.0)))
}
lloyd_and_taylor <- function(temp) {
# Modified Arrhenius equation (Lloyd & Taylor, 1994)
# The modification introduced by Lloyd & Taylor (1994) represents a
# decline in the parameter for activation energy with temperature.
#
# Parameters:
# -----------
# temp : float
# temp deg C
return (exp(308.56 * ((1.0 / 56.02) - (1.0 / (temp + 46.02)))))
}
calc_net_radiation <- function(sw_rad, tair) {
# Net loss of long-wave radn, Monteith & Unsworth '90, pg 52, eqn 4.17
net_lw <- 107.0 - 0.3 * tair # W m-2
# Net radiation recieved by a surf, Monteith & Unsw '90, pg 54 eqn 4.21
# - note the minus net_lw is correct as eqn 4.17 is reversed in
# eqn 4.21, i.e Lu-Ld vs. Ld-Lu
# - NB: this formula only really holds for cloudless skies!
# - Bounding to zero, as we can't have negative soil evaporation, but you
# can have negative net radiation.
# - units: W m-2
net_rad <- max(0.0, (1.0 - albedo) * sw_rad - net_lw)
return (net_rad)
}
calc_stomatal_conductance <- function(vpd, Ca, gpp) {
# Calculate stomatal conductance using Belinda's model. For the medlyn
# model this is already in conductance to CO2, so the 1.6 from the
# corrigendum to Medlyn et al 2011 is missing here
#
# References:
# -----------
# For conversion factor for conductance see...
# * Jones (1992) Plants and microclimate, pg 56 + Appendix 3
# * Diaz et al (2007) Forest Ecology and Management, 244, 32-40.
#
# Stomatal Model:
# * Medlyn et al. (2011) Global Change Biology, 17, 2134-2144.
# **Note** Corrigendum Global Change Biology, 18, 3476.
#
# Parameters:
# -----------
# g1 : float
# slope
# wtfac : float
# water availability scaler [0,1]
# vpd : float
# vapour pressure deficit (Pa)
# Ca : float
# atmospheric co2 [umol mol-1]
# gpp : float
# photosynthesis at the canopy scale (umol m-2 s-1)
#
# Returns:
# --------
# gs : float
# stomatal conductance (mol CO2 m-2 s-1)
g1__ <- g1 * wtfac_root
g0__ <- 0.0 # g0
gs_over_a <- (1.0 + g1__ / sqrt(vpd * PA_2_KPA)) / Ca
gsc <- max(g0__, g0__ + gs_over_a * gpp)
# mol m-2 s-1
return (gsc)
}
canopy_boundary_layer_conduct <- function(canht, wind, press, tair) {
# Canopy boundary layer conductance, ga (from Jones 1992 p 68)
#
#
# Notes:
# ------
# 'Estimates of ga for pine canopies from LAI of 3 to 6 vary from
# 3.5 to 1.1 mol m-2 s-1 (Kelliher et al., 1993 Juang et al., 2007).'
# Drake et al, 2010, 17, pg. 1526.
#
# References:
# ------------
# * Jones 1992, pg. 67-8.
# * Monteith and Unsworth (1990), pg. 248. Note this in the inverted form
# of what is in Monteith (ga = 1 / ra)
# * Allen et al. (1989) pg. 651.
# * Gash et al. (1999) Ag forest met, 94, 149-158.
#
# Parameters:
# -----------
# params : p
# parameters structure
# canht : float
# canopy height (m)
# wind : float
# wind speed (m s-1)
# press : float
# atmospheric pressure (Pa)
# tair : float
# air temperature (deg C)
#
# Returns:
# --------
# ga : float
# canopy boundary layer conductance (mol m-2 s-1)
# z0m roughness length governing momentum transfer [m]
vk <- 0.41
# Convert from mm s-1 to mol m-2 s-1
cmolar <- press / (RGAS * (tair + DEG_TO_KELVIN))
# roughness length for momentum
z0m <- dz0v_dh * canht
# z0h roughness length governing transfer of heat and vapour [m]
# *Heat tranfer typically less efficent than momentum transfer. There is
# a lot of variability in values quoted for the ratio of these two...
# JULES uses 0.1, Campbell and Norman '98 say z0h = z0m / 5. Garratt
# and Hicks, 1973/ Stewart et al '94 say z0h = z0m / 7. Therefore for
# the default I am following Monteith and Unsworth, by setting the
# ratio to be 1, the code below is identical to that on page 249,
# eqn 15.7
z0h <- z0h_z0m * z0m
#s zero plan displacement height [m]
d <- displace_ratio * canht
arg1 <- (vk * vk) * wind
arg2 <- log((canht - d) / z0m)
arg3 <- log((canht - d) / z0h)
ga <- (arg1 / (arg2 * arg3)) * cmolar
return (ga)
}
calc_sat_water_vapour_press <- function(tac) {
# Calculate saturated water vapour pressure (Pa) at
# temperature TAC (Celsius). From Jones 1992 p 110 (note error in
# a - wrong units)
return (613.75 * exp(17.502 * tac / (240.97 + tac)))
}
calc_slope_of_sat_vapour_pressure_curve <- function(tair) {
# Constant slope in Penman-Monteith equation
#
# Parameters:
# -----------
# tavg : float
# average daytime temperature
#
# Returns:
# --------
# slope : float
# slope of saturation vapour pressure curve [Pa K-1]
# Const slope in Penman-Monteith equation (Pa K-1)
arg1 <- calc_sat_water_vapour_press(tair + 0.1)
arg2 <- calc_sat_water_vapour_press(tair)
slope <- (arg1 - arg2) / 0.1
return (slope)
}
calc_pyschrometric_constant <- function(press, lambda) {
# Psychrometric constant ratio of specific heat of moist air at
# a constant pressure to latent heat of vaporisation.
#
# Parameters:
# -----------
# press : float
# air pressure (Pa)
# lambda : float
# latent heat of water vaporization (J mol-1)
#
#
# Returns:
# --------
# gamma : float
# pyschrometric constant [Pa K-1]
return ( CP * MASS_AIR * press / lambda )
}
calc_latent_heat_of_vapourisation <- function(tair) {
# Latent heat of water vapour at air temperature
#
# Returns:
# -----------
# lambda : float
# latent heat of water vaporization [J mol-1]
return ( (H2OLV0 - 2.365E3 * tair) * H2OMW )
}
penman_monteith <- function(press, vpd, rnet, slope, lambda, gamma, gh, gv) {
# Calculates transpiration using the Penman-Monteith
#
# Parameters:
# ----------
# press : float
# atmospheric pressure (Pa)
# vpd : float
# vapour pressure deficit of air (Pa)
# rnet : float
# net radiation (J m-2 s-1)
# slope : float
# slope of VPD/T curve, Pa K-1
# lambda : flot
# latent heat of water at air T, J mol-1
# gamma : float
# psychrometric constant, J mol-1
# gh : float
# boundary layer conductance to heat (free & forced & radiative
# components), mol m-2 s-1
# gv : float
# conductance to water vapour (stomatal & bdry layer components),
# mol m-2 s-1
# transpiration : float
# transpiration (mol H2O m-2 s-1 returned)
# LE : float
# latent heat flux (W m-2 returned)
# omega : float
# decoupling coefficient (unitless returned)
#
# References:
# ------------
# * Medlyn et al. (2007), Tree Physiology, 27, 1687-1699.
if (gv > 0.0) {
arg1 <- slope * rnet + vpd * gh * CP * MASS_AIR
arg2 <- slope + gamma * gh / gv
LE <- arg1 / arg2 # W m-2
transpiration <- LE / lambda # mol H20 m-2 s-1
} else {
transpiration <- 0.0
LE <- 0
}
# Should not be negative - not sure gv>0.0 catches it as g0 = 1E-09?
transpiration <- max(0.0, transpiration)
return (c(gh, gv, transpiration, LE))
}
penman_canopy_wrapper <- function(press, vpd, tair, wind, rnet, ca, gpp) {
# Calculates transpiration at the canopy scale (or big leaf) using the
# Penman-Monteith
#
# Parameters:
# ----------
# parms : structure
# parameters
# state : structure
# state variables
# press : float
# atmospheric pressure (Pa)
# vpd : float
# vapour pressure deficit of air (Pa)
# tair : float
# air temperature (deg C)
# wind : float
# wind speed (m s-1)
# rnet : float
# net radiation (J m-2 s-1)
# ca : float
# ambient CO2 concentration (umol mol-1)
# gpp : float
# gross primary productivity (umol m-2 s-1)
# ga : float
# canopy scale boundary layer conductance (mol m-2 s-1 returned)
# gsv : float
# stomatal conductance to H20 (mol m-2 s-1 returned)