UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
387 stars 83 forks source link

Aggregate with exponential decay #127

Open rolocampusano opened 5 years ago

rolocampusano commented 5 years ago

Description of the bug

I'm creating a value of land access for each node where I want to sum de land area a node can access within 1000m with exponential distance decay. The data is summed from a grid cell so I first attach each grid centroid to the closest node and then sum from then. The network I'm using is obtain through the osm loader and the aggregation works just fine when I use linear decay but when I use exponential decay I get the following panda error.

ValueError: Length of passed values is 0, index implies 326262

Environment

Paste the code that reproduces the issue here:

x, y = grid_land_data.grid_index_x, grid_land_data.grid_index_y
grid_land_data["node_ids"] = network.get_node_ids(x, y)

network.set(grid_land_data["node_ids"], variable=grid_land_data['area_Parks'], name="area_Parks")
s = network.aggregate(1000, type='sum', decay='exponential', name="area_Parks")

Whole error message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-48-e2900f6bc766> in <module>
      4 for use in uses:
      5     network.set(grid_land_data["node_ids"], variable=grid_land_data['area_'+str(use)], name="area_"+str(use))
----> 6     s = network.aggregate(200, type=aggregation, decay=decay, name="area_"+str(use))
      7     s = pd.DataFrame(data = s.values, index=s.index)
      8 

~/.conda/envs/research/lib/python3.7/site-packages/pandana/network.py in aggregate(self, distance, type, decay, imp_name, name)
    351                                                                  imp_num)
    352 
--> 353         return pd.Series(res, index=self.node_ids)
    354 
    355     def get_node_ids(self, x_col, y_col, mapping_distance=None):

~/.conda/envs/research/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    297                         raise ValueError(
    298                             "Length of passed values is {val}, "
--> 299                             "index implies {ind}".format(val=len(data), ind=len(index))
    300                         )
    301                 except TypeError:

ValueError: Length of passed values is 0, index implies 326262
knaaptime commented 5 years ago

i meant to raise an issue earlier (especially because now I cant remember how I discovered the fix) but there's an error in the docs. To use exponential decay, I believe you have to use decay='exp' not exponential

rolocampusano commented 5 years ago

This is great. It worked! Should I change the issue so that there is a fix in the docs?

d-wasserman commented 1 year ago

This is still in the documentation. Would a PR be well received for a correction?