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 nodes j within the threshold at cost d and their weights w (1 without node_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 by w of 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; sample estimates 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 of weight; None for no limit.

  • weight (Literal['length_meter', 'time_min']) – Edge cost column: length_meter (metres, the default) or time_min (minutes).

  • beta (Union[float, Iterable[float], None]) – Decay rate of gravity, one value or one per threshold. By default 4 / 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 of nodes_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, as territory of 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. None uses every node.

  • seed (int | None) – Seed of the sample.

  • max_workers (int | None) – Number of threads; None uses all cores.

Return type:

DataFrame

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, beta or node_weights are invalid.