You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inverted vapor pressure and saturation vapor pressure #2734
I checked this on current main before assuming the direction, and rh_from_tdew actually returns the correct values — it's the variable names and the comment that are backwards, not the result:
and it round-trips with tdew_from_rh (tdew_from_rh(20, 52.56) ≈ 10.0).
The reason: at L374-375 the variable named e is computed from temp_air, so it is really the saturation pressure es(Ta), and es is computed from temp_dew, so it is the actual vapor pressure e = es(Td). That makes 100 * (es / e) at L378 equal to 100 * actual / saturation, which is correct.
So a literal change to 100 * (e / es)without also swapping the two assignments would invert a currently-correct result — and it would break tdew_from_rh, whose derivation (L410) starts from RH = 100 * es/e.
The clean fix is to make the names match the WMO convention: compute e from temp_dew and es from temp_air, then write 100 * (e / es). That is numerically identical to today but no longer misleading, plus fixing the L373 comment (and the L410 comment in tdew_from_rh). Happy to open that PR — names + comments only, result unchanged, with a regression test pinning these known-good values — if that sounds right, @AdamRJensen.
Thanks for the insight @gaoflow. I did also that research a while ago with the same outcome, by comparing against an online calculator and NRL's pvdeg implementation (link) but I didn't report back for two reasons:
"Magnus equation" comment is written in the code but I couldn't locate it in the reference, which ended up making me traverse wikipedia and other sources to be sure. The references section may need updating.
I also wanted to suggest other documentation improvements, like the assumptions and applicability (near sea level, valid temp range, expected max error)
The computation could also be micro-optimized at the cost of a bit of legibility, by collapsing the exp's division - I'm in favor of that while leaving the previous code commented out, but I understand the maintainers may not agree with me on this point.
Btw, the latter part of your analysis seems to be AI slop. We really want contributors to know what they are doing, so please, if you contribute any further, we kindly suggest that you make a sensible use of AI instead, learn as much as you need to understand and verify all your steps, check sources, etc. It takes a lot of time from our side to verify an LLM contribution.
Thanks for confirming @echedey-ls — good to have the independent pvdeg / online-calculator cross-check.
I'll open a PR that:
keeps the result identical but renames the two intermediate variables so they match convention (e = actual vapor pressure from the dew point, es = saturation from the air temperature, RH = 100·e/es), which removes the source of confusion here;
fixes the now-inaccurate comments (including the es/e derivation note in tdew_from_rh);
tightens the References — the (6.112, 17.62, 243.12) set is the WMO-recommended Magnus form (Alduchov & Eskridge, 1996); I'll cite that alongside the CIMO guide;
adds a short Notes on validity (over liquid water, the usual Magnus temperature range);
adds a regression test pinning the current correct values so the direction can't silently flip later.
I'll leave the exp-division micro-optimisation out of the first pass since you flagged maintainers may differ — trivial to add if they want it. Does that scope work? Happy to fold in any specific applicability wording (max error / valid range) you had in mind.
Activity
AdamRJensen commentedon Apr 14, 2026
I agree that this seems like a bug. Thanks for reporting @nicomignoni!
The equation was implemented in #2286 .
The below equations are from page 194 in https://library.wmo.int/idurl/4/68695
with
echedey-ls commentedon Apr 14, 2026
Beware of affected
tdew_from_rhtoo, at least this comment and possibly the implementation:pvlib-python/pvlib/atmosphere.py
Lines 409 to 411 in cf49dea
binggao1230 commentedon Jun 10, 2026
I checked this on current
mainbefore assuming the direction, andrh_from_tdewactually returns the correct values — it's the variable names and the comment that are backwards, not the result:and it round-trips with
tdew_from_rh(tdew_from_rh(20, 52.56) ≈ 10.0).The reason: at L374-375 the variable named
eis computed fromtemp_air, so it is really the saturation pressurees(Ta), andesis computed fromtemp_dew, so it is the actual vapor pressuree = es(Td). That makes100 * (es / e)at L378 equal to100 * actual / saturation, which is correct.So a literal change to
100 * (e / es)without also swapping the two assignments would invert a currently-correct result — and it would breaktdew_from_rh, whose derivation (L410) starts fromRH = 100 * es/e.The clean fix is to make the names match the WMO convention: compute
efromtemp_dewandesfromtemp_air, then write100 * (e / es). That is numerically identical to today but no longer misleading, plus fixing the L373 comment (and the L410 comment intdew_from_rh). Happy to open that PR — names + comments only, result unchanged, with a regression test pinning these known-good values — if that sounds right, @AdamRJensen.echedey-ls commentedon Jun 10, 2026
Thanks for the insight @gaoflow. I did also that research a while ago with the same outcome, by comparing against an online calculator and NRL's pvdeg implementation (link) but I didn't report back for two reasons:
The computation could also be micro-optimized at the cost of a bit of legibility, by collapsing the exp's division - I'm in favor of that while leaving the previous code commented out, but I understand the maintainers may not agree with me on this point.
Btw, the latter part of your analysis seems to be AI slop. We really want contributors to know what they are doing, so please, if you contribute any further, we kindly suggest that you make a sensible use of AI instead, learn as much as you need to understand and verify all your steps, check sources, etc. It takes a lot of time from our side to verify an LLM contribution.
binggao1230 commentedon Jun 10, 2026
Thanks for confirming @echedey-ls — good to have the independent pvdeg / online-calculator cross-check.
I'll open a PR that:
e= actual vapor pressure from the dew point,es= saturation from the air temperature,RH = 100·e/es), which removes the source of confusion here;es/ederivation note intdew_from_rh);(6.112, 17.62, 243.12)set is the WMO-recommended Magnus form (Alduchov & Eskridge, 1996); I'll cite that alongside the CIMO guide;I'll leave the exp-division micro-optimisation out of the first pass since you flagged maintainers may differ — trivial to add if they want it. Does that scope work? Happy to fold in any specific applicability wording (max error / valid range) you had in mind.
Clarify rh_from_tdew variable naming, comments and references
Clarify rh_from_tdew variable naming, comments and references
Clarify rh_from_tdew variable naming, comments and references
Clarify rh_from_tdew variable naming, comments and references (#2782)