Compare commits

..

No commits in common. "28a3200a47a4c22e528c280157f9d63a04a1f1a3" and "0d831b62cf888e3ab186b1b6cb8c916bb363a8cc" have entirely different histories.

3 changed files with 28 additions and 24 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.rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)
cr.fill() cr.fill()
skew_t.draw(cr, 64, 64, sounding) skew_t.draw(cr, 64, 64, sounding.samples)
cr.set_source_rgb(0, 0, 0) cr.set_source_rgb(0, 0, 0)
cr.rectangle(64, 64, GRAPH_WIDTH, GRAPH_HEIGHT) cr.rectangle(64, 64, GRAPH_WIDTH, GRAPH_HEIGHT)

View file

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

View file

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