spacenet.node_metrics.eccentricity#

spacenet.node_metrics.eccentricity(spatial_network, nodes=None, edge_weight_name='Distance', add_as_node_label=False, node_label_name='eccentricity')#

Computes the eccentricity for the nodes in the spatial network. The eccentricity of a node is defined as the maximum distance from that node to any other node in the network. It provides a measure of how far a node is from the furthest node in the network, and can be used to identify nodes that are central or peripheral in terms of their distance to other nodes.

Parameters:
spatial_networkNetworkX graph

The spatial network for which to calculate the eccentricity.

nodeslist or np.ndarray, optional

The set of nodes to compute the eccentricity. Default is ‘None’, computing for all nodes.

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 eccentricity 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 eccentricity values if add_as_node_label is True. Default is ‘eccentricity’.

Returns:
eccentricity_valuesnp.ndarray

An array of eccentricity 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 eccentricity values were computed. The order of the nodes corresponds to the order of the values in the ‘eccentricity_values’ array.

Examples

You can compute the eccentricity of nodes in a spatial network using the eccentricity function. Below is an example of how to use this function to compute the eccentricity 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 eccentricity for all nodes and add as node label
ecc_vals,node_ids=sn.node_metrics.eccentricity(G,add_as_node_label=True,node_label_name='eccentricity')

# plot the spatial network with the node label 'eccentricity'
sn.utils.plot_spatial_network(G,node_label_name='eccentricity')