-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.py
More file actions
195 lines (177 loc) · 6.1 KB
/
weather.py
File metadata and controls
195 lines (177 loc) · 6.1 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from typing import List, Dict, Any
class WeatherProperty:
def __init__(self, dref: str, value):
"""
dref: dataref for xplane api
value: value corresponding to dref
"""
self.dref = dref
self.value = value
class ChangeMode(WeatherProperty):
def __init__(self, value: int):
"""
value: integer
0 = Rapidly Improving,
1 = Improving,
2 = Gradually Improving,
3 = Static,
4 = Gradually Deteriorating,
5 = Deteriorating,
6 = Rapidly Deteriorating
"""
super().__init__(dref="sim/weather/region/change_mode",
value=value)
"""
Clouds
- at most 3 cloud layers
"""
class CloudBaseMsl(WeatherProperty):
def __init__(self, value: List[float]):
"""
Base altitude (MSL in meters) of 3 cloud layers
"""
super().__init__(dref="sim/weather/region/cloud_base_msl_m",
value=value)
class CloudTopMsl(WeatherProperty):
def __init__(self, value: List[float]):
"""
Top altitude (MSL in meters) of 3 cloud layers
"""
super().__init__(dref="sim/weather/region/cloud_tops_msl_m",
value=value)
class CloudCoverage(WeatherProperty):
def __init__(self, value: List[float]):
"""
Coverage of 3 cloud layers (0-1 range)
How dense the clouds are
"""
super().__init__(dref="sim/weather/region/cloud_coverage_percent",
value=value)
class CloudType(WeatherProperty):
def __init__(self, value: List[float]):
"""
Type of 3 cloud layers.
Intermediate float values can be accepted
0 = Cirrus
1 = Stratus
2 = Cumulus
3 = Cumulo-nimbus
"""
super().__init__(dref="sim/weather/region/cloud_type",
value=value)
"""
Precipitation and Temperature
"""
class Precipitation(WeatherProperty):
def __init__(self, value: float):
"""
Degree of rain/snow falling (0-1 range)
"""
super().__init__(dref="sim/weather/region/rain_percent",
value=value)
class RunwayWetness(WeatherProperty):
def __init__(self, value: float):
"""
Degree of how wet the runway is (0-15 range)
Dry = 0,
wet(1-3),
puddly(4-6),
snowy(7-9),
icy(10-12),
snowy/icy(13-15)
"""
super().__init__(dref="sim/weather/region/runway_friction",
value=value)
class Temperature(WeatherProperty):
def __init__(self, value: float):
"""
Temperature at MSL(Mean Sea Level) (degree Celsius)
"""
super().__init__(dref="sim/weather/region/sealevel_temperature_c",
value=value)
"""
Wind
- at most 13 wind layers
Note that Xplane doesn't let you explicitly set the exact value of each property.
Xplane modifies the values based on physics engine.
Input at least 2 wind layers.
"""
class WindMsl(WeatherProperty):
def __init__(self, value: List[float]):
"""
MSL altitude of 13 wind layers (MSL meters)
wind layer should be atleast 1000ft apart
"""
super().__init__(dref="sim/weather/region/wind_altitude_msl_m",
value=value)
class WindDirection(WeatherProperty):
def __init__(self, value: List[float]):
"""
Direction of 13 wind layers (0-360 degrees)
"""
super().__init__(dref="sim/weather/region/wind_direction_degt",
value=value)
class WindSpeed(WeatherProperty):
def __init__(self, value: List[float]):
"""
Speed of 13 wind layers (>=0 m/s)
"""
super().__init__(dref="sim/weather/region/wind_speed_msc",
value=value)
class WindTurbulence(WeatherProperty):
def __init__(self, value: List[float]):
"""
Magnitude of turbulence (0-1) of 13 wind layers
"""
super().__init__(dref="sim/weather/region/turbulence",
value=value)
class WindShearDirection(WeatherProperty):
def __init__(self, value: List[float]):
"""
Wind shear direction (0-360 degrees) of 13 wind layers
"""
super().__init__(dref="sim/weather/region/shear_direction_degt",
value=value)
class WindShearMaxSpeed(WeatherProperty):
def __init__(self, value: List[float]):
"""
Max wind shear speed (m/s) of 13 wind layers
"""
super().__init__(dref="sim/weather/region/shear_speed_msc",
value=value)
class Weather:
def __init__(self,
change_mode: ChangeMode,
cloud_base_msl: CloudBaseMsl,
cloud_top_msl: CloudTopMsl,
cloud_coverage: CloudCoverage,
cloud_type: CloudType,
precipitation: Precipitation,
runway_wetness: RunwayWetness,
temperature: Temperature,
wind_msl: WindMsl,
wind_direction: WindDirection,
wind_speed: WindSpeed,
wind_turbulence: WindTurbulence,
wind_shear_direction: WindShearDirection,
wind_shear_max_speed: WindShearMaxSpeed):
self.change_mode = change_mode
# clouds
self.cloud_base_msl = cloud_base_msl
self.cloud_top_msl = cloud_top_msl
self.cloud_coverage = cloud_coverage
self.cloud_type = cloud_type
self.precipitation = precipitation
self.runway_wetness = runway_wetness
self.temperature = temperature
self.wind_msl = wind_msl
self.wind_direction = wind_direction
self.wind_speed = wind_speed
self.wind_turbulence = wind_turbulence
self.wind_shear_direction = wind_shear_direction
self.wind_shear_max_speed = wind_shear_max_speed
def serialize(self) -> Dict[str, Any]:
data = {}
for key, obj in self.__dict__.items():
data[key] = obj.value
return data