Skip to content

Inverted vapor pressure and saturation vapor pressure #2734

Closed

Description

@nicomignoni

Hi! Unless I'm missing something, in atmosphere.py:378 the vapor pressure and saturation vapor pressure are inverted: it should be

relative_humidity = 100 * (e / es)

as per Guide to Meteorological Instruments and Methods of Observation at page 91 of the PDF.

Activity

  1. AdamRJensen commented on Apr 14, 2026

    @AdamRJensen
    Member

    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

    Image

    with

    Image
  2. echedey-ls commented on Apr 14, 2026

    @echedey-ls
    Member

    Beware of affected tdew_from_rh too, at least this comment and possibly the implementation:

    # Calculate the term inside the log
    # From RH = 100 * (es/e), we get es = (RH/100) * e
    # Substituting the Magnus equation and solving for dewpoint

  3. added theissue type on Apr 14, 2026
  4. binggao1230 commented on Jun 10, 2026

    @binggao1230
    Contributor

    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:

    rh_from_tdew(Ta=20, Td=10) = 52.56 %
    rh_from_tdew(Ta=25, Td=25) = 100.00 %
    rh_from_tdew(Ta=30, Td=10) = 28.96 %
    

    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.

  5. echedey-ls commented on Jun 10, 2026

    @echedey-ls
    Member

    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.

  6. binggao1230 commented on Jun 10, 2026

    @binggao1230
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions