spacenet.centrality.node_reach#
- spacenet.centrality.node_reach(spatial_network, nodes=None, max_distance=inf, edge_weight_name='Distance', add_as_node_label=False, node_label_name='node_reach')#
Computes the node reach centrality for the nodes in the spatial network. This is the proportion of nodes within the network that are reachable from a given node within a certain distance.
- Parameters:
- spatial_networkNetworkX graph
The spatial network for which to calculate the node reach centrality.
- nodeslist or np.ndarray, optional
The set of nodes to compute the centrality. Default is ‘None’, computing for all nodes.
- max_distancefloat, optional
The maximum distance to consider when computing the centrality. Only pairs of nodes that are within this distance of each other will be included in the computation. Default is np.inf (no limit).
- edge_weight_namestr, optional
The name of the edge attribute in the graph that corresponds to the distance between nodes. Default is ‘Distance’.
- add_as_node_labelbool, optional
Whether to add the computed centrality values as a node attribute in the spatial network. Default is False.
- node_label_namestr, optional
The name of the node attribute to which to add the computed centrality values if add_as_node_label is True. Default is ‘node_reach’.
- Returns:
- reach_valuesnp.ndarray
An array of node reach centrality values for the specified nodes in the spatial network. The order of the values corresponds to the order of the nodes in the ‘nodes’ parameter.
- nodesnp.ndarray
An array of the node ids for which the node reach centrality values were computed. The order of the nodes corresponds to the order of the values in the ‘reach_values’ array.
Examples
You can compute the node reach centrality of nodes in a spatial network using the node_reach function. Below is an example of how to use this function to compute the node reach centrality for all nodes in a spatial network generated from a set of points.
import spacenet as sn # Load the spiral dataset and extract the 'x' and 'y' columns as points spiral_data = sn.datasets.load_dataset('spiral') points = spiral_data[['x', 'y']].to_numpy() # generate a spatial network G = sn.utils.spatial_network_from_points(points,max_edge_distance=50) # compute the node reach for each node in the spatial network and add it as a node label node_reach_vals,node_ids=sn.centrality.node_reach(G,max_distance=200,add_as_node_label=True,node_label_name='node_reach') # plot the spatial network and with the node label 'node_reach' to visualise the node reach centrality values sn.utils.plot_spatial_network(G,node_label_name='node_reach')