Hardcode lapse() to perform dry lapse

This commit is contained in:
XANTRONIX 2025-03-04 22:57:01 -05:00
parent 706a1cf41e
commit 929e6b4351
2 changed files with 10 additions and 15 deletions

View file

@ -4,8 +4,7 @@ import cairo
from typing import Callable from typing import Callable
from xmet.sounding import Sounding from xmet.sounding import Sounding
from xmet.thermo import pressure_height, lapse, \ from xmet.thermo import pressure_height, lapse
LAPSE_RATE_MOIST, LAPSE_RATE_DRY
PRESSURE_MAX = 1050 # millibar PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100 PRESSURE_MIN = 100
@ -22,9 +21,6 @@ TEMP_CENTER = 0 # degrees C
TEMP_STEP = 5 TEMP_STEP = 5
TEMP_STEP_COUNT = math.ceil(TEMP_RANGE / TEMP_STEP) TEMP_STEP_COUNT = math.ceil(TEMP_RANGE / TEMP_STEP)
LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per 1000m
LAPSE_RATE_MOIST = 4.0 / 1000
def clamp(value, lowest, highest): def clamp(value, lowest, highest):
if value < lowest: if value < lowest:
return lowest return lowest
@ -108,8 +104,7 @@ class SkewTGraph():
x: float, x: float,
y: float, y: float,
start_temp: float, start_temp: float,
start_pressure: float, start_pressure: float):
lapse_rate: float):
start_height = pressure_height(start_pressure) start_height = pressure_height(start_pressure)
sx_last = None sx_last = None
sy_last = None sy_last = None
@ -118,7 +113,7 @@ class SkewTGraph():
while pressure >= PRESSURE_MIN: while pressure >= PRESSURE_MIN:
height = pressure_height(pressure) height = pressure_height(pressure)
temp_cur = lapse(start_temp, lapse_rate, height - start_height) temp_cur = lapse(start_temp, height - start_height)
sx, sy = self.sample_to_screen(temp_cur, pressure) sx, sy = self.sample_to_screen(temp_cur, pressure)
@ -140,7 +135,7 @@ class SkewTGraph():
cr.set_source_rgba(1.0, 0.2, 0, 0.2) cr.set_source_rgba(1.0, 0.2, 0, 0.2)
for temp in range(-140, 140, 10): for temp in range(-140, 140, 10):
self.draw_adiabat(cr, x, y, temp, PRESSURE_MAX, LAPSE_RATE_DRY) self.draw_adiabat(cr, x, y, temp, PRESSURE_MAX)
cr.restore() cr.restore()

View file

@ -1,5 +1,5 @@
LAPSE_RATE_MOIST = 4.0 # degrees C per km LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km
LAPSE_RATE_DRY = 9.8 LAPSE_RATE_MOIST = 4.0 / 1000
def vapor_pressure(dewpoint: float) -> float: def vapor_pressure(dewpoint: float) -> float:
""" """
@ -50,9 +50,9 @@ def pressure_height(pressure: float) -> float:
""" """
return (1 - (pressure / 1013.25) ** 0.190284) * 145366.45 * 0.3048 return (1 - (pressure / 1013.25) ** 0.190284) * 145366.45 * 0.3048
def lapse(temp: float, rate: float, delta: float) -> float: def lapse(temp: float, delta: float) -> float:
""" """
Return the temperature of a parcel cooled at either the dry or moist lapse Return the temperature of a parcel cooled at the dry lapse rate for a
rate for a given increase in height (in meters). given increase in height (in meters).
""" """
return temp - (rate * delta) return temp - (LAPSE_RATE_DRY * delta)