-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeta.py
73 lines (53 loc) · 1.37 KB
/
theta.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
61
62
63
64
65
66
67
68
69
70
71
72
73
"""This is the docstring for the theta.py module."""
from constants import constants
def theta(*args):
"""
theta(*args)
Computes potential temperature.
Allows for either T,p or T,p,wv as inputs.
Parameters
- - - - - -
T : float
Temperature (K).
p : float
Pressure (Pa).
Returns
- - - -
thetaOut : float
Potential temperature (K).
Other Parameters
- - - - - - - - -
wv : float, optional
Vapour mixing ratio (kg,kg). Can be appended as an argument
in order to increase precision of returned 'theta' value.
Raises
- - - -
NameError
If an incorrect number of arguments is provided.
References
- - - - - -
Emanuel p. 111 4.2.11
Examples
- - - - -
>>> theta(300., 8.e4) # Only 'T' and 'p' are input.
319.72798180767984
>>> theta(300., 8.e4, 0.001) # 'T', 'p', and 'wv' all input.
319.72309475657323
"""
c = constants();
if len(args) == 2:
wv = 0;
elif len(args) == 3:
wv = args[2];
else:
raise NameError('need either T,p or T,p,wv');
T = args[0];
p = args[1];
power = c.Rd / c.cpd * (1. - 0.24 * wv);
thetaOut = T * (c.p0 / p) ** power;
return thetaOut
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()