气象计算函数


作者Lou Xiao创建时间2023-10-27 16:58:11更新时间2023-10-27 16:58:11

1. 比湿(relative humidity) To 相对湿度(specific humidity)

参考:
1. How do I convert specific humidity to relative humidity?
2. METPY

1.1 精确计算

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 import numpy as np
2 def relative_humidity_from_specific_humidity(pressure, temperature, specific_humidity):
3 # @param pressure: atmosphere pressure, units: Pa
4 # @param temperature: atmosphere temperature, units: K
5 # @param specific_humidity: specific humidity, units: 1
6 # @return: relative_humidity, units: %
7 es = 611.2 * np.exp((17.67 * (temperature - 273.15)) / (temperature - 29.65))
8 ws = 0.6219569100577033 * es / (pressure - es)
9 wq = specific_humidity / (1 - specific_humidity)
10 rh = 100 * wq / ws
11 return rh
12 print("relative_humidity:", relative_humidity_from_specific_humidity(
13 1013.25 * 100, # as Pa
14 30 + 273.15, # as K
15 18 / 1000,
16 ))
17 # 67.38936293846538
18
19 # 验证
20 from metpy.calc import relative_humidity_from_specific_humidity as metpy_relative_humidity_from_specific_humidity
21 from metpy.units import units
22 print("relative_humidity:", metpy_relative_humidity_from_specific_humidity(
23 1013.25 * units.hPa,
24 30 * units.degC,
25 18 / 1000
26 ).to('percent'))
27 # 67.3893629384654

1.2 近似计算

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 import numpy as np
2 def relative_humidity_from_specific_humidity(pressure, temperature, specific_humidity):
3 # @param pressure: atmosphere pressure, units: Pa
4 # @param temperature: atmosphere temperature, units: K
5 # @param specific_humidity: specific humidity, units: 1
6 # @return: relative_humidity, units: %
7 es = 611.2 * np.exp((17.67 * (temperature - 273.15)) / (temperature - 29.65))
8 ws = 0.622 * es / pressure
9 wq = specific_humidity
10 rh = 100 * wq / ws
11 return rh
12
13 print("relative_humidity:", relative_humidity_from_specific_humidity(
14 1013.25 * 100, # as Pa
15 30 + 273.15, # as K
16 18 / 1000,
17 ))
18 # 69.06566061892872
19 # or
20 import numpy as np
21 def relative_humidity_from_specific_humidity(pressure, temperature, specific_humidity):
22 # @param pressure: atmosphere pressure, units: Pa
23 # @param temperature: atmosphere temperature, units: K
24 # @param specific_humidity: specific humidity, units: 1
25 # @return: relative_humidity, units: %
26 rh = 0.263 * pressure * specific_humidity / np.exp((17.67 * (temperature - 273.15)) / (temperature - 29.65))
27 return rh
28
29 print("relative_humidity:", relative_humidity_from_specific_humidity(
30 1013.25 * 100, # as Pa
31 30 + 273.15, # as K
32 18 / 1000,
33 ))
34 # 69.05444656574537
文章目录