Newer
Older
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
# -*- coding: utf-8 -*-
#
# This file is for use with essm.
# Copyright (C) 2021 ETH Zurich, Swiss Data Science Center.
#
# essm is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# essm is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with essm; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
"""Equations defined in notebooks/theory/theory.ipynb and dependencies."""
from __future__ import division
from __main__ import (
T0, VPD, Delta, E, G, L, Mw, Pvs, R, Rn, S, S_mvg, T, alpha, alpha_PT, c1,
c_p, e_a, e_s, g_a, g_s, gamma, h, m, n, r_a, r_s, rho_a, theta, theta_1,
theta_2, theta_3, theta_4, theta_res, theta_sat
)
from essm import Eq
from essm.equations import Equation
from sympy import Abs, Eq, Piecewise, exp, log
class eq_m_n(Equation):
"""Relation between n and m parameters in MVG model"""
expr = Eq(m, 1 - 1 / n)
class eq_MVG_neg_case(Equation):
"""Mualem-Van Genuchtem model if h < 0"""
expr = Eq(
theta,
theta_res + ((-theta_res + theta_sat) / (Abs(alpha * h) ** n + 1)) ** m
)
class eq_MVG(Equation):
"""Complet Van Genuchtem model"""
expr = Eq(
theta,
Piecewise((theta_sat, h > 0), (
theta_res + ((-theta_res + theta_sat) /
(Abs(alpha * h) ** n + 1)) ** m, True
))
)
class eq_sat_degree(Equation):
"""Relative Saturation degree equation"""
expr = Eq(S_mvg, (theta - theta_res) / (-theta_res + theta_sat))
class eq_MVG_h(Equation):
"""Mualem Van Genuchten model, h as function of theta"""
expr = Eq(h, (-1 + S_mvg ** (-1 / m)) ** (1 / n) / alpha)
class eq_h_FC(Equation):
"""Compute the field capacity out of the soil properties"""
expr = Eq(h, ((n - 1) / n) ** ((1 - 2 * n) / n) / alpha)
class eq_theta_4_3(Equation):
"""Equation valide between theta_4 and theta_3"""
expr = Eq(
theta, theta / (theta_3 - theta_4) + theta_4 / (-theta_3 + theta_4)
)
class eq_theta_2_1(Equation):
"""Equation valide between theta_2 and theta_1"""
expr = Eq(
theta, theta / (-theta_1 + theta_2) + theta_1 / (theta_1 - theta_2)
)
class eq_water_stress_simple(Equation):
"""Simple water stress factor function (h_3 independant of T_0)"""
expr = Eq(
S,
Piecewise((0, theta < theta_4), (
theta / (theta_3 - theta_4) + theta_4 /
(-theta_3 + theta_4), theta < theta_3
), (1, theta < theta_2), (
theta / (-theta_1 + theta_2) + theta_1 /
(theta_1 - theta_2), theta < theta_1
), (0, True))
)
class eq_Pvs_T(Equation):
"""Saturation vapour pressure, Slide 8"""
expr = Eq(Pvs, c1 * exp(L * Mw * (1 / T0 - 1 / T) / R))
class eq_Delta(Equation):
"""Slope of d.Pvas(T)/d.T """
expr = Eq(
Delta,
L * Mw * c1 * exp(L * Mw * (1 / T0 - 1 / T) / R) / (R * T ** 2)
)
class eq_PT(Equation):
"""Priestley-Taylor equation for evaporation flux"""
expr = Eq(E, Delta * alpha_PT * (-G + Rn) / (L * (Delta + gamma)))
class eq_PM(Equation):
"""Penman-Monteith equation"""
expr = Eq(
E, (Delta * (-G + Rn) + c_p * rho_a * (-e_a + e_s) / r_a) /
(L * (Delta + gamma * (1 + r_s / r_a)))
)
class eq_PM_VPD(Equation):
"""Penman-Monteith equation using VPD"""
expr = Eq(
E, (Delta * (-G + Rn) + VPD * c_p * rho_a / r_a) /
(L * (Delta + gamma * (1 + r_s / r_a)))
)
class eq_PM_g(Equation):
"""Penman-Monteith equation using stomatal conductance"""
expr = Eq(
E, (Delta * (-G + Rn) + VPD * c_p * g_a * rho_a) /
(L * (Delta + gamma * (g_a / g_s + 1)))
)
class eq_PM_inv(Equation):
"""Inverse PM equation for inverse modelling of surface resistance"""
expr = Eq(
r_s, (
-Delta * E * L * r_a - Delta * G * r_a + Delta * Rn * r_a -
E * L * gamma * r_a + VPD * c_p * rho_a
) / (E * L * gamma)
)
__all__ = (
'eq_m_n',
'eq_MVG_neg_case',
'eq_MVG',
'eq_sat_degree',
'eq_MVG_h',
'eq_h_FC',
'eq_theta_4_3',
'eq_theta_2_1',
'eq_water_stress_simple',
'eq_Pvs_T',
'eq_Delta',
'eq_PT',
'eq_PM',
'eq_PM_VPD',
'eq_PM_g',
'eq_PM_inv',
)