Compare commits
2 commits
72d8195943
...
e0438ac8f9
Author | SHA1 | Date | |
---|---|---|---|
e0438ac8f9 | |||
edf1af526f |
2 changed files with 39 additions and 3 deletions
|
@ -22,8 +22,13 @@ def knots(ms: float) -> float:
|
||||||
class Hodograph():
|
class Hodograph():
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
self.zoom = 1.2
|
self.zoom = 1.2
|
||||||
self.offset_x = 0.1
|
self.offset_x = 0.1 # Percentage of the upper left quadrant rendered
|
||||||
self.offset_y = 0.9
|
self.offset_y = 0.9 # Percentage of the upper right quadrant rendered
|
||||||
|
|
||||||
|
self.min_x = 0
|
||||||
|
self.min_y = 0
|
||||||
|
self.max_x = 0
|
||||||
|
self.max_y = 0
|
||||||
|
|
||||||
self.width = min(width, height)
|
self.width = min(width, height)
|
||||||
self.height = min(width, height)
|
self.height = min(width, height)
|
||||||
|
@ -45,6 +50,32 @@ class Hodograph():
|
||||||
self.offset_y * self.height + gy
|
self.offset_y * self.height + gy
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def find_extents(self, sounding: Sounding):
|
||||||
|
"""
|
||||||
|
Determine the boundaries of the sounding to set the center and zoom
|
||||||
|
appropriately.
|
||||||
|
"""
|
||||||
|
for sample in sounding.samples:
|
||||||
|
x, y = self.sample_to_graph(sample.wind_speed, sample.wind_dir)
|
||||||
|
|
||||||
|
if self.min_x > x:
|
||||||
|
self.min_x = x
|
||||||
|
|
||||||
|
if self.min_y > y:
|
||||||
|
self.min_y = y
|
||||||
|
|
||||||
|
if self.max_x < x:
|
||||||
|
self.max_x = x
|
||||||
|
|
||||||
|
if self.max_y < y:
|
||||||
|
self.max_y = y
|
||||||
|
|
||||||
|
self.offset_x = self.min_x / self.radius + 0.1
|
||||||
|
self.offset_y = (self.radius - self.max_y) / self.radius
|
||||||
|
self.zoom = min(self.width, self.height) / max(self.max_x - self.min_x,
|
||||||
|
self.max_y - self.min_y) / 2
|
||||||
|
self.radius = min(self.width, self.height) * self.zoom
|
||||||
|
|
||||||
def draw_speed_lines(self, cr: cairo.Context, x, y):
|
def draw_speed_lines(self, cr: cairo.Context, x, y):
|
||||||
cr.save()
|
cr.save()
|
||||||
|
|
||||||
|
@ -199,6 +230,8 @@ class Hodograph():
|
||||||
offset += interval
|
offset += interval
|
||||||
|
|
||||||
def draw(self, cr: cairo.Context, x, y, sounding: Sounding):
|
def draw(self, cr: cairo.Context, x, y, sounding: Sounding):
|
||||||
|
self.find_extents(sounding)
|
||||||
|
|
||||||
cr.rectangle(x, y, self.width, self.height)
|
cr.rectangle(x, y, self.width, self.height)
|
||||||
cr.clip()
|
cr.clip()
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ from xmet.sounding import Sounding, SoundingSample
|
||||||
CHUNK_SEP = "\x01"
|
CHUNK_SEP = "\x01"
|
||||||
CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
|
CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
|
||||||
|
|
||||||
|
def meters_second(knots: float) -> float:
|
||||||
|
return knots / 1.944
|
||||||
|
|
||||||
class RAOBReaderException(Exception):
|
class RAOBReaderException(Exception):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -92,7 +95,7 @@ class RAOBObs():
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'dir': wind_dir,
|
'dir': wind_dir,
|
||||||
'speed': wind_speed
|
'speed': meters_second(wind_speed)
|
||||||
}
|
}
|
||||||
|
|
||||||
TTAA_PRESSURES = {
|
TTAA_PRESSURES = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue