From 72051fe5ee550f72a1ef394a46125feec752a882 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 11 Apr 2026 12:52:31 -0500 Subject: [PATCH] Guard against zero specific humidity in theta-e computation --- lib/microwaveprop/weather/theta_e.ex | 4 ++++ 1 file changed, 4 insertions(+) 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)