Skip to content

Fix sign of temperature term in water_latent_heat_melting - #4232

Open
kadnaoui wants to merge 1 commit into
Unidata:mainfrom
kadnaoui:latent-heat-melting-sign
Open

kadnaoui wants to merge 1 commit into
Unidata:mainfrom
kadnaoui:latent-heat-melting-sign

Conversation

@kadnaoui

Copy link
Copy Markdown

Description Of Changes

water_latent_heat_melting returned Lf - (Cp_l - Cp_i) * (T - T0). Its own docstring (Ambaum 2020) gives L_m = L_m0 + (c_pl - c_pi)(T - T0), so the sign of the second term was inverted. As a result, the latent heat of melting grew below freezing instead of falling. The term is now added.

As the issue points out, L_m should equal L_s - L_v. With MetPy's own water_latent_heat_sublimation and water_latent_heat_vaporization, (Lv0 - (Cp_l - Cp_v)ΔT) subtracted from (Ls0 - (Cp_i - Cp_v)ΔT) gives Lf + (Cp_l - Cp_i)ΔT.

Value changes:

  • The docstring example at −15 °C goes from 365662.294 to 301737.706 J/kg, the value given in the issue.
  • The existing test value at 233 K goes from 0.4192 to 0.2483 MJ/kg. The old value matched the inverted sign.

Checklist

  • Closes water_latent_heat_melting subtracts the heat capacity term instead of adding it #4182
  • Tests added. test_water_latent_heat_melting_is_sublimation_minus_vaporization checks the result against sublimation minus vaporization at three temperatures. test_water_latent_heat_melting_decreases_below_freezing checks that the value is below Lf at −15 °C. Both fail on main and pass here. tests/calc passes (650 passed). The calc doctests pass (81) with the CI pins from ci/requirements.txt. ruff, flake8 and codespell pass on the changed files.
  • Fully documented

The latent heat of melting is the latent heat of sublimation minus that
of vaporization, so it changes with temperature as c_pl - c_pi, as the
docstring already says (L_m = L_m0 + (c_pl - c_pi)(T - T0)). The code
subtracted the term instead, so the value grew below freezing. Add it,
update the docstring example and the test value at 233 K, and test that
melting equals sublimation minus vaporization.

Fixes Unidata#4182
@kadnaoui
kadnaoui requested a review from a team as a code owner November 27, 2026 17:37
@kadnaoui
kadnaoui requested review from dcamron and removed request for a team November 27, 2026 17:37
@CLAassistant

CLAassistant commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

water_latent_heat_melting subtracts the heat capacity term instead of adding it

2 participants