-
Notifications
You must be signed in to change notification settings - Fork 1
/
InteractiveMapper.py
157 lines (129 loc) · 3.84 KB
/
InteractiveMapper.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
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
import plotly.express as px
import pandas as pd
import numpy as np
import pygrib
import matplotlib.pyplot as plt
import netCDF4
import plotly
import chart_studio.plotly as py
import plotly.offline as py_off
import plotly.graph_objs as go
import plotly.figure_factory as ff
print("reading gribs")
file = netCDF4.Dataset('http://nomads.ncep.noaa.gov:80/dods/gfs_0p25/gfs20200914/gfs_0p25_00z')
raw_lat = np.array(file.variables['lat'][:])
raw_lon = np.array(file.variables['lon'][:])
raw_wind = np.array(file.variables['gustsfc'][1, :, :])
raw_wind_u = np.array(file.variables['ugrd10m'][1,:,:])
raw_wind_v = np.array(file.variables['vgrd10m'][1,:,:])
file.close()
print("done reading gribs")
min_lat = 0
max_lat = 50
min_lon = 180
max_lon = 242
lat_to_use = np.argwhere((raw_lat >= min_lat) & (raw_lat <= max_lat))
min_row = int(lat_to_use[0])
max_row = int(lat_to_use[-1])
lon_to_use = np.argwhere((raw_lon >= min_lon) & (raw_lon <= max_lon))
min_col = int(lon_to_use[0])
max_col = int(lon_to_use[-1])
lat = raw_lat[lat_to_use].reshape(len(lat_to_use))
lon = raw_lon[lon_to_use].reshape(len(lon_to_use))
wind = raw_wind[min_row:max_row+1, min_col:max_col+1]
wind_u = raw_wind_u[min_row:max_row+1, min_col:max_col+1]
wind_v = raw_wind_v[min_row:max_row+1, min_col:max_col+1]
# wind_angle = np.zeros([len(wind), len(wind[0])])
# for i in range(0, len(wind_u)):
# for j in range (0, len(wind_v)):
# wind_angle[i][j] = 180 + math.degrees(math.atan2(raw_wind_u[i][j], raw_wind_v[i][j]))
# dead_wind = wind*1
#
# dead_min_row = 65
# dead_max_row = 90
# dead_min_col = 110
# dead_max_col = 115
#
# dead_wind[dead_min_row:dead_max_row, dead_min_col:dead_max_col] = 0.1
#
# dead_min_row = 85
# dead_max_row = 105
# dead_min_col = 125
# dead_max_col = 130
#
# dead_wind[dead_min_row:dead_max_row, dead_min_col:dead_max_col] = 0.1
#
# wind = dead_wind
wlat = []
wlon = []
wwind = []
for i in range(0, len(wind)):
for j in range(0, len(wind[0])):
wlat.append(lat[i])
wlon.append(lon[j])
wwind.append(wind[i][j])
weather_data = {"lat": wlat, "lon": wlon, "wind": wwind}
weather_df = pd.DataFrame(data=weather_data)
BOARD_ROWS = len(wind)
BOARD_COLS = len(wind[0])
board = np.zeros([BOARD_ROWS, BOARD_COLS])
#racemap = np.zeros([BOARD_ROWS, BOARD_COLS])
visited = []
racemap = []
route_file = './output/route_lr0.5_er0.8_r10000_gamma0.95_0914.csv'
route = pd.read_csv(route_file)
for i in range(0, len(route)-1):
for j in range(0, len(route.values[0])-1):
if route.values[i][j] > 0:
lati = lat[i]
lonj = lon[j]
val = route.values[i][j]
racemap.append((lati,lonj, val))
racemap_df = pd.DataFrame(racemap, columns = ["lat", "lon", "val"])
mapbox_access_token = open("mapbox_key.txt").read()
print("plotting!!")
fig = go.Figure()
fig.add_trace(go.Scattermapbox(
lon=weather_df.lon,
lat=weather_df.lat,
mode='markers',
text=weather_df.wind,
marker=dict(
size = 5,
cmax = 20,
cmin =0,
opacity = 0.1,
color = weather_df.wind,
showscale = True)))
fig.add_trace(go.Scattermapbox(
lon=racemap_df.lon,
lat=racemap_df.lat))
fig.update_layout(
autosize=True,
margin=dict(t=0, b=0, l=0, r=0),
mapbox={
'center': {'lon': 200, 'lat': 25},
'style': "open-street-map",
'center': {'lon': 200, 'lat': 25},
'zoom': 1,
'accesstoken': mapbox_access_token
})
fig.update_layout(geo=dict(lonaxis=dict(
showgrid=True,
gridwidth=1,
range=[min_lon + 10, max_lon + 30],
dtick=1
),
lataxis=dict(
showgrid=True,
gridwidth=1,
range=[min_lat, max_lat],
dtick=1
)))
# x, y = np.meshgrid(lon,lat)
#
# f = ff.create_quiver(x, y, wind_u, wind_v)
# f.show()
# To be able to see the plot while using pycharm
# fig.write_image('C:/Users/user/Desktop/test.png')
fig.show()