Compare commits

...

2 commits

3 changed files with 24 additions and 28 deletions

View file

@ -42,7 +42,7 @@ with cairo.SVGSurface(args.output, IMAGE_WIDTH, IMAGE_HEIGHT) as surface:
cr.rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)
cr.fill()
skew_t.draw(cr, 64, 64, sounding.samples)
skew_t.draw(cr, 64, 64, sounding)
cr.set_source_rgb(0, 0, 0)
cr.rectangle(64, 64, GRAPH_WIDTH, GRAPH_HEIGHT)

View file

@ -1,10 +1,8 @@
import math
import cairo
from typing import Iterable
from xmet.igra import IGRAReader
from xmet.sounding import Sounding, SoundingSample
from xmet.sounding import Sounding
WIND_SPEED_MAX = 100 # knots
WIND_SPEED_MIN = 10
@ -123,11 +121,11 @@ class Hodograph():
if height < key:
return self.COLORS[key]
def draw_samples(self,
cr: cairo.Context,
x,
y,
samples: Iterable[SoundingSample]):
def draw_sounding(self,
cr: cairo.Context,
x,
y,
sounding: Sounding):
cr.save()
first = True
@ -135,7 +133,7 @@ class Hodograph():
sx_last = None
sy_last = None
for sample in samples:
for sample in sounding.samples:
if sample.pressure < 0 or sample.pressure is None:
continue
@ -176,7 +174,7 @@ class Hodograph():
cr.save()
cr.set_source_rgb(1, 1, 1)
cr.rectangle(offset + x - width / 2,
cr.rectangle(offset + x - width * 0.75,
y + width,
interval * 4,
width * 3)
@ -184,7 +182,7 @@ class Hodograph():
cr.fill()
cr.set_source_rgb(0.8, 0.8, 0.8)
cr.rectangle(offset + x - width / 2,
cr.rectangle(offset + x - width * 0.75,
y + width,
interval * 4,
width * 3)
@ -203,18 +201,16 @@ class Hodograph():
cr.rectangle(offset + x, y + width * 1.5, width, width)
cr.stroke()
cr.move_to(offset + x, y + 3.5*width)
if height < 1000:
cr.show_text("%dm" % height)
else:
cr.show_text("%dkm" % (height / 1000))
text = "%dm" % (height) if height < 1000 else "%dkm" % (height /1000)
extents = cr.text_extents(text)
cr.move_to(offset + x - extents.width / 4, y + 3.5*width)
cr.show_text(text)
cr.stroke()
offset += interval
def draw(self, cr: cairo.Context, x, y, samples: Iterable[SoundingSample]):
def draw(self, cr: cairo.Context, x, y, sounding: Sounding):
cr.rectangle(x, y, self.width, self.height)
cr.clip()
@ -224,7 +220,7 @@ class Hodograph():
self.draw_speed_lines(cr, x, y)
self.draw_direction_lines(cr, x, y)
self.draw_samples(cr, x, y, samples)
self.draw_sounding(cr, x, y, sounding)
self.draw_speed_legends(cr, x, y)
self.draw_direction_legends(cr, x, y)

View file

@ -1,9 +1,9 @@
import math
import cairo
from typing import Iterable, Callable
from typing import Callable
from xmet.sounding import SoundingSample
from xmet.sounding import Sounding
PRESSURE_MAX = 1050 # millibar
PRESSURE_MIN = 100
@ -101,17 +101,17 @@ class SkewTGraph():
cr.restore()
def draw_samples(self,
def draw_sounding(self,
cr: cairo.Context,
x: float,
y: float,
samples: Iterable[SoundingSample],
sounding: Sounding,
fn: Callable):
cr.save()
first = True
for sample in samples:
for sample in sounding.samples:
if sample.pressure < 0 or sample.pressure is None:
continue
@ -143,7 +143,7 @@ class SkewTGraph():
cr: cairo.Context,
x: float,
y: float,
samples: Iterable[SoundingSample]):
sounding: Sounding):
cr.rectangle(x, y, self.width, self.height)
cr.clip()
@ -151,10 +151,10 @@ class SkewTGraph():
self.draw_isobars(cr, x, y)
cr.set_source_rgb(1, 0, 0)
self.draw_samples(cr, x, y, samples, lambda s: s.temp)
self.draw_sounding(cr, x, y, sounding, lambda s: s.temp)
cr.set_source_rgb(0, 1, 0)
self.draw_samples(cr, x, y, samples, lambda s: s.dewpoint)
self.draw_sounding(cr, x, y, sounding, lambda s: s.dewpoint)
cr.reset_clip()