-
Notifications
You must be signed in to change notification settings - Fork 1
/
omega2w.py
executable file
·58 lines (45 loc) · 1.55 KB
/
omega2w.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
import numpy as np
import constants
import sys
def omega2w(omega,temp,pressure,**kwargs):
'''
This function converts omega (pressure velocity) to vertical velocity (cartesian) assuming hydrostatic balance.
INPUTS
------
omega : np.ndarray
array of pressure velocities (arbitrary dimension) in Pa/s
temp : np.ndarray
array of temperatures (arbitrary dimension) in K
pressure : np.ndarray
array of pressure values (arbitrary dimension) in Pa
OUTPUTS
-------
w : np.ndarray
array (same size as the input arrays) of vertical velocities (m/s)
KWARGS
------
q : np.ndarray
array of specific humidities (kg/kg), if given, will use to calculate virtual temp
NOTES
-----
- All arrays for positional arguments must be of the same shape, otherwise the function will quit
- If q keyword arg is passed, virtual temp will be used instead of temp passed
'''
#Process kwargs
known_kwargs=["q"]
kwargs = {k:kwargs.pop(k) for k,v in list(kwargs.items()) if k in known_kwargs}
#Make sure shapes match
shapes = [ np.shape(omega), np.shape(temp), np.shape(pressure) ]
allsame = all(elem == shapes[0] for elem in shapes)
if not allsame:
print("omega2w: Not all passed arguments have same shape, exiting...")
sys.exit()
#Establish constants
g = constants.g
R = constants.R
#See if q is kwargs, if so calculate virutal temp
if "q" in kwargs.keys():
q = kwargs['q']
temp = temp*(1+0.608*q)
w = -R*temp*omega/(pressure*g)
return w