-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconstants.py
82 lines (73 loc) · 2.21 KB
/
constants.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
79
80
81
82
g = 9.81 #[m/s2 ]
a0 = 6376.0e3 # [m]
Omega = 7.292e-5 #[1/s]
R = 8.314 #[J/mol/K]
Rd = 287.04 # [J/kg/K]
Rv = 461.50 # [J/kg/K]
Na = 6.022e23 # [1/mol]
kappa = 2./7. # []
cp = Rd/kappa # [J/kg/K]
sigma = 5.6734e-8 # [W/m2/K4]
ES0 = 610.78 # [Pa]
HLV = 2.5e6 # [J/kg]
Tfreeze = 273.16 # [K]
p0 = 1e3 # [hPa]
p0_Pa = 1e5 # [Pa]
cmaps = {
'slp' : 'BrBG_r',
'precip' : 'PuOr',
't' : 'RdBu_r',
'u' : 'RdBu_r',
'olr' : 'PiYG',
'cldfrac': 'binary_r',
'ep' : 'PRGn_r',
'v' : 'PiYG',
'pv' : 'RdYlGn_r',
}
def f(lat):
''' Compute Coriolis parameter f = 2*Omega*sin(lat)
INPUTS:
lat: latitude in degrees. Either numpy or xarray array
OUTPUTS:
f: Coriolis parameter. Either numpy or xarray array
'''
from numpy import sin,deg2rad
return 2*Omega*sin(deg2rad(lat))
def beta(lat,u=None):
''' Compute meridional derivative of Coriolis parameter, i.e. beta = 2*Omega*cos(lat)/a0.
If u is not None, returns beta* = 2*Omega*cos(lat)/a0 - u_yy
If u is not None, it has to be an xarray.DataArray.
INPUTS:
lat: latitude in degrees. Either numpy or xarray array
u: None or meridonal wind as xarray dataarray. If
OUTPUTS:
beta: beta parameter. Either numpy or xarray array depending on input.
'''
from numpy import cos,deg2rad
beta = 2*Omega*cos(deg2rad(lat))/a0
if u is None:
return beta
else:
lats = lat.name
# uyy = d_phi(1/acosphi*d_phi(u*cosphi))/a0
uy = deg2rad((u*coslat(lat))).differentiate(lats,edge_order=2)
uyy = deg2rad((uy/coslat(lat)/a0).differentiate(lats,edge_order=2))/a0
return beta - uyy
def kstar(u,lat,c=0):
'''K* = \cos\theta\sqrt{\beta*/(u-c)}
\beta* = \beta - u_yy
'''
from numpy import sqrt
beta_star = beta(lat,u)
k_star = coslat(lat)*sqrt(beta_star/(u-c))
return k_star
def coslat(lat):
'''Compute cosine of latitude from degrees.
'''
from numpy import cos,deg2rad
return cos(deg2rad(lat))
def sinlat(lat):
'''Compute sine of latitude from degrees.
'''
from numpy import sin,deg2rad
return sin(deg2rad(lat))