Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UrbanAccess/Pandana network not working with Pandana nearest_pois query #24

Closed
stefancoe opened this issue May 2, 2017 · 4 comments
Closed

Comments

@stefancoe
Copy link

stefancoe commented May 2, 2017

Description of the bug

In the code below, I have successfully created a Pandana network from an integrated UrbanAccess network and everything seems to work when running a Pandana aggregate query. However, when running a nearest_pois query, the code crashes on the last line and provides the error message below, which seems to suggest that the set of coordinates I am using for the query is out of bounds. However, I am using the same set of coordinates for both queries and I have confirmed that the coordinates are within the bbox of the network. Edit- looking closer at libch.cpp- the error has to do with a data array not the bounding box.

At one point I was able to get the pois query to work, but it was with a Pandana network that had the default Oneway parameter set to True. I changed this to False, cleaned up the code a bit, and then it no longer worked. Even when reverting back, I was not able to get it to work again. I still have the working network saved and can provide it if it will help the troubleshooting process.

We are really excited about this library and have already made some cool maps with the aggregate function. Thanks!

-Stefan

GTFS feed or OSM data (optional)

GTFS:
https://file.ac/-LhHHOc0HaA/

Environment

  • Operating system:
    Windows

  • Python version:
    2.7

  • UrbanAccess version:

  • UrbanAccess required packages versions (optional):

Paste the code that reproduces the issue here:

import urbanaccess as ua
import pandas as pd
import pandana as pdna 

# GTFS
gtfs_df = ua.gtfs.load.gtfsfeed_to_df(r'D:\stefan\Isochrone\repository\gtfs\transit_agencies', 
                                      validation=False, verbose=True, 
                                      bbox=(-122.459702,47.480999,-122.224426,47.734138), 
                                      remove_stops_outsidebbox=True, 
                                      append_definitions=False)


ua_net = ua.gtfs.network.create_transit_net(gtfs_df, 
                                   day='monday', 
                                   timerange=["06:00:00","09:00:00"], 
                                   overwrite_existing_stop_times_int=False, 
                                   use_existing_stop_times_int=True, 
                                   save_processed_gtfs=False, 
                                   save_dir='data', 
                                   save_filename=None)

ua.gtfs.headways.headways(gtfs_df,["06:00:00","09:00:00"])

# OSM:
osm_data = ua.osm.load.ua_network_from_bbox(bbox=(-122.459702,47.480999,-122.224426,47.734138), 
                                           network_type='walk', 
                                           timeout=180, 
                                           memory=None, 
                                           max_query_area_size=2500000000L, 
                                           remove_lcn=True)

ua_net = ua.osm.network.create_osm_net(osm_edges=osm_data[1], osm_nodes=osm_data[0], travel_speed_mph=3, network_type='walk')

# Integrate the network
ua_integrated_net = ua.network.integrate_network(ua_net, 
                             headways=True, 
                             urbanaccess_gtfsfeeds_df=gtfs_df, 
                             headway_statistic='mean')

# I thought this was the fix when I got it to work:
ua.network._format_pandana_edges_nodes(ua_integrated_net.net_edges, ua_integrated_net.net_nodes)

# Create a pandana network
imp = pd.DataFrame(ua_integrated_net.net_edges['weight'])
net = pdna.network.Network(ua_integrated_net.net_nodes.x, ua_integrated_net.net_nodes.y, 
                                ua_integrated_net.net_edges.from_int, ua_integrated_net.net_edges.to_int, imp, False)

dist = 30

def assign_nodes_to_dataset(dataset, network, column_name, x_name, y_name):
    """Adds an attribute node_ids to the given dataset."""
    dataset[column_name] = network.get_node_ids(dataset[x_name].values, dataset[y_name].values)


# *******Code works for Pandana aggregate query:
coords_dict = [{'x' : -122.355, 'y' : 47.687, 'var' : 1}]
df = pd.DataFrame(coords_dict)
assign_nodes_to_dataset(df, net, 'node_ids', 'x', 'y')
net.set(df.node_ids, variable=df['var'], name='test') 
aggr = net.aggregate(distance = dist, type = 'sum', decay='flat', imp_name = 'weight', name='test')
newdf = pd.DataFrame({'test': aggr, "node_ids": aggr.index.values})
print len(newdf[(newdf.test==1)])


# *******Code crashes on Pandana nearest_pois query:
net.init_pois(1, dist, 1)
x = pd.Series(-122.355)
y = pd.Series(47.687)
# Set as a point of interest on the pandana network
net.set_pois('tstop', x, y)
# Find distance to point from all nodes, everything over max_dist gets a value of 99999
res = net.nearest_pois(dist, 'tstop', num_pois=1, max_distance=99999)

Paste the error message (if applicable):

[error [error src/contraction_hierarchies/src/libch.cpp[error src/contraction_hierarchies/src/libch.cpp:[error src/contraction_hierarchies/src/libch.cpp:[error src/contraction_hierarchies/src/libch.cpp:[error 368src/contraction_hierarchies/src/libch.cpp:] [error src/contraction_hierarchies/src/libch.cpp[error src/contraction_hierarchies/src/libch.cpp:368] [error POI Category is out of Boundssrc/contraction_hierarchies/src/libch.cpp:368
An internal error has occurred in the Interactive window.  Please restart Visual Studio.
[error src/contraction_hierarchies/src/libch.cpp:
The Python REPL process has exited
@stefancoe stefancoe changed the title UrbanAccess network not working with Pandana nearest_pois query UrbanAccess/Pandana network not working with Pandana nearest_pois query May 2, 2017
@sablanchard
Copy link
Contributor

Thank you Stefan, we will look into this later this week and get back to you on what we find.

@stefancoe
Copy link
Author

Sam- I realized I was not using the most current pandana version so I upgraded. The code runs now, but the nearest_poi returns a dataframe where none of the nodes are within 30 minutes. The aggregate query, however, does returns a dataframe that has nodes that are within 30 minutes. So there is still an issue.
This is the same thing that is happening here: UDST/pandana#73. So Maybe this should only be a pandana issue.

Thanks!

@kuanb
Copy link
Member

kuanb commented May 8, 2017

^ Sounds like the Pandana issue you created should cover the issue (since it deals with two pdna functions - nearest_poi and aggregate, rather than UrbanAccess functionality). Which you acknowledge in the above.

I'd also just mention that, looking through the Pandana issues, there have been some logged in the past that appear to deal with limitations on the operability of the library in a Windows environment, so it might be worth using a Linux environment and rerunning your code to see if that's the issue.

@sablanchard
Copy link
Contributor

closing this issue for now as its a pandana issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants