11import numpy as np
22
3+ from ._kernel import _kernel_functions
34from ._utils import _induce_cliques , _validate_geometry_input
45
56
@@ -61,7 +62,7 @@ def pdna_to_adj(origins, network, node_ids, threshold):
6162 return adj
6263
6364
64- def build_travel_graph (df , network , threshold , mapping_distance ):
65+ def build_travel_graph (df , network , threshold , mapping_distance , kernel = None ):
6566 """Compute the shortest path between gdf centroids via a pandana.Network
6667 and return an adjacency list with weight=cost. Note unlike distance_band,
6768 :math:`G_{ij}` and :math:`G_{ji}` are often different because travel networks
@@ -81,6 +82,11 @@ def build_travel_graph(df, network, threshold, mapping_distance):
8182 snapping tolerance passed to ``pandana.Network.get_node_ids`` that defines
8283 the maximum range at which observations are snapped to nearest nodes in the
8384 network. Default is None
85+ kernel : str
86+ kernel transformation applied to the weights. See
87+ libpysal.graph.Graph.build_kernel for more information on kernel
88+ transformation options. Default is None, in which case the Graph weight
89+ is pure distance between focal and neighbor
8490
8591 Returns
8692 -------
@@ -118,4 +124,11 @@ def build_travel_graph(df, network, threshold, mapping_distance):
118124 .reset_index ()
119125 )
120126
127+ if callable (kernel ):
128+ adj_cliques ["weight" ] = kernel (adj_cliques ["weight" ], threshold )
129+ else :
130+ adj_cliques ["weight" ] = _kernel_functions [kernel ](
131+ adj_cliques ["weight" ], threshold
132+ )
133+
121134 return adj_cliques
0 commit comments