-
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 24 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,82 @@ def gueymard94_pw(temp_air, relative_humidity): | |||||
| return pw | ||||||
|
|
||||||
|
|
||||||
| def rh_from_tdew(temperature, dewpoint, coeff=(6.112, 17.62, 243.12)): | ||||||
|
||||||
| """ | ||||||
| Calculate relative humidity from dewpoint temperature using the Magnus equation. | ||||||
|
||||||
| Calculate relative humidity from dewpoint temperature using the Magnus equation. | |
| Calculate relative humidity from dew-point temperature using the Magnus equation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(inner grammarian emerges) the term is either "dewpoint" or "dew point": NOAA glossary. The AMS glossary prefers "dewpoint".
I can't find any instances of "dew-point" as a hyphenated adjective, although I understand that's what grammar rules suggest it should be, rather than "dew point".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly I didn't search beyond the WMO document we referenced, so it could be an old-world / new-world thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to use any term that you all prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like EPW and TMY3 files use the hyphen. Most of the pvlib docs use "dew point", with the exception of the Nomenclature page which says "Dewpoint".
I suggest we leave this for a potential package-wide cleanup and not worry about it here.
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Dewpoint temperature in degrees Celsius | |
| Dew-point temperature in degrees Celsius |
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,143 @@ def test_gueymard94_pw(): | |
| assert_allclose(pws, expected, atol=0.01) | ||
|
|
||
|
|
||
| # Unit tests | ||
| def test_rh_from_tdew(): | ||
|
|
||
| # dewpoint temp calculated with who and aekr coefficients | ||
|
||
| dewpoint = pd.Series([ | ||
| 15.0, 20.0, 25.0, 12.0, 8.0 | ||
| ]) | ||
|
|
||
| # relative humidity calculated with who and aekr coefficients | ||
| relative_humidity_who = pd.Series([ | ||
| 72.95185312581116, 73.81500029087906, 74.6401272083123, | ||
| 82.27063889868842, 87.39018119185337 | ||
| ]) | ||
| relative_humidity_aekr = pd.Series([ | ||
| 72.93876680928582, 73.8025121880607, 74.62820502423823, | ||
| 82.26135295757305, 87.38323744820416 | ||
| ]) | ||
|
|
||
| temperature_ambient = pd.Series([20.0, 25.0, 30.0, 15.0, 10.0]) | ||
|
|
||
| # Calculate relative humidity using pandas series as input | ||
| rh_series = atmosphere.rh_from_tdew( | ||
| temperature=temperature_ambient, | ||
| dewpoint=dewpoint | ||
| ) | ||
|
|
||
| # Calulate relative humidity using pandas series as input | ||
| # with AEKR coefficients | ||
| rh_series_aekr = atmosphere.rh_from_tdew( | ||
| temperature=temperature_ambient, | ||
| dewpoint=dewpoint, | ||
| coeff=(6.1094, 17.625, 243.04) | ||
| ) | ||
|
|
||
| # Calculate relative humidity using array as input | ||
| rh_array = atmosphere.rh_from_tdew( | ||
| temperature=temperature_ambient.to_numpy(), | ||
| dewpoint=dewpoint.to_numpy() | ||
| ) | ||
|
|
||
| # Calculate relative humidity using float as input | ||
| rh_float = atmosphere.rh_from_tdew( | ||
| temperature=temperature_ambient.iloc[0], | ||
| dewpoint=dewpoint.iloc[0] | ||
| ) | ||
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # test | ||
| pd.testing.assert_series_equal( | ||
| rh_series, | ||
| relative_humidity_who, | ||
| check_names=False | ||
| ) | ||
kurt-rhee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| pd.testing.assert_series_equal( | ||
| rh_series_aekr, | ||
| relative_humidity_aekr, | ||
| check_names=False | ||
| ) | ||
|
|
||
| np.testing.assert_allclose( | ||
| rh_array, | ||
| relative_humidity_who.to_numpy(), | ||
| atol=0.001 | ||
kandersolar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| assert np.isclose( | ||
| rh_float, | ||
| relative_humidity_who.iloc[0] | ||
| ) | ||
|
|
||
|
|
||
| # Unit tests | ||
| def test_tdew_from_rh(): | ||
|
|
||
| # dewpoint temp calculated with who and aekr coefficients | ||
| dewpoint = pd.Series([ | ||
| 15.0, 20.0, 25.0, 12.0, 8.0 | ||
| ]) | ||
|
|
||
| # relative humidity calculated with who and aekr coefficients | ||
| relative_humidity_who = pd.Series([ | ||
| 72.95185312581116, 73.81500029087906, 74.6401272083123, | ||
| 82.27063889868842, 87.39018119185337 | ||
| ]) | ||
| relative_humidity_aekr = pd.Series([ | ||
| 72.93876680928582, 73.8025121880607, 74.62820502423823, | ||
| 82.26135295757305, 87.38323744820416 | ||
| ]) | ||
|
|
||
| temperature_ambient = pd.Series([20.0, 25.0, 30.0, 15.0, 10.0]) | ||
|
|
||
| # test as series | ||
| dewpoint_series = atmosphere.tdew_from_rh( | ||
| temperature=temperature_ambient, | ||
| relative_humidity=relative_humidity_who | ||
| ) | ||
|
|
||
| # test as series with AEKR coefficients | ||
| dewpoint_series_aekr = atmosphere.tdew_from_rh( | ||
| temperature=temperature_ambient, | ||
| relative_humidity=relative_humidity_aekr, | ||
| coeff=(6.1094, 17.625, 243.04) | ||
| ) | ||
|
|
||
| # test as numpy array | ||
| dewpoint_array = atmosphere.tdew_from_rh( | ||
| temperature=temperature_ambient.to_numpy(), | ||
| relative_humidity=relative_humidity_who.to_numpy() | ||
| ) | ||
|
|
||
| # test as float | ||
| dewpoint_float = atmosphere.tdew_from_rh( | ||
| temperature=temperature_ambient.iloc[0], | ||
| relative_humidity=relative_humidity_who.iloc[0] | ||
| ) | ||
|
|
||
| # test | ||
| pd.testing.assert_series_equal( | ||
| dewpoint_series, dewpoint, check_names=False | ||
| ) | ||
|
|
||
| pd.testing.assert_series_equal( | ||
| dewpoint_series_aekr, dewpoint, | ||
| check_names=False | ||
| ) | ||
|
|
||
| np.testing.assert_allclose( | ||
| dewpoint_array, | ||
| dewpoint.to_numpy(), | ||
| ) | ||
|
|
||
| assert np.isclose( | ||
| dewpoint_float, | ||
| dewpoint.iloc[0] | ||
| ) | ||
|
|
||
|
|
||
| def test_first_solar_spectral_correction_deprecated(): | ||
| with pytest.warns(pvlibDeprecationWarning, | ||
| match='Use pvlib.spectrum.spectral_factor_firstsolar'): | ||
|
|
||
kurt-rhee marked this conversation as resolved.
Show resolved
Hide resolved
kurt-rhee marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.