From 362ee0a2f44bcef67b2c6180b5443a74e89f73ac Mon Sep 17 00:00:00 2001
From: XANTRONIX Industrial <xan@xantronix.com>
Date: Sun, 9 Mar 2025 16:14:20 -0400
Subject: [PATCH] Do not compute lapse on first height

---
 lib/xmet/thermo.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/xmet/thermo.py b/lib/xmet/thermo.py
index 193e068..1c17ec0 100644
--- a/lib/xmet/thermo.py
+++ b/lib/xmet/thermo.py
@@ -123,19 +123,17 @@ def loft_parcel(start_temp: float,
     while pressure >= PRESSURE_MIN:
         height = pressure_height(pressure)
 
-        if height_last is None:
-            height_last = height
+        if height_last is not None:
+            try:
+                rate = lapse_rate(temp, pressure)
+            except OverflowError:
+                break
 
-        try:
-            rate = lapse_rate(temp, pressure)
-        except OverflowError:
-            break
+            height_delta = height - height_last
 
-        temp = lapse(temp, height - height_last, rate)
+            temp = lapse(temp, height_delta, rate)
 
-        yield temp, pressure
-
-        height_last = height
+            yield temp, pressure
 
         if pressure == PRESSURE_MIN:
             break
@@ -144,6 +142,8 @@ def loft_parcel(start_temp: float,
         else:
             pressure -= step
 
+        height_last = height
+
 def follow_dry_adiabat(temp: float, pressure: float) -> Series:
     """
     Follow a dry adiabat starting at a given temp and pressure level, returning