diff --git a/lib/microwaveprop/weather/theta_e.ex b/lib/microwaveprop/weather/theta_e.ex index aff6844e..b5d9f48b 100644 --- a/lib/microwaveprop/weather/theta_e.ex +++ b/lib/microwaveprop/weather/theta_e.ex @@ -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)