Skip to content
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

Calculate Relative Humidity via Magnus Tetens Equation #2286

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

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

pvlib/spectrum/magnus_tetens.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I agree that atmosphere.py is a better home for this functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved in latest commit

Copy link
Member

Choose a reason for hiding this comment

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

Still need to remove this magnus_tetens.py file

pvlib/spectrum/magnus_tetens.py Show resolved Hide resolved
pvlib/spectrum/magnus_tetens.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
uv.lock Outdated Show resolved Hide resolved
pvlib/spectrum/magnus_tetens.py Show resolved Hide resolved
@cwhanse cwhanse added this to the v0.11.2 milestone Nov 11, 2024
pvlib/atmosphere.py Outdated Show resolved Hide resolved
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!

Copy link
Member

Choose a reason for hiding this comment

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

Still need to remove this magnus_tetens.py file

pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
@@ -82,12 +82,50 @@ def test_gueymard94_pw():
pws = atmosphere.gueymard94_pw(temps_humids[:, 0], temps_humids[:, 1])

expected = np.array(
[ 0.1 , 0.33702061, 1.12340202, 0.1 ,
[0.1 , 0.33702061, 1.12340202, 0.1 ,
Copy link
Member

Choose a reason for hiding this comment

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

I suggest reverting the changes to lines 85 and 36, just to prevent the linter from complaining at you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @kandersolar thanks for the look and sorry for the late response, I have been out for the holiday. I was wondering, should I try to remove all of the flake8 linter complaints? I could revert how the function looks in main, but flake8 still doesn't like the white space, or I could remove the white space and make the linter happy..

rh,
tdew_rh_conversion_relative_humidity,
check_names=False
)
Copy link
Member

Choose a reason for hiding this comment

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

For completeness, let's add corresponding tests where the inputs are float and array. We will also need to include tests where alternative coefficient values are specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kandersolar just reworked the unit tests, I added tests which take in a numpy array and a float as well as a pandas series with a different set of coefficients. Let me know what you think, happy to adjust in any way.

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]>
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
4 participants