From 1cb8875053eb2815ccb1ce200969ad8f8b6d769c Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sun, 23 Feb 2025 23:45:46 -0500 Subject: [PATCH] Rip out hardcoded isotherms (for now) --- lib/xmet/skew_t.py | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/lib/xmet/skew_t.py b/lib/xmet/skew_t.py index 8d66026..a495cf5 100644 --- a/lib/xmet/skew_t.py +++ b/lib/xmet/skew_t.py @@ -13,8 +13,12 @@ PRESSURE_LOG_MAX = math.log(PRESSURE_MAX) PRESSURE_LOG_MIN = math.log(PRESSURE_MIN) PRESSURE_LOG_RANGE = PRESSURE_LOG_MAX - PRESSURE_LOG_MIN -TEMP_CENTER = 0 # degrees C -TEMP_STEP = 5 +TEMP_MAX = 60 +TEMP_MIN = -40 +TEMP_RANGE = TEMP_MAX - TEMP_MIN +TEMP_CENTER = 0 # degrees C +TEMP_STEP = 5 +TEMP_STEP_COUNT = 16 def clamp(value, lowest, highest): if value < lowest: @@ -27,25 +31,11 @@ def clamp(value, lowest, highest): class SkewT(): __slots__ = 'width', 'height', 'temp_step_width', - ISOTHERM_LINES = ( - (0, 0, 9, 9), (1, 0, 9, 8), (2, 0, 9, 7), (3, 0, 9, 6), - (4, 0, 9, 5), (5, 0, 9, 4), (6, 0, 9, 3), (7, 0, 9, 2), - (8, 0, 9, 1), (9, 0, 9, 0), - - (-1, 0, 9, 10), (-2, 0, 8, 10), (-3, 0, 7, 10), (-4, 0, 6, 10), - (-5, 0, 5, 10), (-6, 0, 4, 10), (-7, 0, 3, 10), (-8, 0, 2, 10), - (-9, 0, 1, 10), - - (-9, 1, 0, 10), (-9, 2, -1, 10), (-9, 3, -2, 10), (-9, 4, -3, 10), - (-9, 5, -4, 10), (-9, 6, -5, 10), (-9, 7, -6, 10), (-9, 8, -7, 10), - (-9, 9, -8, 10), - ) - def __init__(self, width: float, height: float): self.width = width self.height = height - self.temp_step_width = self.height / 10.0 + self.temp_step_width = min(self.width, self.height) / TEMP_STEP_COUNT def graph_to_screen(self, x, y) -> tuple: return (self.width / 2) + x, self.height - y @@ -57,6 +47,8 @@ class SkewT(): return factor * self.height def draw_isobars(self, cr: cairo.Context, x: float, y: float): + cr.set_source_rgb(0.5, 0.5, 0.5) + for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP): coord = self.graph_to_screen(-self.width / 2, self.pressure_y(pressure)) @@ -69,24 +61,16 @@ class SkewT(): def draw_isotherms(self, cr: cairo.Context, x: float, y: float): cr.set_source_rgba(0.1, 0.5, 0.1, 0.8) - for line in self.ISOTHERM_LINES: - x1 = line[0] * self.temp_step_width - y1 = line[1] * self.temp_step_width - x2 = line[2] * self.temp_step_width - y2 = line[3] * self.temp_step_width + pass - (screen_x1, screen_y1) = self.graph_to_screen(x1, y1) - (screen_x2, screen_y2) = self.graph_to_screen(x2, y2) - - cr.move_to(x + screen_x1, y + screen_y1) - cr.line_to(x + screen_x2, y + screen_y2) - cr.stroke() + def skew_t_to_graph(self, x: float, y: float): + return (x+y, y) def sample_to_graph(self, temp: float, pressure: float): x = (temp / TEMP_STEP) * self.temp_step_width y = self.pressure_y(pressure) - return x + y, y + return self.skew_t_to_graph(x, y) def draw_samples(self, cr: cairo.Context,