<jupyter_start><jupyter_text>Manhattan<jupyter_code># manhattan_graph = ox.graph_from_place('Manhattan', network_type='walk')
# ox.save_graphml(manhattan_graph, 'manhattan_graph.graphml')

manhattan_graph = ox.load_graphml('manhattan_graph.graphml')
gdf_manhattan = ox.gdf_from_place('Manhattan')
manhattan_sample = pd.read_csv('manhattan_sample.csv')
manhattan_stacked = F.stack_coordinates(manhattan_sample)
pts_manhattan = F.make_even_meshgrid(gdf_manhattan, spacing_lat=0.006, spacing_long=0.007)
nearest_nodes_manhattan = F.get_nearest_nodes(manhattan_graph, pts_manhattan)
F.plot_pts_on_graph(manhattan_graph, nearest_nodes_manhattan)
manhattan_sample[manhattan_sample['geo_dist'] < 500]
# manhattan_sample = F.distance_sample(manhattan_graph, nearest_nodes_manhattan)
# manhattan_sample_df = pd.DataFrame(manhattan_sample, columns = ['orig_lat', 'orig_long', 'nn_orig', 'dest_lat', 'dest_long', 'nn_dest', 'street_dist', 'geo_dist'])
# manhattan_sample_df['dist_ratio'] = manhattan_sample_df['street_dist'] / manhattan_sample_df['geo_dist']
# manhattan_sample_df.to_csv('manhattan_sample.csv', header=True, index=False)
F.histograms(manhattan_sample, ['street_dist', 'geo_dist', 'dist_ratio'])
F.plot_density(manhattan_stacked[['long', 'lat', 'dist_ratio']], title='bandwidth=0.0075, has_weight=True', base_plot=manhattan_graph, bandwidth=0.0075, has_weight=True, show=True)
# manhattan_stacked = F.stack_coordinates(manhattan_sample[(manhattan_sample['nn_orig'] != 371218803) & 
#                                                          (manhattan_sample['nn_orig'] != 3786876206)])
F.plot_density(manhattan_stacked[(manhattan_stacked['dist_ratio'] >= 1.5)
                                ]
               [['long', 'lat', 'dist_ratio']], title='bandwidth=0.0075, has_weight=True, dist_ratio >= 1.5', base_plot=manhattan_graph, bandwidth=0.0075, has_weight=True, show=True)<jupyter_output><empty_output><jupyter_text>Bucharest<jupyter_code># bucharest_graph = ox.graph_from_place('Bucharest', network_type='walk', which_result=2)
# ox.save_graphml(bucharest_graph, 'bucharest_graph.graphml')

bucharest_graph = ox.load_graphml('bucharest_graph.graphml')
gdf_buc = ox.gdf_from_place('Bucharest', which_result=2)
bucharest_sample = pd.read_csv('bucharest_sample.csv')
bucharest_stacked = F.stack_coordinates(bucharest_sample)
pts_buc = F.make_even_meshgrid(gdf_buc, spacing_lat=0.00675, spacing_long=0.0085, margins=[0.05, 0.0375, 0.025, 0.0375])
nearest_nodes_buc = F.get_nearest_nodes(bucharest_graph, pts_buc)
F.plot_pts_on_graph(bucharest_graph, nearest_nodes_buc)
# bucharest_sample = distance_sample(bucharest_graph, nearest_nodes_buc)
# bucharest_sample_df = pd.DataFrame(bucharest_sample, columns = ['orig_lat', 'orig_long', 'nn_orig', 'dest_lat', 'dest_long', 'nn_dest', 'street_dist', 'geo_dist', 'full_path'])
# bucharest_sample_df['geo_dist'] = bucharest_sample_df.apply(lambda x: great_circle_dist(bucharest_graph.nodes[x['nn_orig']], 
#                                                                               bucharest_graph.nodes[x['nn_dest']]), 
#                                                   axis=1)
# bucharest_sample_df['dist_ratio'] = bucharest_sample_df['street_dist'] / bucharest_sample_df['geo_dist']
# bucharest_sample_df.to_csv('bucharest_sample.csv', header=True, index=False)
F.histograms(bucharest_sample_df, ['street_dist', 'geo_dist', 'dist_ratio'])
plot_density(bucharest_stacked#[(bucharest_stacked['dist_ratio'] > 1.2) 
#                                (bucharest_stacked['geo_dist'] <= 2000)
             #                 ]
             [['long', 'lat', 'dist_ratio']], 
             title='', base_plot=bucharest_graph, bandwidth=0.0075, has_weight=False, show=True)
