Make draw_adiabat() take fn to find lapsse rate

This commit is contained in:
XANTRONIX 2025-03-05 13:48:08 -05:00
parent ff18a8821a
commit 796257194b

View file

@ -4,7 +4,8 @@ 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, moist_lapse_rate from xmet.thermo import pressure_height, lapse, moist_lapse_rate, \
LAPSE_RATE_DRY
PRESSURE_MAX = 1050 # millibar PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100 PRESSURE_MIN = 100
@ -105,7 +106,7 @@ class SkewTGraph():
y: float, y: float,
start_temp: float, start_temp: float,
start_pressure: float, start_pressure: float,
moist: bool=False): lapse_rate: Callable):
start_height = pressure_height(start_pressure) start_height = pressure_height(start_pressure)
sx_last = None sx_last = None
sy_last = None sy_last = None
@ -120,15 +121,12 @@ class SkewTGraph():
if height_last is None: if height_last is None:
height_last = height height_last = height
if moist: try:
try: rate = lapse_rate(temp, temp, pressure)
rate = moist_lapse_rate(temp, temp, pressure) except OverflowError:
except OverflowError: break
break
temp = lapse(temp, height - height_last, rate) temp = lapse(temp, height - height_last, rate)
else:
temp = lapse(start_temp, height - start_height)
sx, sy = self.sample_to_screen(temp, pressure) sx, sy = self.sample_to_screen(temp, pressure)
@ -157,12 +155,12 @@ 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) self.draw_adiabat(cr, x, y, temp, PRESSURE_MAX, lambda t, d, p: LAPSE_RATE_DRY)
cr.set_source_rgba(0.3, 0.1, 0, 0.2) cr.set_source_rgba(0.3, 0.1, 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, True) self.draw_adiabat(cr, x, y, temp, PRESSURE_MAX, moist_lapse_rate)
cr.restore() cr.restore()