From d564391d6b6cfff202b52410183a58fa44e203a8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sun, 23 Feb 2025 21:20:30 -0500 Subject: [PATCH] Render both temperature and dewpoint on Skew-T --- lib/xmet/skew_t.py | 48 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/xmet/skew_t.py b/lib/xmet/skew_t.py index e06f47b..18657d3 100644 --- a/lib/xmet/skew_t.py +++ b/lib/xmet/skew_t.py @@ -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))