F.plot_density(bucharest_stacked[bucharest_stacked['geo_dist'] <= 3000][['long', 'lat', 'dist_ratio']], 
             title='', base_plot=bucharest_graph, bandwidth=0.0075, has_weight=True, show=True)
F.plot_density(bucharest_stacked[(bucharest_stacked['dist_ratio'] > 1.25) 
                                ][['long', 'lat', 'dist_ratio']], 
             title='bandwidth=0.0075, has_weight=True, dist_ratio > 1.25', base_plot=bucharest_graph, bandwidth=0.0075, has_weight=True, show=True)<jupyter_output><empty_output><jupyter_text>Amsterdam<jupyter_code># amsterdam_graph = ox.graph_from_place('Amsterdam', network_type='walk')
# ox.save_graphml(amsterdam_graph, 'amsterdam_graph.graphml')

amsterdam_graph = ox.load_graphml('amsterdam_graph.graphml')
gdf_amsterdam = ox.gdf_from_place('Amsterdam')
amsterdam_sample = pd.read_csv('amsterdam_sample.csv')
amsterdam_stacked = F.stack_coordinates(amsterdam_sample)
pts_amsterdam = F.make_even_meshgrid(gdf_amsterdam, spacing_lat=0.00675, spacing_long=0.0085, margins=[0.0, 0.0, 0.125, 0.05])
nearest_nodes_amsterdam = F.get_nearest_nodes(amsterdam_graph, pts_amsterdam)
F.plot_pts_on_graph(amsterdam_graph, nearest_nodes_amsterdam)
# amsterdam_sample = distance_sample(amsterdam_graph, nearest_nodes_amsterdam)
# amsterdam_sample_df = pd.DataFrame(amsterdam_sample, columns = ['orig_lat', 'orig_long', 'nn_orig', 'dest_lat', 'dest_long', 'nn_dest', 'street_dist', 'geo_dist'])
# amsterdam_sample_df['dist_ratio'] = amsterdam_sample_df['street_dist'] / amsterdam_sample_df['geo_dist']
# amsterdam_sample_df.to_csv('amsterdam_sample.csv', header=True, index=False)
F.histograms(amsterdam_sample_df, ['street_dist', 'geo_dist', 'dist_ratio'])
F.plot_density(amsterdam_stacked[['long', 'lat', 'dist_ratio']], title='bandwidth=0.0075, has_weight=False', base_plot=amsterdam_graph, bandwidth=0.0075, has_weight=False, show=True)
F.plot_density(amsterdam_stacked[
    (amsterdam_stacked['dist_ratio'] >= 1.5)
#     (amsterdam_stacked['geo_dist'] <= 2000) & 
#     (amsterdam_stacked['lat'] > 52.32)
][['long', 'lat', 'dist_ratio']], title='', base_plot=amsterdam_graph, bandwidth=0.0075, has_weight=True, show=True)<jupyter_output><empty_output><jupyter_text>----------------------------------------------------------------------------------------------<jupyter_code>origin_point = (40.861823, -73.924137)
destination_point = (40.858565, -73.923156)

origin_node = ox.get_nearest_node(manhattan_graph, origin_point)
destination_node = ox.get_nearest_node(manhattan_graph, destination_point)

route = nx.shortest_path(manhattan_graph, origin_node, destination_node, weight='length')
fig, ax = ox.plot_graph_route(manhattan_graph, route, origin_point=origin_point, destination_point=destination_point,  
                        axis_off=False, use_geom=False, show=False, close=False)

plt.show()
origin_point = (52.359266, 4.916046)
destination_point = (52.422185, 4.899023)

origin_node = ox.get_nearest_node(amsterdam_graph, origin_point)
destination_node = ox.get_nearest_node(amsterdam_graph, destination_point)

route = nx.shortest_path(amsterdam_graph, origin_node, destination_node, weight='length')
fig, ax = ox.plot_graph_route(amsterdam_graph, route, origin_point=origin_point, destination_point=destination_point,  
                        axis_off=False, use_geom=False, show=False, close=False)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14679415073115862, 'fraction_numerical': 0.03233970753655793, 'mean_word_length': 5.74218009478673, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '572883', 'license': 'MIT', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2479, 'n_words': 298, 'path': 'city_routes.ipynb', 'repo_name': 'traian-d/city_routes', 'size': '7112'}