-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAATC_Weather.py
27 lines (20 loc) · 1.21 KB
/
AATC_Weather.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
import pyowm, AATC_Coordinate, math,time,AATC_Config
##def Get_OWM():
## owm = pyowm.OWM('5b943c4857a45d75ef7ee9b301666fa8')
class OWM_Control:
def __init__(self):
self._owm = pyowm.OWM(AATC_Config.OWM_API_KEY)
def Get_Adjusted_Speed(self,CoordA,CoordB,Speed,At_Time = time.time()): #Calculate the estimated speed if wind is present (lower speed when moving into wind)
try:
forecast = self._owm.daily_forecast_at_coords(CoordA.Get_Y(),CoordA.Get_X())
wind = forecast.get_weather_at(int(At_Time)).get_wind()
bearing = AATC_Coordinate.GetBearing(CoordA,CoordB)
wind_bearing = AATC_Coordinate.Reverse_Angle(wind["deg"])
Vx = Speed*math.sin(AATC_Coordinate.toRadian(bearing))+ wind["speed"]*math.sin(AATC_Coordinate.toRadian(wind_bearing))
Vy = Speed*math.cos(AATC_Coordinate.toRadian(bearing))+ wind["speed"]*math.cos(AATC_Coordinate.toRadian(wind_bearing))
V = math.sqrt(Vx**2+Vy**2)
if V <= 0: #To prevent estimating negative speeds
V = 1
return V
except:
return Speed #If failure to connect return normal speed.