generate_network#
- generate_network(domain, network_name='default_network', objects_as_nodes=None, include_boundaries=None, exclude_boundaries=None, boundary_exclude_distance=0, network_type='Delaunay', inverse_distance_function=None, min_edge_distance=0, max_edge_distance=inf, number_of_nearest_neighbours=10, store_network=True, n_jobs=1)#
Generate a spatial network using domain objects. The network can stored within the domain under a given name for future use. Nodes are indexed using Object ID for consistent querying
- Parameters:
- domainobject
The domain containing the objects to be used for network generation.
- network_namestr, optional
The name of the network, by default ‘default_network’.
- objects_as_nodesarray-like, query-like, or None, optional
The objects_as_nodes to select specific objects, by default None.
- include_boundariesarray-like, query-like, or None, optional
Boundaries to include in the analysis. Defaults to None.
- exclude_boundariesarray-like, query-like, or None, optional
Boundaries to exclude from the analysis. Defaults to None.
- boundary_exclude_distancefloat, optional
Buffer to exclude objects located within boundary_exclude_distance from the boundaries. Defaults to 0.
- network_typestr, optional
The type of network to generate. Options are ‘Delaunay’ (Delaunay triangulation), ‘KNN’ (K-nearest neighbour), ‘Proximity’ and ‘RNG’ (relative neighbourhood graph).
- inverse_distance_functioncallable, optional
Function to compute inverse distance, by default None.
- min_edge_distancefloat, optional
Minimum edge distance, by default 0.
- max_edge_distancefloat, optional
Maximum edge distance, by default np.inf.
- number_of_nearest_neighboursint, optional
Number of nearest neighbours for KNN. Only used for KNN networks, by default 10.
- store_networkbool, optional
Whether to store the network in the domain, by default True.
- n_jobsint, string, optional
Number of cores to use for parallelisation of object-object distance computations in proximity networks with shapes. n_jobs=1 computes without parallisation, n_jobs=-1 computes will all available cores. n_jobs=’auto’ set the n_jobs using the number of computations. Defaults to 1.
- Returns:
- networkx.Graph
The generated network. KNN networks will return a directed network (networkx.DiGraph).
- Raises:
- ValueError
If the network type is not implemented or if the objects_as_nodes is of incorrect type.
Notes
Delaunay networks estimates a natural geometric triangulation for pointclouds. In spatial applications, a Delaunay network approximates contact-based connectivity using only centroid data. See Delaunay networks for more information.
K-Nearest Neighbours (KNN) networks estimates the local connectivity of points in space by connecting any object to it’s k closest objects. See KNN networks for more information.
Proximity networks define connectivity purely by distance thresholds. See Proximity networks for more information.
Relative Neighbourhood Graph (RNG) esimtates the natural connectivity of points in space. MuSpAn implements the Urquhart approximation to the RNG for computational efficiency. See RNGs for more information.
If parallisation is producing a ValueError: cannot pickle ‘_thread._local’ object, this is likely due to the domain object not being serializable. In this case, add if __name__ == “__main__”: to the top of your script or you can set n_jobs=1 to disable parallisation.