-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCLfind.py
78 lines (61 loc) · 1.72 KB
/
LCLfind.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
74
75
76
77
78
"""This is the docstring for the LCLfind.py module."""
import numpy as np
from constants import constants
from esat import esat
def LCLfind(Td, T, p):
"""
LCLfind(Td, T, p)
Finds the temperature and pressure at the lifting condensation
level (LCL) of an air parcel.
Parameters
- - - - - -
Td : float
Dewpoint temperature (K).
T : float
Temperature (K).
p : float
Pressure (Pa)
Returns
- - - -
Tlcl : float
Temperature at the LCL (K).
plcl : float
Pressure at the LCL (Pa).
Raises
- - - -
NameError
If the air is saturated at a given Td and T (ie. Td >= T)
Examples
- - - - -
>>> [Tlcl, plcl] = LCLfind(280., 300., 8.e4)
>>> print [Tlcl, plcl]
[275.76250387361404, 59518.928699453245]
>>> LCLfind(300., 280., 8.e4)
Traceback (most recent call last):
...
NameError: parcel is saturated at this pressure
References
- - - - - -
Emanuel 4.6.24 p. 130 and 4.6.22 p. 129
"""
c = constants();
hit = Td >= T;
if hit is True:
raise NameError('parcel is saturated at this pressure');
e = esat(Td);
ehPa = e * 0.01; #Bolton's formula requires hPa.
# This is is an empircal fit from for LCL temp from Bolton, 1980 MWR.
Tlcl = (2840. / (3.5 * np.log(T) - np.log(ehPa) - 4.805)) + 55.;
r = c.eps * e / (p - e);
#disp(sprintf('r=%0.5g',r'))
cp = c.cpd + r * c.cpv;
logplcl = np.log(p) + cp / (c.Rd * (1 + r / c.eps)) * \
np.log(Tlcl / T);
plcl = np.exp(logplcl);
#disp(sprintf('plcl=%0.5g',plcl))
return Tlcl, plcl
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()