-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Calculate Relative Humidity via Magnus Tetens Equation #2286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
70e0156
0ec0cbf
5eb9d00
ab2de3a
f62bd8e
77025c7
b52f9a9
58b246e
a06871a
caa4417
edd84b1
9c32f6a
63ed5c7
6312f92
410e95f
d94df47
e6b5908
63a9226
459d5a6
05b846f
0ae31e1
337f723
8bc9b86
9651c3b
b860ca5
2bdc1dc
c39c449
b5a6f09
aedc835
4fcb9e3
c956c91
f682815
0bfc6cb
71a165e
25527d6
1eff53f
df33a31
b4802a3
3893692
11d81c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,85 @@ def gueymard94_pw(temp_air, relative_humidity): | |
return pw | ||
|
||
|
||
def rh_from_tdew(temp_air, temp_dew, coeff=(6.112, 17.62, 243.12)): | ||
""" | ||
Calculate relative humidity from dewpoint temperature using the Magnus | ||
equation. | ||
|
||
Parameters | ||
---------- | ||
temp_air : numeric | ||
Air temperature (dry-bulb temperature). [°C] | ||
temp_dew : numeric | ||
Dew-point temperature. [°C] | ||
coeff : tuple, default (6.112, 17.62, 243.12) | ||
Magnus equation coefficients (A, B, C). The default values are those | ||
recommended by the WMO [1]_. | ||
|
||
Returns | ||
------- | ||
numeric | ||
Relative humidity (0.0-100.0). [%] | ||
|
||
References | ||
---------- | ||
.. [1] "Guide to Instruments and Methods of Observation", | ||
World Meteorological Organization, WMO-No. 8, 2023. | ||
https://library.wmo.int/idurl/4/68695 | ||
""" | ||
|
||
# Calculate vapor pressure (e) and saturation vapor pressure (es) | ||
e = coeff[0] * np.exp((coeff[1] * temp_air) / (coeff[2] + temp_air)) | ||
es = coeff[0] * np.exp((coeff[1] * temp_dew) / (coeff[2] + temp_dew)) | ||
|
||
# Calculate relative humidity as percentage | ||
relative_humidity = 100 * (es / e) | ||
|
||
return relative_humidity | ||
|
||
|
||
def tdew_from_rh(temp_air, relative_humidity, coeff=(6.112, 17.62, 243.12)): | ||
""" | ||
Calculate dewpoint temperature using the Magnus equation. | ||
This is a reversal of the calculation in :py:func:`rh_from_tdew`. | ||
|
||
Parameters | ||
---------- | ||
temp_air : numeric | ||
Air temperature (dry-bulb temperature). [°C] | ||
relative_humidity : numeric | ||
Relative humidity (0-100). [%] | ||
coeff: tuple, default (6.112, 17.62, 243.12) | ||
Magnus equation coefficients (A, B, C). The default values are those | ||
recommended by the WMO [1]_. | ||
|
||
Returns | ||
------- | ||
numeric | ||
Dewpoint temperature. [°C] | ||
|
||
References | ||
---------- | ||
.. [1] "Guide to Instruments and Methods of Observation", | ||
World Meteorological Organization, WMO-No. 8, 2023. | ||
https://library.wmo.int/idurl/4/68695 | ||
""" | ||
# Calculate the term inside the log | ||
# From RH = 100 * (es/e), we get es = (RH/100) * e | ||
# Substituting the Magnus equation and solving for dewpoint | ||
|
||
# First calculate ln(es/A) | ||
ln_term = ( | ||
(coeff[1] * temp_air) / (coeff[2] + temp_air) | ||
+ np.log(relative_humidity/100) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like RH zero might throw an error or warning here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a check for zero values or leave the original message in the stack trace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary, RH=0% is practically impossible (source). |
||
) | ||
|
||
# Then solve for dewpoint | ||
dewpoint = coeff[2] * ln_term / (coeff[1] - ln_term) | ||
|
||
return dewpoint | ||
|
||
|
||
first_solar_spectral_correction = deprecated( | ||
since='0.10.0', | ||
alternative='pvlib.spectrum.spectral_factor_firstsolar' | ||
|
Uh oh!
There was an error while loading. Please reload this page.