Initial implementation of moist adiabat plotting (it sucks)

This commit is contained in:
XANTRONIX 2025-03-05 00:35:21 -05:00
parent fe4b980ac9
commit bc9a2977a5

View file

@ -4,7 +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, moist_lapse_rate
PRESSURE_MAX = 1050 # millibar PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100 PRESSURE_MIN = 100
@ -104,18 +104,33 @@ class SkewTGraph():
x: float, x: float,
y: float, y: float,
start_temp: float, start_temp: float,
start_pressure: float): start_pressure: float,
moist: bool=False):
start_height = pressure_height(start_pressure) start_height = pressure_height(start_pressure)
sx_last = None sx_last = None
sy_last = None sy_last = None
height_last = None
temp = start_temp
pressure = start_pressure pressure = start_pressure
while pressure >= PRESSURE_MIN: while pressure >= PRESSURE_MIN:
height = pressure_height(pressure) height = pressure_height(pressure)
temp_cur = lapse(start_temp, height - start_height)
sx, sy = self.sample_to_screen(temp_cur, pressure) if height_last is None:
height_last = height
if moist:
try:
rate = moist_lapse_rate(temp, temp, pressure)
except OverflowError:
break
temp = lapse(temp, height - height_last, rate)
else:
temp = lapse(start_temp, height - start_height)
sx, sy = self.sample_to_screen(temp, pressure)
if sx_last is not None: if sx_last is not None:
cr.move_to(x + sx, y + sy) cr.move_to(x + sx, y + sy)
@ -124,6 +139,7 @@ class SkewTGraph():
sx_last = sx sx_last = sx
sy_last = sy sy_last = sy
height_last = height
pressure -= 10.0 pressure -= 10.0
@ -137,6 +153,9 @@ class SkewTGraph():
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)
for temp in range(-140, 140, 10):
self.draw_adiabat(cr, x, y, temp, PRESSURE_MAX, True)
cr.restore() cr.restore()
def draw_sounding(self, def draw_sounding(self,