Render both temperature and dewpoint on Skew-T
This commit is contained in:
parent
bfff79c929
commit
d564391d6b
1 changed files with 47 additions and 1 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue