From 9309393189be474e44155670c14d8cb3876583e8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sun, 9 Mar 2025 23:59:25 -0400 Subject: [PATCH] Add PRESSURE_MSL magic constant --- lib/xmet/thermo.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/xmet/thermo.py b/lib/xmet/thermo.py index c19a6e1..fa3ac1b 100644 --- a/lib/xmet/thermo.py +++ b/lib/xmet/thermo.py @@ -8,6 +8,7 @@ LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km LAPSE_RATE_MOIST = 4.0 / 1000 PRESSURE_MAX = 1050 # millibar +PRESSURE_MSL = 1013.25 PRESSURE_MIN = 100 PRESSURE_STEP = 50 @@ -68,12 +69,12 @@ def lcl(temp: float, dewpoint: float) -> float: """ return (temp - dewpoint) / 0.008 -def pressure_height(pressure: float) -> float: +def pressure_height(pressure: float, surface: float=PRESSURE_MSL) -> float: """ Return the approximate altitude, in meters, for a given pressure in millibar. """ - return (1 - (pressure / 1013.25) ** 0.190284) * 145366.45 * 0.3048 + return (1 - (pressure / surface) ** 0.190284) * 145366.45 * 0.3048 def lapse(temp: float, delta: float, rate=LAPSE_RATE_DRY) -> float: """