Render both temperature and dewpoint on Skew-T

This commit is contained in:
XANTRONIX 2025-02-23 21:20:30 -05:00
parent bfff79c929
commit d564391d6b

View file

@ -1,6 +1,10 @@
import math
import cairo
from typing import Iterable, Callable
from xmet.sounding import SoundingSample
PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100
PRESSURE_STEP = 50
@ -84,6 +88,48 @@ class SkewT():
cr.line_to(x + screen_x2, y + screen_y2)
cr.stroke()
def draw(self, cr: cairo.Context, x: float, y: float):
def draw_samples(self,
cr: cairo.Context,
x: float,
y: float,
samples: Iterable[SoundingSample],
fn: Callable):
first = True
for sample in samples:
if sample.pressure < PRESSURE_MIN:
break
#
# Temperature may possibly be dewpoint, depending on the
# return value of the callback.
#
temp, pressure = fn(sample)
if temp is None:
continue
gx, gy = self.sample_to_graph(temp, pressure)
sx, sy = self.graph_to_screen(gx, gy)
if first:
cr.move_to(x + sx, y + sy)
first = False
else:
cr.line_to(x + sx, y + sy)
cr.stroke()
def draw(self,
cr: cairo.Context,
x: float,
y: float,
samples: Iterable[SoundingSample]):
self.draw_isotherms(cr, x, y)
self.draw_isobars(cr, x, y)
cr.set_source_rgb(1, 0, 0)
self.draw_samples(cr, x, y, samples, lambda s: (s.temp, s.pressure))
cr.set_source_rgb(0, 1, 0)
self.draw_samples(cr, x, y, samples, lambda s: (s.dewpoint, s.pressure))