Compare commits

..

5 commits

3 changed files with 26 additions and 20 deletions

View file

@ -1,7 +1,7 @@
import math
import cairo
from xmet.igra import IGRAReader
from xmet.units import rad, knots
from xmet.sounding import Sounding
WIND_SPEED_MAX = 140 # knots
@ -10,15 +10,6 @@ WIND_SPEED_STEP = 10
WIND_DIR_STEP = 30 # degrees
def radians(degrees: float) -> float:
return (degrees + 90) * (math.pi / 180.0)
def degrees(radians: float) -> float:
return (radians * (180.0 / math.pi)) - 90
def knots(ms: float) -> float:
return ms * 1.944
class Hodograph():
def __init__(self, width, height):
self.width = min(width, height)
@ -29,8 +20,8 @@ class Hodograph():
def sample_to_screen(self, wind_speed: dir, wind_dir: float) -> tuple:
r = self.radius * (wind_speed / WIND_SPEED_MAX)
x = self.radius + r * math.cos(radians(wind_dir))
y = self.radius + r * math.sin(radians(wind_dir))
x = self.radius + r * math.cos(rad(wind_dir))
y = self.radius + r * math.sin(rad(wind_dir))
if self.extents is None:
return x, y
@ -235,8 +226,6 @@ class Hodograph():
min_x, min_y = self.extents['min']
max_x, max_y = self.extents['max']
box = max(max_x - min_x, max_y - min_y)
for sample in self.each_significant_sample(sounding):
color = self.color(sample.height)

View file

@ -3,6 +3,7 @@ import math
from typing import Callable
from xmet.series import Series
from xmet.units import rad, kelvin, celsius
LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km
@ -11,12 +12,6 @@ PRESSURE_MSL = 1013.25
PRESSURE_MIN = 100
PRESSURE_STEP = 50
def kelvin(c: float) -> float:
return 273.15 + c
def celsius(k: float) -> float:
return k - 273.15
def virtual_temp(temp: float, dewpoint: float, pressure: float) -> float:
a = 7.5 * dewpoint
b = 237.3 + dewpoint
@ -194,3 +189,9 @@ def follow_saturated_mixing_ratio(temp: float, pressure: float, step: float=1.0)
p2 -= step
return series
def wind_u(speed: float, direction: float) -> float:
return speed * math.cos(rad(direction))
def wind_v(speed: float, direction: float) -> float:
return -speed * math.sin(rad(direction))

16
lib/xmet/units.py Normal file
View file

@ -0,0 +1,16 @@
import math
def deg(rad: float) -> float:
return (rad * (180.0 / math.pi)) - 90
def rad(deg: float) -> float:
return (deg + 90) * (math.pi / 180.0)
def knots(ms: float) -> float:
return ms * 1.944
def kelvin(c: float) -> float:
return 273.15 + c
def celsius(k: float) -> float:
return k - 273.15