Compare commits
5 commits
060d48e0cc
...
9d9cfab9e2
Author | SHA1 | Date | |
---|---|---|---|
9d9cfab9e2 | |||
a231954de1 | |||
1b7952b94e | |||
8e359850f7 | |||
35c8ee27b1 |
3 changed files with 26 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
import math
|
import math
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
from xmet.igra import IGRAReader
|
from xmet.units import rad, knots
|
||||||
from xmet.sounding import Sounding
|
from xmet.sounding import Sounding
|
||||||
|
|
||||||
WIND_SPEED_MAX = 140 # knots
|
WIND_SPEED_MAX = 140 # knots
|
||||||
|
@ -10,15 +10,6 @@ WIND_SPEED_STEP = 10
|
||||||
|
|
||||||
WIND_DIR_STEP = 30 # degrees
|
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():
|
class Hodograph():
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
self.width = min(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:
|
def sample_to_screen(self, wind_speed: dir, wind_dir: float) -> tuple:
|
||||||
r = self.radius * (wind_speed / WIND_SPEED_MAX)
|
r = self.radius * (wind_speed / WIND_SPEED_MAX)
|
||||||
|
|
||||||
x = self.radius + r * math.cos(radians(wind_dir))
|
x = self.radius + r * math.cos(rad(wind_dir))
|
||||||
y = self.radius + r * math.sin(radians(wind_dir))
|
y = self.radius + r * math.sin(rad(wind_dir))
|
||||||
|
|
||||||
if self.extents is None:
|
if self.extents is None:
|
||||||
return x, y
|
return x, y
|
||||||
|
@ -235,8 +226,6 @@ class Hodograph():
|
||||||
min_x, min_y = self.extents['min']
|
min_x, min_y = self.extents['min']
|
||||||
max_x, max_y = self.extents['max']
|
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):
|
for sample in self.each_significant_sample(sounding):
|
||||||
color = self.color(sample.height)
|
color = self.color(sample.height)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import math
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from xmet.series import Series
|
from xmet.series import Series
|
||||||
|
from xmet.units import rad, kelvin, celsius
|
||||||
|
|
||||||
LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km
|
LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km
|
||||||
|
|
||||||
|
@ -11,12 +12,6 @@ PRESSURE_MSL = 1013.25
|
||||||
PRESSURE_MIN = 100
|
PRESSURE_MIN = 100
|
||||||
PRESSURE_STEP = 50
|
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:
|
def virtual_temp(temp: float, dewpoint: float, pressure: float) -> float:
|
||||||
a = 7.5 * dewpoint
|
a = 7.5 * dewpoint
|
||||||
b = 237.3 + dewpoint
|
b = 237.3 + dewpoint
|
||||||
|
@ -194,3 +189,9 @@ def follow_saturated_mixing_ratio(temp: float, pressure: float, step: float=1.0)
|
||||||
p2 -= step
|
p2 -= step
|
||||||
|
|
||||||
return series
|
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
16
lib/xmet/units.py
Normal 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
|
Loading…
Add table
Reference in a new issue