Guard against zero specific humidity in theta-e computation

This commit is contained in:
Graham McIntire 2026-04-11 12:52:31 -05:00
parent 9d5ebc650b
commit 72051fe5ee

View file

@ -24,6 +24,10 @@ defmodule Microwaveprop.Weather.ThetaE do
"""
@spec compute(float, float, float) :: float
def compute(temp_k, spfh, pressure_pa) do
# Guard: zero or negative humidity makes the log terms undefined.
# Clamp to a tiny positive value (equivalent to extremely dry air).
spfh = max(spfh, 1.0e-8)
# Mixing ratio from specific humidity: r = q / (1 - q)
r = spfh / (1.0 - spfh)