libpysal
libpysal copied to clipboard
[WIP] initial draft of network weights
this starts a new weights module that creates a neighbor relationship based on the shortest path through a pandana network.
Currently the weights are set to distance, so need to include some inverse distance weighting functions, but this is a start for generating feedback
Some thoughts about handling situations where the origin or destination dataframes are polygons rather than points.
Currently, I think the approach is to use the geometry centroid as the point geometry and snap that to the closest node of the network.
One can imagine other strategies that might be more appropriate in other cases. For example
- Using a representative point on the polygon instead of a centroid
- If the origin polygons have population like data and we can assume that data is uniform across the polygon, assigning some weighted fraction of the orgin polygon data to each network node that the polygon intersects.
It would be interesting to include a mechanism to specify different strategies for assigning polygon data to the network. Perhaps a function that can be passed into the from_dataframe function with a signature similar to
"""
parameters
--------------
polygon: The origin or destination polygon + properties as a Data Frame
intersecting_nodes: A list of nodes that intersect with the polygon
returns
---------
A DataFrame of the nodes to be used with an associated weight value
"""
def assign_polygon_data_to_network(polygon,intersecting_nodes):
return nodes, weights
An implementation of this function for centroid assignment would simply find the closest intersecting_node to the polygon centroid and return that with a weight of 1.
While an implementation for assigning equal weights for each of the intersecting nodes would return the list of intersecting_nodes with 1/len(intersecting_nodes) as the weights for each.
This probably isn't quite the right way to do this but hopefully gets across the idea and can spark some discussion.
Codecov Report
Merging #356 into master will decrease coverage by
0.91%. The diff coverage is12.22%.
@@ Coverage Diff @@
## master #356 +/- ##
==========================================
- Coverage 81.40% 80.48% -0.92%
==========================================
Files 117 118 +1
Lines 11920 12075 +155
==========================================
+ Hits 9703 9719 +16
- Misses 2217 2356 +139
| Impacted Files | Coverage Δ | |
|---|---|---|
| libpysal/weights/network.py | 11.23% <11.23%> (ø) |
|
| libpysal/weights/__init__.py | 100.00% <100.00%> (ø) |
|
| libpysal/cg/shapely_ext.py | 19.01% <0.00%> (-4.92%) |
:arrow_down: |
| libpysal/cg/locators.py | 60.26% <0.00%> (-0.29%) |
:arrow_down: |
| libpysal/io/util/tests/test_weight_converter.py | 16.12% <0.00%> (-0.18%) |
:arrow_down: |
| libpysal/cg/tests/test_rtree.py | 95.65% <0.00%> (-0.10%) |
:arrow_down: |
| libpysal/cg/tests/test_locators.py | 96.22% <0.00%> (-0.07%) |
:arrow_down: |
| libpysal/common.py | 82.69% <0.00%> (ø) |
|
| libpysal/cg/rtree.py | 91.64% <0.00%> (ø) |
|
| libpysal/cg/kdtree.py | 67.85% <0.00%> (ø) |
|
| ... and 97 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update f24ebba...e1269a6. Read the comment docs.
as @stuartlynn raises above, centroids are sketchy so will be cool to consider other options for attaching polys to the network
as @stuartlynn raises above, centroids are sketchy so will be cool to consider other options for attaching polys to the network
This is what I did my dissertation on (see pp2n). I am planning on making it part of spaghetti eventually. Definitely here, too, if desired.
@jGaboardi that looks great!
the error looks to be specific to windows/fiona/py3.6, but otherwise i think this is basically passing
the error looks to be specific to windows/fiona/py3.6, but otherwise i think this is basically passing
Yes, and I think specific to the feedstock. I opened an issue over there last week.
https://github.com/conda-forge/fiona-feedstock/issues/171
thanks to some fantastic help from the UDST folks, the next version of pandana will expose the vectorized range query, so this should reduce to a few lines of really fast code :). I'll take another pass once pandana 0.7 is out!