Skip to content

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

Merged
merged 40 commits into from
Dec 12, 2024

Conversation

kurt-rhee
Copy link
Contributor

@kurt-rhee kurt-rhee commented Oct 30, 2024

  • Closes implement Tdew to RH conversions #1744
  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • [ x ] New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

Reasoning

  • There are some occasions where dew point temperature is available, but relative humidity is not.
  • Relative humidity can be converted to precipitable water in pvlib via guemard94.
  • Precipitable water is used by first solar to calculate spectral correction factors.
  • This function would allow a user with dew point temperature to convert it to relative humidity.

Caveats

Caveat 1

  • In the issue thread implement Tdew to RH conversions #1744 there is some controversy about the simpleness of this approach. Some users would prefer a more well known solution.
  • I would argue that because this approach was used in the creation of the First Solar spectral correction function, that it has historical significance and should therefore be included.
  • If any user should desire, they could add an alternative function and then create a controller function which allows the user to choose different relative humidity calculation methods, which is a pattern than exists already inside pvlib.

Caveat 2

  • I placed these functions inside of spectrum, but I could also see them living inside of pvlib.atmosphere.py where the gueymard94 function exists. I'd like the maintainers opinion before proceeding to update the docs and what's new file.

@adriesse
Copy link
Member

@kurt-rhee Perhaps it would be better to continue the discussion in #1744 rather than start a new thread here.

@kurt-rhee
Copy link
Contributor Author

@adriesse good idea, I've copied the comment above to the thread in question

@cwhanse cwhanse added this to the v0.11.2 milestone Nov 11, 2024
Co-authored-by: Anton Driesse <[email protected]>
@kurt-rhee
Copy link
Contributor Author

@adriesse agreed, anecdotal and unnecessary, it has been removed.

I have left the formatting of functions outside of the tdew and rh
conversion functions.  I can format them to satisfy flake8 linter if
that is desired by maintainers.

Just let me know how I can help.
@kandersolar kandersolar changed the title Calculate Relative Humidity via Magnus Tetens Equation with AEKR coefficients Calculate Relative Humidity via Magnus Tetens Equation Nov 25, 2024
Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments. A what's new entry will be needed before too long!

kurt-rhee and others added 6 commits November 25, 2024 12:53
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments, and the old magnus_tetens.py file still needs to be removed.

Otherwise I think we just need to tick off the remaining checklist items at the top of this thread: list the new functions in the reference docs, and create a what's new entry!

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more nitpicks, otherwise LGTM!

# Unit tests
def test_rh_from_tdew():

# dewpoint temp calculated with who and aekr coefficients
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

several comments and variables in these two test functions say "who" instead of "wmo" :)

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Calculate relative humidity from dewpoint temperature using the Magnus equation.
Calculate relative humidity from dew-point temperature using the Magnus equation.

Copy link
Member

@cwhanse cwhanse Dec 6, 2024

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".

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

# First calculate ln(es/A)
ln_term = (
(coeff[1] * temperature) / (coeff[2] + temperature)
+ np.log(relative_humidity/100)
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Returns
-------
numeric
Dewpoint temperature in degrees Celsius
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dewpoint temperature in degrees Celsius
Dew-point temperature in degrees Celsius

kurt-rhee and others added 5 commits December 6, 2024 16:01
Copy link
Member

@AdamRJensen AdamRJensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to add a test that demonstrates that you converting to rh and then back to tdew gives the same answer? If possible it would be a nice simple test.

AdamRJensen and others added 7 commits December 9, 2024 20:57
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Adam R. Jensen <[email protected]>
Co-authored-by: Adam R. Jensen <[email protected]>
Co-authored-by: Adam R. Jensen <[email protected]>
Co-authored-by: Adam R. Jensen <[email protected]>
Added a new test to show that you can calculate relative humidity from
dewpoint and then calculate dewpoint from relative humidity and it will
be the same as the original dewpoint values
@kurt-rhee
Copy link
Contributor Author

Does it make sense to add a test that demonstrates that you converting to rh and then back to tdew gives the same answer? If possible it would be a nice simple test.

Just added this test in the latest commit

@@ -337,6 +337,86 @@ def gueymard94_pw(temp_air, relative_humidity):
return pw


def rh_from_tdew(temperature, dewpoint, coeff=(6.112, 17.62, 243.12)):
Copy link
Member

@kandersolar kandersolar Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed earlier but forgot to comment: we should rename this parameter to temp_dew, the name used by other pvlib models and iotools functions. I'll push a commit for that to give @kurt-rhee a break from this PR :P

edit: and same for temp_air of course

@kandersolar
Copy link
Member

I think it's time to merge this.

Thanks @kurt-rhee for the PR, @adriesse for putting us on the right course, and everyone else that contributed to the discussion!

@kandersolar kandersolar merged commit cb37129 into pvlib:main Dec 12, 2024
26 checks passed
@kurt-rhee kurt-rhee deleted the relative-humidity branch February 11, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement Tdew to RH conversions
6 participants