-
Notifications
You must be signed in to change notification settings - Fork 1
/
thetal.py
61 lines (46 loc) · 1.19 KB
/
thetal.py
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
import numpy as np
from L import L
from constants import constants
def thetal(T,p,wv,wl):
"""
thetal(T,p,wv,wl)
Calculates the liquid water potential temperature of a parcel.
Parameters
- - - - - -
T : float
Temperature (K).
p : float
Pressure (Pa)
wv : float
Vapour mixing ratio (kg/kg).
wl : float
Liquid water potential temperature (kg/kg).
Returns
- - - -
thetalOut : float
Liquid water potential temperature (K).
References
- - - - - -
Emanuel 4.5.15 p. 121
Examples
- - - - -
>>> thetal(300., 8.e4, 0.03, 0.01)
298.21374486200278
"""
c = constants();
Lval = L(T);
wt = wv + wl;
chi = (c.Rd + wt * c.Rv) / (c.cpd + wt * c.cpv);
gamma = wt * c.Rv / (c.cpd + wt * c.cpv);
thetaVal = T * (c.p0 / p) ** chi;
term1 = (1 - wl / (1. + wt)) * (1 - wl / (c.eps + wt)) ** (chi-1)
term2 = (1 - wl / wt) ** (-1. * gamma);
cp = c.cpd + wt * c.cpv;
thetalOut = thetaVal * term1 * term2 \
* np.exp(-1. * Lval * wl/(cp*T));
return thetalOut
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()