iduedu.centrality¶
- iduedu.centrality(urban_graph, measures=('reach', 'harmonic', 'gravity'), *, cutoffs=None, weight='length_meter', beta=None, node_weights=None, direction='from', area=None, sample=None, seed=0, max_workers=None)[source]¶
Centralities of the nodes of a graph within travel-cost thresholds.
Measures, for a node
i, the other nodesjwithin the threshold at costdand their weightsw(1 withoutnode_weights):reach:Σ w, how much is within the threshold;harmonic:Σ w / d, closeness that favours near nodes (nodes at cost 0 are left out);gravity:Σ w · exp(-beta · d), the same with an exponential decay;betweenness: how many shortest paths no longer than the threshold pass through the node, each weighted bywof both of its ends. A path shared by several equally short routes is split between them, end points are not counted, and on undirected graphs every pair of nodes counts once.
Reach, harmonic and gravity come from one cut-off search per reported node. Betweenness needs a search from every node of the graph, which takes much longer;
sampleestimates it from a random part of them.- Parameters:
urban_graph (
UrbanGraph) – Graph to measure.measures (
Iterable[str]) – Any of"reach","harmonic","gravity","betweenness".cutoffs (
Union[float,Iterable[float],None]) – Threshold or thresholds in the units ofweight;Nonefor no limit.weight (
Literal['length_meter','time_min']) – Edge cost column:length_meter(metres, the default) ortime_min(minutes).beta (
Union[float,Iterable[float],None]) – Decay rate ofgravity, one value or one per threshold. By default4 / threshold, which leaves a weight of 0.018 at the threshold; required when there is no threshold.node_weights (
str|Series|ndarray|None) – Weights of the nodes: a column ofnodes_gdf, a Series indexed by node id or an array in node order. Missing values count as 0.direction (
Literal['from','to']) – On directed graphs,"from"measures the way from the node to the others,"to"towards the node. Betweenness does not depend on it.area (
BaseGeometry|GeoSeries|GeoDataFrame|None) – Report only the nodes inside: a shapely geometry in EPSG:4326, asterritoryof the graph builders, or a GeoSeries / GeoDataFrame in any CRS. The searches still use the whole graph.sample (
int|None) – For betweenness, the number of randomly chosen source nodes; the result is scaled up to all nodes.Noneuses every node.max_workers (
int|None) – Number of threads;Noneuses all cores.
- Return type:
- Returns:
DataFrame indexed by node id with one column per measure and threshold, named
<measure>_<cutoff>(reach_400,betweenness_inf).- Raises:
ValueError – If a measure is unknown, or
cutoffs,betaornode_weightsare invalid.