-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindshear.py
37 lines (26 loc) · 1.03 KB
/
windshear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
from aviation_weather.components import Component
from aviation_weather.components.wind import Wind
from aviation_weather.exceptions import WindShearDecodeError, WindDecodeError
class WindShear(Component):
def __init__(self, raw):
"""Parse `raw` to create a new WindShear object.
Args:
raw (str): The wind shear to be parsed.
Raises:
WindShearDecodeError: If `raw` could not be parsed.
"""
m = re.search(r"\bWS(?P<altitude>\d{3})/(?P<wind>.+)\b", raw)
if not m:
raise WindShearDecodeError("WindShear(%r) could not be parsed" % raw)
self.altitude = int(m.group("altitude")) * 100
try:
self.wind = Wind(m.group("wind"))
except WindDecodeError as e:
raise WindShearDecodeError("WindShear(%r) could not be parsed" % raw) from e
@property
def raw(self):
return "WS%(altitude)03d/%(wind)s" % {
"altitude": self.altitude // 100,
"wind": self.wind.raw
}