Compare commits

..

2 commits

2 changed files with 50 additions and 2 deletions

View file

@ -42,7 +42,9 @@ def etime_to_seconds(etime: str) -> int:
if etime == '-8888' or etime == '-9999': if etime == '-8888' or etime == '-9999':
return return
return 60 * int(etime[0:2]) + int(etime[2:]) minutes = 0 if etime[0:3] == ' ' else int(etime[0:3])
return 60 * minutes + int(etime[3:])
def parse_num(num: str, scale: float) -> float: def parse_num(num: str, scale: float) -> float:
if num == '-8888' or num == '-9999': if num == '-8888' or num == '-9999':

View file

@ -1,6 +1,10 @@
import math import math
import cairo import cairo
from typing import Iterable, Callable
from xmet.sounding import SoundingSample
PRESSURE_MAX = 1050 # millibar PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100 PRESSURE_MIN = 100
PRESSURE_STEP = 50 PRESSURE_STEP = 50
@ -84,6 +88,48 @@ class SkewT():
cr.line_to(x + screen_x2, y + screen_y2) cr.line_to(x + screen_x2, y + screen_y2)
cr.stroke() 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_isotherms(cr, x, y)
self.draw_isobars(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))