diff --git a/lib/xmet/thermo.py b/lib/xmet/thermo.py index 02e800f..e14dfb6 100644 --- a/lib/xmet/thermo.py +++ b/lib/xmet/thermo.py @@ -3,7 +3,7 @@ import math from typing import Callable from xmet.series import Series -from xmet.units import rad, kelvin, celsius +from xmet.units import rad, deg, kelvin, celsius LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km @@ -196,3 +196,15 @@ def wind_u(speed: float, direction: float) -> float: def wind_v(speed: float, direction: float) -> float: return -speed * math.sin(rad(direction)) + +def wind_uv(speed: float, direction: float) -> float: + return ( + math.cos(rad(direction)) * speed, + math.sin(rad(direction)) * -speed + ) + +def wind_speed_dir(u: float, v: float) -> float: + return ( + math.sqrt(u**2 + v**2), + (180 - deg(math.atan2(v, u))) % 360 + )