-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteo_utilities.py
executable file
·66 lines (51 loc) · 1.64 KB
/
meteo_utilities.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
# -*- coding: utf-8 -*-
"""
General meteorological utility functions
"""
import numpy as np
import sys
def rrmixv1(p,T,humv,kindhum):
"""
computes mixing ratio in (g/g)
Input: rrmixv1(p,T,humv,kindhum)
p ... pressure in [hPa]
T ... temperature [K]
humv ... humidity variable; one of: dew point [K]
relative humidity [0-1]
kindhum . kind of humidity variable: 1 = dew point [K]
2 = relative humidity [0-1]
Output: mixv1
"""
#Define local constant
eps= 0.62198
if kindhum == 1: # dew point is the input
esat = eswat1(humv)
mixv1 = eps*esat/(p - esat)
elif kindhum == 2: # relative humidity is the input
esat = eswat1(T)
if kindhum == 1 or kindhum == 2:
mixv1=np.where(esat >= 0.616*p,0.,eps*humv*esat/(p - humv*esat))
else:
sys.exit("kindhum needs to be 1 or 2")
return mixv1
def eswat1(T):
"""
Saturation vapor pressure over water, Goff-Gratch formulation
(based on exact integration of Clausius-Clapeyron equation)
Input: T ... temperature [K]
Output: mixv1
"""
#Define local constants
C1=7.90298
C2=5.02808
C3=1.3816e-7
C4=11.344
C5=8.1328e-3
C6=3.49149
RMIXV = 373.16 / T
ES = - C1*( RMIXV - 1) + C2*np.log10( RMIXV ) - \
C3*( 10**( C4*(1 - 1/RMIXV)) - 1 ) + \
C5*( 10**( - C6*(RMIXV - 1)) - 1 )
eswat = 1013.246 * 10**ES
return eswat
# END OF METEO_UTILITIES.PY