Skip to content

Clarify rh_from_tdew variable naming, comments and references#2782

Open
gaoflow wants to merge 1 commit 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 1 commit into
pvlib:mainfrom
gaoflow:fix-2734-rh-from-tdew-naming

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Addresses #2734.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant