437adc78851881b1ce9d51308c8803be1e5b493b
2 # Desc: Humidity conversion functions from EVA-2020-02-2
3 # Ref/Attrib: https://gitlab.com/baltakatei/ninfacyzga-01
5 def rel_to_abs(T
,P
,RH
):
6 """Returns absolute humidity given relative humidity.
11 Absolute temperature in units Kelvin (K).
13 Total pressure in units Pascals (Pa).
15 Relative humidity in units percent (%).
19 absolute_humidity : float
20 Absolute humidity in units [kg water vapor / kg dry air].
24 1. Sonntag, D. "Advancements in the field of hygrometry". 1994. https://doi.org/10.1127/metz/3/1994/51
25 2. Green, D. "Perry's Chemical Engineers' Handbook" (8th Edition). Page "12-4". McGraw-Hill Professional Publishing. 2007.
28 Author: Steven Baltakatei Sandoval
40 # print('DEBUG:Input Temperature (K) :' + str(T));
41 # print('DEBUG:Input Pressure (Pa) :' + str(P));
42 # print('DEBUG:Input Rel. Humidity (%) :' + str(RH));
44 # Set constants and initial conversions
45 epsilon
= 0.62198 # (molar mass of water vapor) / (molar mass of dry air)
46 t
= T
- 273.15; # Celsius from Kelvin
47 P_hpa
= P
/ 100; # hectoPascals (hPa) from Pascals (Pa)
49 # Calculate e_w(T), saturation vapor pressure of water in a pure phase, in Pascals
50 ln_e_w
= -6096*T
**-1 + 21.2409642 - 2.711193*10**-2*T
+ 1.673952*10**-5*T
**2 + 2.433502*math
.log(T
); # Sonntag-1994 eq 7; e_w in Pascals
51 e_w
= math
.exp(ln_e_w
);
52 e_w_hpa
= e_w
/ 100; # also save e_w in hectoPascals (hPa)
53 # print('DEBUG:ln_e_w:' + str(ln_e_w)); # debug
54 # print('DEBUG:e_w:' + str(e_w)); # debug
56 # Calculate f_w(P,T), enhancement factor for water
57 f_w
= 1 + (10**-4*e_w_hpa
)/(273 + t
)*(((38 + 173*math
.exp(-t
/43))*(1 - (e_w_hpa
/ P_hpa
))) + ((6.39 + 4.28*math
.exp(-t
/ 107))*((P_hpa
/ e_w_hpa
) - 1))); # Sonntag-1994 eq 22.
58 # print('DEBUG:f_w:' + str(f_w)); # debug
60 # Calculate e_prime_w(P,T), saturation vapor pressure of water in air-water mixture, in Pascals
61 e_prime_w
= f_w
* e_w
; # Sonntag-1994 eq 18
62 # print('DEBUG:e_prime_w:' + str(e_prime_w)); # debug
64 # Calculate e_prime, vapor pressure of water in air, in Pascals
65 e_prime
= (RH
/ 100) * e_prime_w
;
66 # print('DEBUG:e_prime:' + str(e_prime)); # debug
68 # Calculate r, the absolute humidity, in [kg water vapor / kg dry air]
69 r
= (epsilon
* e_prime
) / (P
- e_prime
);
70 # print('DEBUG:r:' + str(r)); # debug
74 def rel_to_dpt(T
,P
,RH
):
75 """Returns dew point temperature given relative humidity.
80 Absolute temperature in units Kelvin (K).
82 Total pressure in units Pascals (Pa).
84 Relative humidity in units percent (%).
89 Dew point temperature in units Kelvin (K).
93 1. Sonntag, D. "Advancements in the field of hygrometry". 1994. https://doi.org/10.1127/metz/3/1994/51
94 2. Green, D. "Perry's Chemical Engineers' Handbook" (8th Edition). Page "12-4". McGraw-Hill Professional Publishing. 2007.
97 Author: Steven Baltakatei Sandoval
109 # print('DEBUG:Input Temperature (K) :' + str(T));
110 # print('DEBUG:Input Pressure (Pa) :' + str(P));
111 # print('DEBUG:Input Rel. Humidity (%) :' + str(RH));
113 # Set constants and initial conversions
114 epsilon
= 0.62198 # (molar mass of water vapor) / (molar mass of dry air)
115 t
= T
- 273.15; # Celsius from Kelvin
116 P_hpa
= P
/ 100; # hectoPascals (hPa) from Pascals (Pa)
118 # Calculate e_w(T), saturation vapor pressure of water in a pure phase, in Pascals
119 ln_e_w
= -6096*T
**-1 + 21.2409642 - 2.711193*10**-2*T
+ 1.673952*10**-5*T
**2 + 2.433502*math
.log(T
); # Sonntag-1994 eq 7; e_w in Pascals
120 e_w
= math
.exp(ln_e_w
);
121 e_w_hpa
= e_w
/ 100; # also save e_w in hectoPascals (hPa)
122 # print('DEBUG:ln_e_w:' + str(ln_e_w)); # debug
123 # print('DEBUG:e_w:' + str(e_w)); # debug
125 # Calculate f_w(P,T), enhancement factor for water
126 f_w
= 1 + (10**-4*e_w_hpa
)/(273 + t
)*(((38 + 173*math
.exp(-t
/43))*(1 - (e_w_hpa
/ P_hpa
))) + ((6.39 + 4.28*math
.exp(-t
/ 107))*((P_hpa
/ e_w_hpa
) - 1))); # Sonntag-1994 eq 22.
127 # print('DEBUG:f_w:' + str(f_w)); # debug
129 # Calculate e_prime_w(P,T), saturation vapor pressure of water in air-water mixture, in Pascals
130 e_prime_w
= f_w
* e_w
; # Sonntag-1994 eq 18
131 # print('DEBUG:e_prime_w:' + str(e_prime_w)); # debug
133 # Calculate e_prime, vapor pressure of water in air, in Pascals
134 e_prime
= (RH
/ 100) * e_prime_w
;
135 # print('DEBUG:e_prime:' + str(e_prime)); # debug
137 n
= 0; repeat_flag
= True;
138 while repeat_flag
== True:
139 # print('DEBUG:n:' + str(n)); # debug
141 # Calculate f_w_td, the enhancement factor for water at dew point temperature.
143 f
= 1.0016 + 3.15*10**-6*P_hpa
- (0.074 / P_hpa
); # Sonntag-1994 eq 24
144 f_w_td
= f
; # initial approximation
146 t_d_prev
= float(t_d
); # save previous t_d value for later comparison
147 f_w_td
= 1 + (10**-4*e_w_hpa
)/(273 + t_d
)*(((38 + 173*math
.exp(-t_d
/43))*(1 - (e_w_hpa
/ P_hpa
))) + ((6.39 + 4.28*math
.exp(-t_d
/ 107))*((P_hpa
/ e_w_hpa
) - 1))); # Sonntag-1994 eq 22.
148 # print('DEBUG:f_w_td:' + str(f_w_td)); # debug
150 # Calculate e, the vapor pressure of water in the pure phase, in Pascals
151 e
= (e_prime
/ f_w_td
); # Sonntag-1994 eq 9 and 20
152 # print('DEBUG:e:' + str(e)); # debug
154 # Calculate y, an intermediate dew point calculation variable
155 y
= math
.log(e
/ 611.213);
156 # print('DEBUG:y:' + str(y)); # debug
158 # Calculate t_d, the dew point temperature in degrees Celsius
159 t_d
= 13.715*y
+ 8.4262*10**-1*y
**2 + 1.9048*10**-2*y
**3 + 7.8158*10**-3*y
**4;# Sonntag-1994 eq 10
160 # print('DEBUG:t_d:' + str(t_d)); # debug
167 t_d_diff
= math
.fabs(t_d
- t_d_prev
);
168 # print('DEBUG:t_d :' + str(t_d)); # debug
169 # print('DEBUG:t_d_prev:' + str(t_d_prev)); # debug
170 # print('DEBUG:t_d_diff:' + str(t_d_diff)); # debug
176 # Calculate T_d, the dew point temperature in Kelvin
178 # print('DEBUG:T_d:' + str(T_d)); # debug
181 return T_d
; # good enough
183 # update loop counter