def test_plots(): G = ox.graph_from_place('Piedmont, California, USA', network_type='drive', simplify=False) G2 = ox.simplify_graph(G, strict=False) # test getting colors co = ox.get_colors(n=5, return_hex=True) nc = ox.get_node_colors_by_attr(G2, 'osmid') ec = ox.get_edge_colors_by_attr(G2, 'length') # save a plot to disk as png fig, ax = ox.plot_graph(G, save=True, file_format='png') # save a plot to disk as svg G_simplified = ox.simplify_graph(G) fig, ax = ox.plot_graph(G_simplified, show=False, save=True, close=True, file_format='svg') G_projected = ox.project_graph(G_simplified) fig, ax = ox.plot_graph(G_projected) fig, ax = ox.plot_graph(G_projected, fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor='y', file_format='png', filename='x', dpi=180, annotate=True, node_color='k', node_size=5, node_alpha=0.1, node_edgecolor='b', node_zorder=5, edge_color='r', edge_linewidth=2, edge_alpha=0.1, use_geom=False, show=False, save=True, close=True) fig, ax = ox.plot_figure_ground(G=G_simplified, file_format='png') fig, ax = ox.plot_figure_ground(point=(33.694981, -117.841375), file_format='png') fig, ax = ox.plot_figure_ground(address='Denver, Colorado, USA', file_format='png')
def test_plots(): G = ox.graph_from_place('Piedmont, California, USA', network_type='drive', simplify=False) G2 = ox.simplify_graph(G, strict=False) # test getting colors co = ox.get_colors(n=5, return_hex=True) nc = ox.get_node_colors_by_attr(G2, 'osmid') ec = ox.get_edge_colors_by_attr(G2, 'length') # save a plot to disk as png fig, ax = ox.plot_graph(G, save=True, file_format='png') # save a plot to disk as svg G_simplified = ox.simplify_graph(G) fig, ax = ox.plot_graph(G_simplified, show=False, save=True, close=True, file_format='svg') G_projected = ox.project_graph(G_simplified) fig, ax = ox.plot_graph(G_projected) fig, ax = ox.plot_graph(G_projected, fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor='y', file_format='png', filename='x', dpi=180, annotate=True, node_color='k', node_size=5, node_alpha=0.1, node_edgecolor='b', node_zorder=5, edge_color='r', edge_linewidth=2, edge_alpha=0.1, use_geom=False, show=False, save=True, close=True) fig, ax = ox.plot_figure_ground(G=G_simplified, file_format='png') fig, ax = ox.plot_figure_ground(point=(33.694981, -117.841375), file_format='png') fig, ax = ox.plot_figure_ground(address='Denver, Colorado, USA', file_format='png')
def load_data(self, file_path, origin): r_earth = 6378137 mat_contents = sio.loadmat(file_path) array_mat = mat_contents var = array_mat['var_pred'] pol = array_mat['Y_pred'] coord = mat_contents['central_coord'] min0 = min(coord[0]) min1 = min(coord[1]) max0 = max(coord[0]) max1 = max(coord[1]) bottom_left = (min0, min1) bottom_right = (min0, max1) top_right = (max0, max1) top_left = (max0, min1) grid = nx.Graph() nodes_visualized = [] for n in range(len(coord)): # Origin[0] = lat Origin[1] = long new_latitude = origin[0] + (1*coord[n][0] / r_earth) * (180 / math.pi) new_longitude = origin[1] + (1*coord[n][1] / r_earth) * (180 / math.pi) / math.cos(new_latitude * math.pi / 180) print(str(new_latitude) + str(new_longitude)) nodes_visualized.append((new_latitude, new_longitude)) x, y, _, _ = utm.from_latlon(new_latitude, new_longitude) grid.add_node(n, lat=new_latitude, lon=new_longitude, pol=pol[n][-1], var=var[n][-1], y=y, x=x) for n, data in self.graph.nodes(data=True): node = self.graph.nodes()[n] # Returns the node attribute's dictionary. grid_copy = copy.deepcopy(grid) pol_var_dist = [] total_dist = 0.0 for grid_node in range(4): node_location, dist = ox.get_nearest_node(grid_copy, (node['y'], node['x']), method='euclidean', return_dist=True) print(dist) pol = grid_copy.node[node_location]['pol'] var = grid_copy.node[node_location]['var'] pol_var_dist.append((pol, var, dist)) total_dist += dist grid_copy.remove_node(node_location) summed_pol = 0.0 summed_var = 0.0 for m in range(4): summed_pol += (1 - (pol_var_dist[m][2] / total_dist)) * pol_var_dist[m][0] summed_var += (1 - pol_var_dist[m][2] / total_dist) * pol_var_dist[m][1] summed_var = summed_var / 3 summed_pol = summed_pol / 3 data['pol'] = summed_pol data['var'] = summed_var print("pol " + str(summed_pol)) print("finished") nc = ox.get_node_colors_by_attr(self.graph, 'pol', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(self.G, fig_height=6, node_zorder=2, edge_color='#dddddd', node_color=nc, use_geom=True, show=False, close=False) # node_color=nc for lat, long in nodes_visualized: ax.scatter(long, lat, c='red', alpha=0.1, s=2) ax.set_title("Imported FRF Pollution") plt.show()
def grid_weighting_nodes(self, meters, n): self.planner = randomplanner.planner(self.kalman.env) coords = self.env.grid_weight_nodes(self.north, self.south, self.east, self.west, meters, n) nc = ox.get_node_colors_by_attr(self.env.graph, 'grid_weight', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(self.env.G, fig_height=6, node_color=nc, node_zorder=2, edge_color='#dddddd', use_geom=True, show=False, close=False) for lat, long in coords: print("(" + str(lat) + ", " + str(long) +")") ax.scatter(long, lat, c='red', alpha=0.2, s=2) ax.set_title("Weighted nodes from Grid") plt.show()
def plot_node_elevation(self): G_proj = ox.project_graph(self.G) nc = ox.get_node_colors_by_attr(G_proj, 'elevation', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(G_proj, fig_height=6, node_color=nc, node_size=12, node_zorder=2, edge_color='#dddddd')
def grid_weighting_nodes_dist(self, meters, n, dist): self.planner = randomplanner.planner(self.kalman.env) coords = self.planner.grid_weight_nodes_max_dist(self.north, self.south, self.east, self.west, meters, n, dist) nc = ox.get_node_colors_by_attr(self.planner.graph, 'grid_weight', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(self.planner.env.G, fig_height=6, node_color=nc, node_zorder=2, edge_color='#dddddd', use_geom=True, show=False, close=False) for lat, long in coords: print("(" + str(lat) + ", " + str(long) +")") ax.scatter(long, lat, c='red', alpha=0.3, s=3) ax.set_title("Weighted nodes from Grid") for node in self.planner.graph.nodes(): lat = self.planner.env.G.node[node]['lat'] long = self.planner.env.G.node[node]['long'] data = self.planner.graph.node[node]['grid_weight'] print(str(long) + ", " + str(lat) + ", " + str(data)) ax.annotate(long, lat, str(data)) plt.show()
print('Average street grade in {} is {:.1f}%'.format(place, avg_grade*100)) med_grade = np.median(edge_grades) print('Median street grade in {} is {:.1f}%'.format(place, med_grade*100)) # In[24]: G_proj = ox.project_graph(G) # In[25]: nc = ox.get_node_colors_by_attr(G_proj, 'elevation', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(G_proj, fig_height=6, node_color=nc, node_size=12, node_zorder=2, edge_color='#dddddd') # In[46]: origin = ox.get_nearest_node(G, (42.3778, -72.5198)) destination = ox.get_nearest_node(G, (42.3898, -72.5283)) bbox = ox.bbox_from_point((42.384, -72.524), distance=1500, project_utm=True) # In[47]: def impedance(length, grade):
graph = ox.graph_from_place(place_query, network_type='all') ox.plot_graph(graph) # add elevation to each of the nodes, using the google elevation API, then calculate edge grades graph = ox.add_node_elevations(graph, api_key=apikey) graph = ox.add_edge_grades(graph) ''' Convert the network into nodes geodataframe and edges geodataframe respectively ''' nodes, edges = ox.graph_to_gdfs(graph, nodes=True, edges=True) # In[5]: ''' Convert into UTM format ''' graph_proj = ox.project_graph(graph) # get one color for each node, by elevation, then plot the network nc = ox.get_node_colors_by_attr(graph_proj, 'elevation', cmap='viridis', num_bins=20) fig, ax = ox.plot_graph(graph_proj, node_color=nc, node_zorder=2) plt.tight_layout() ''' Convert the projected network into nodes geodataframe and edges geodataframe respectively ''' nodes_proj, edges_proj = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True) # In[6]: # Find the elevation rises by multiplying edge length together with grade / slope for u, v, k, data in graph_proj.edges(keys=True, data=True): data['rise'] = data['length'] * data['grade'] # In[7]: '''Get the convex hull of the whole network system''' # region = edges.unary_union.convex_hull
G = ox.graph_from_bbox(north, south, east, west, network_type='drive', simplify=True, truncate_by_edge=True) env = PolEnv(G) kalman = kalman(env) kalman.wipe_initilize() kalman.update(500, (34.05, -117.0), 50) # bot right kalman.update(500, (34.05, -117.05), 100) # bot left nc = ox.get_node_colors_by_attr(env.graph, 'pol', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(kalman.env.graph, fig_height=6, node_color=nc, node_size=12, node_zorder=2, edge_color='#dddddd', use_geom=True) kalman.update(20, (34.025, -117.025), 100) nc = ox.get_node_colors_by_attr(kalman.env.graph, 'pol', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(env.graph, fig_height=6, node_color=nc,