Skip to content

Clarify rh_from_tdew variable naming, comments and references#2782

Open
gaoflow wants to merge 2 commits into
pvlib:mainfrom
gaoflow:fix-2734-rh-from-tdew-naming
Open

Clarify rh_from_tdew variable naming, comments and references#2782
gaoflow wants to merge 2 commits into
pvlib:mainfrom
gaoflow:fix-2734-rh-from-tdew-naming

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
  • Closes Inverted vapor pressure and saturation vapor pressure #2734
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • 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`).
  • 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.

This is a clarity change with no change to the returned values. As noted in #2734 and independently confirmed by @echedey-ls (cross-checked against an online calculator and NREL's pvdeg), rh_from_tdew already returns correct relative humidity — e.g. rh_from_tdew(20, 10) == 52.56 %, rh_from_tdew(25, 25) == 100 %, and it round-trips with tdew_from_rh. What confused the report is that the two intermediate variables were named backwards: e was computed from temp_air (so it was really the saturation pressure) and es from temp_dew (the actual pressure), and 100 * es/e with those swapped names happens to equal the conventional 100 * e/es.

Changes:

  • Compute e from the dew point (actual vapor pressure) and es from the air temperature (saturation) so the source matches the usual convention, and write 100 * e/es. Numerically identical — the existing value-pinning tests (test_rh_from_tdew, test_tdew_from_rh, test_tdew_to_rh_to_tdew) pass unchanged.
  • Fix the now-inaccurate derivation comment in tdew_from_rh (it referenced es/e).
  • Add a short Notes section and the Alduchov & Eskridge (1996) reference for the Magnus form, since the WMO guide alone doesn't name it (per @echedey-ls).
  • Add a physical-bounds regression test: saturation when dew point == air temperature, RH below 100 % otherwise and monotonic in the dew point, so the direction can't silently invert.

I left the exp-division micro-optimisation @echedey-ls mentioned out of this first pass since he flagged maintainers may differ on it — happy to add it (or expand the applicability notes with a max-error / valid-range figure) if wanted.

In rh_from_tdew the intermediate named `e` was computed from the air
temperature (so it was actually the saturation vapor pressure) and `es`
from the dew point (the actual vapor pressure) -- swapped relative to the
usual convention, which led pvlib#2734 to read it as an inverted formula. The
returned values are correct and unchanged (100 * es/e with the swapped
names equals 100 * e/es with conventional ones); this computes `e` from
the dew point and `es` from the air temperature so the source matches the
convention, and fixes the matching derivation comment in tdew_from_rh.

Also adds a Notes section and the Alduchov & Eskridge (1996) reference for
the Magnus form, plus a physical-bounds regression test (saturation when
dew point == air temperature, RH below 100% and monotonic in the dew point
otherwise) so the direction cannot silently invert.

Addresses pvlib#2734.
@gaoflow gaoflow force-pushed the fix-2734-rh-from-tdew-naming branch from 6d5a9fe to 0239748 Compare June 10, 2026 22:17
@kandersolar

Copy link
Copy Markdown
Member

@gaoflow in the future please include the PR template checklist when making PRs. I've added it back to this one.

@gaoflow

gaoflow commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, and apologies for omitting the checklist - I will include the PR template on future PRs.

Comment thread pvlib/atmosphere.py Outdated
State the -45 to +60 C validity range of the Magnus form directly in the
Notes, citing WMO-No. 8 [1], instead of deferring to the reference.
@cwhanse cwhanse added this to the v0.15.2 milestone Jun 15, 2026
Comment on lines +60 to +61
:py:func:`pvlib.atmosphere.tdew_from_rh`) so the actual and saturation vapor
pressures are no longer swapped in the source. The returned values are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
:py:func:`pvlib.atmosphere.tdew_from_rh`) so the actual and saturation vapor
pressures are no longer swapped in the source. The returned values are
:py:func:`pvlib.atmosphere.tdew_from_rh`) related to the actual
and saturation vapor pressures. Function output is

Comment thread pvlib/atmosphere.py
Comment on lines +368 to +369
Relative humidity is computed as ``100 * e / es``, where the actual vapor
pressure ``e`` is the saturation vapor pressure at the dew point and the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Relative humidity is computed as ``100 * e / es``, where the actual vapor
pressure ``e`` is the saturation vapor pressure at the dew point and the
Relative humidity is computed as ``100 * e / es``, where ``e`` is the
saturation vapor pressure at the dew point temperature, and ``es``

Comment thread pvlib/atmosphere.py
Comment on lines +370 to +371
saturation vapor pressure ``es`` is evaluated at the air temperature, both
from the Magnus equation ``A * exp(B * T / (C + T))``. The default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
saturation vapor pressure ``es`` is evaluated at the air temperature, both
from the Magnus equation ``A * exp(B * T / (C + T))``. The default
is the saturation vapor pressureat the air temperature, both
from the Magnus equation ``A * exp(B * T / (C + T))``. The default

@kandersolar kandersolar modified the milestones: v0.15.2, v0.15.3 Jun 16, 2026
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.

Inverted vapor pressure and saturation vapor pressure

4 participants