core.geo_network¶
Provides classes for analyzing spatially embedded complex networks, handling multivariate data and generating time series surrogates.
-
class
pyunicorn.core.geo_network.
GeoNetwork
(grid, adjacency=None, edge_list=None, directed=False, node_weight_type='surface', silence_level=0)[source]¶ Bases:
pyunicorn.core.network.Network
Encapsulates a network embedded on a spherical surface.
Particularly adds more network measures and statistics based on the spatial embedding.
Variables: node_weight_type – (string) - The type of geographical node weight to be used. -
static
BarabasiAlbert
(n_nodes, n_links, grid, node_weight_type='surface', silence_level=0)[source]¶ Generates an undirected and spatially embedded Barabasi-Albert network.
Parameters: - n_nodes (int) – The number of nodes.
- n_links (int) – The number of links of the node that is added at each step of the growth process.
- grid (Grid object) – The Grid object describing the network’s spatial embedding.
- node_weight_type (str) – The type of geographical node weight to be
used (see
set_node_weight_type()
). - silence_level (int) – The inverse level of verbosity of the object.
Return type: Returns: the Barabasi-Albert network.
-
static
ConfigurationModel
(grid, degrees, node_weight_type='surface', silence_level=0)[source]¶ Generates an undirected and spatially embedded configuration model graph.
The configuration model gives a fully random graph with a given degree sequence degrees.
Note
The configuration model network is simplified to eliminate self-loops and multiple edges. This results in a model degree sequence differing (slightly) from the original one. To fully conserve the degree sequence, distribution, link density etc., random rewiring should be used (
Network.randomly_rewire()
).Example (Repeat creation of configuration model network from SmallTestNetwork until the number of links is the same as in the original network):
>>> n = 0 >>> while n != 7: ... net = GeoNetwork.ConfigurationModel( ... grid=Grid.SmallTestGrid(), ... degrees=GeoNetwork.SmallTestNetwork().degree(), ... silence_level=2) ... n = net.n_links >>> print(net.link_density) 0.4666666666666667
Parameters: - degrees (1D array [index]) – The original degree sequence.
- grid (Grid object) – The Grid object describing the network’s spatial embedding.
- node_weight_type (str) – The type of geographical node weight to be
used (see
set_node_weight_type()
). - silence_level (int) – The inverse level of verbosity of the object.
Return type: Returns: the configuration model network.
-
static
ErdosRenyi
(grid, n_nodes, link_probability=None, n_links=None, node_weight_type='surface', silence_level=0)[source]¶ Generates an undirected and spatially embedded Erdos-Renyi random graph
Any pair of nodes is connected with probability \(p\).
Example:
>>> print(GeoNetwork.ErdosRenyi( ... grid=Grid.SmallTestGrid(), n_nodes=6, n_links=5)) Generating Erdos-Renyi random graph with 6 nodes and 5 links... Setting area weights according to type surface... GeoNetwork: Network: undirected, 6 nodes, 5 links, link density 0.333. Geographical boundaries: time lat lon min 0.0 0.00 2.50 max 9.0 25.00 15.00
Parameters: - grid (
Grid
object) – TheGrid
object describing the network’s spatial embedding. - n_nodes (number > 0 (int)) – Number of nodes.
- link_probability (number from 0 to 1 (float), or None) – If not None, each pair of nodes is independently linked with this probability. (Default: None)
- n_links (number > 0 (int), or None) – If not None, this many links are assigned at random. Must be None if link_probability is not None. (Default: None)
- node_weight_type (str) – The type of geographical node weight to be
used (see
set_node_weight_type()
). - silence_level (int) – The inverse level of verbosity of the object.
Return type: Returns: the Erdos-Renyi random graph.
- grid (
-
static
Load
(filename_network, filename_grid, fileformat=None, silence_level=0, *args, **kwds)[source]¶ Return a GeoNetwork object stored in files.
Unified reading function for graphs. Relies on and partially extends the corresponding igraph function. Refer to igraph documentation for further details on the various reader methods for different formats.
This method tries to identify the format of the graph given in the first parameter and calls the corresponding reader method.
Existing node and link attributes/weights are also restored depending on the chosen file format. E.g., the formats GraphML and gzipped GraphML are able to store both node and link weights.
The remaining arguments are passed to the reader method without any changes.
Parameters: - filename_network (str) – The name of the file where the Network object is to be stored.
- filename_grid (str) – The name of the file where the Grid object is to be stored (including ending).
- fileformat (str) – the format of the file (if known in advance)
None
means auto-detection. Possible values are:"ncol"
(NCOL format),"lgl"
(LGL format),"graphml"
,"graphmlz"
(GraphML and gzipped GraphML format),"gml"
(GML format),"net"
,"pajek"
(Pajek format),"dimacs"
(DIMACS format),"edgelist"
,"edges"
or"edge"
(edge list),"adjacency"
(adjacency matrix),"pickle"
(Python pickled format). - silence_level (int) – The inverse level of verbosity of the object.
Return type: GeoNetwork object
Returns: GeoNetwork
instance.
-
static
SmallTestNetwork
()[source]¶ Return a 6-node undirected geographically embedded test network.
The test network consists of the SmallTestNetwork of the Network class with node coordinates given by the SmallTestGrid of the Grid class.
The network looks like this:
3 - 1 | | \ 5 - 0 - 4 - 2
Return type: GeoNetwork instance Returns: an instance of GeoNetwork for testing purposes.
-
__init__
(grid, adjacency=None, edge_list=None, directed=False, node_weight_type='surface', silence_level=0)[source]¶ Initialize an instance of GeoNetwork.
Parameters: - grid (
Grid
) – The Grid object describing the network’s spatial embedding. - adjacency (2D array (int8) [index, index]) – The network’s adjacency matrix.
- edge_list (array-like list of lists) – Edge list of the new network. Entries [i,0], [i,1] contain the end-nodes of an edge.
- directed (bool) – Determines, whether the network is treated as directed.
- node_weight_type (str) – The type of geographical node weight to be used.
- silence_level (int) – The inverse level of verbosity of the object.
- Possible choices for
node_weight_type
: - None (constant unit weights)
- “surface” (cos lat)
- “irrigation” (cos² lat)
- grid (
-
_calculate_general_average_link_distance
(adjacency, degrees, geometry_corrected=False)[source]¶ Return general average link distances (\(ALD\)).
This general method is called to calculate undirected average link distance, average in-link distance and average out-link distance.
The resulting sequence can optionally be corrected for biases in average link distance arising due to the grid geometry. E.g., for regional networks, nodes on the boundaries may have a bias towards larger values of \(ALD\), while nodes in the center have a bias towards smaller values of \(ALD\).
Parameters: - adjacency (2D array [index, index]) – The adjacency matrix.
- degrees (1D array [index]) – The degree sequence.
- geometry_corrected (bool) – Toggles geometry correction.
Return type: 1D array [index]
Returns: the general average link distance sequence.
-
_calculate_general_connectivity_weighted_distance
(adjacency, degrees)[source]¶ Return general connectivity weighted link distances (CWD).
This method is called to calculate undirected CWD, in-CWD and out-CWD.
Parameters: - adjacency (2D array [index, index]) – The adjacency matrix.
- degrees (1D array [index]) – The degree sequence.
Return type: 1D array [index]
Returns: the general connectivity weighted distance sequence.
-
area_weighted_connectivity
()[source]¶ Return area weighted connectivity (\(AWC\)).
It gives the fractional area of the network, a node is connected to. \(AWC\) is closely related to node splitting invariant degree
Network.nsi_degree()
with area as node weight.Example:
>>> r(GeoNetwork.SmallTestNetwork().area_weighted_connectivity()) array([ 0.4854, 0.499 , 0.3342, 0.3446, 0.5146, 0.1726])
Return type: 1D Numpy array [index] Returns: the area weighted connectivity sequence.
-
area_weighted_connectivity_cumulative_distribution
(n_bins)[source]¶ Return the cumulative area weighted connectivity distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). area_weighted_connectivity_cumulative_distribution( ... n_bins=4)[0]) array([ 1. , 0.8435, 0.5068, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the cumulative \(AWC\) distribution, statistical error, and lower bin boundaries.
-
area_weighted_connectivity_distribution
(n_bins)[source]¶ Return the area weighted connectivity frequency distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). area_weighted_connectivity_distribution(n_bins=4)[0]) array([ 0.1565, 0.3367, 0.3446, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the \(AWC\) distribution, statistical error, and lower bin boundaries.
-
average_distance_weighted_path_length
()[source]¶ Return average distance weighted path length.
Returns the average path length link-weighted by the angular great circle distance between nodes.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). average_distance_weighted_path_length()) 0.4985
Return type: number (float) Returns: the average distance weighted path length.
-
average_link_distance
(geometry_corrected=False)[source]¶ Return average link distances (undirected).
Note
Does not use directionality information.
Examples:
>>> r(GeoNetwork.SmallTestNetwork(). average_link_distance(geometry_corrected=False)) array([ 0.3885, 0.1943, 0.1456, 0.2433, 0.2912, 0.4847]) >>> r(GeoNetwork.SmallTestNetwork(). average_link_distance(geometry_corrected=True))[:-1] array([ 1.5988, 1.0921, 1.0001, 1.6708, 1.6384])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the average link distance sequence (undirected).
-
average_neighbor_area_weighted_connectivity
()[source]¶ Return average neighbor area weighted connectivity.
Note
Does not use directionality information.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). average_neighbor_area_weighted_connectivity()) array([ 0.3439, 0.3978, 0.5068, 0.4922, 0.4395, 0.4854])
Return type: 1D Numpy array [index] Returns: the average neighbor area weighted connectivity sequence.
-
boundary
(nodes, geodesic=True, gap=0.0)[source]¶ Return a list of ordered lists of nodes on the connected parts of the boundary of a subset of nodes and a list of ordered lists of (lat,lon) coordinates of the corresponding polygons
- EXPERIMENTAL! *
-
clear_cache
()[source]¶ Clean up cache.
Is reversible, since all cached information can be recalculated from basic data.
-
connectivity_weighted_distance
()[source]¶ Return undirected connectivity weighted link distances (CWD).
Note
Does not use directionality information.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). connectivity_weighted_distance()) array([ 0.0625, 0.0321, 0.0241, 0.0419, 0.05 , 0.0837])
Return type: 1D Numpy array [index] Returns: the undirected connectivity weighted distance sequence.
-
distance_weighted_closeness
()[source]¶ Return distance weighted closeness.
Returns the sequence of closeness centralities link-weighted by the angular great circle distance between nodes.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). distance_weighted_closeness()) array([ 2.2378, 2.4501, 2.2396, 2.4501, 2.2396, 1.1982])
Return type: 1D Numpy array [index] Returns: the distance weighted closeness sequence.
-
geographical_cumulative_distribution
(sequence, n_bins)[source]¶ Return a normalized geographical cumulative distribution.
Also return estimated statistical error and the lower bin boundaries.
This function counts which percentage of total surface area has a value of sequence larger or equal than the one bounded by a specific bin and NOT which number of nodes does so.
Note
Be aware that this method only returns meaningful results for regular rectangular grids, where the representative area of each node is proportional to the cosine of its latitude.
Example:
>>> net = GeoNetwork.SmallTestNetwork() >>> r(net.geographical_cumulative_distribution( ... sequence=net.degree(), n_bins=3)[0]) array([ 1. , 0.8435, 0.5068])
Parameters: - sequence (1D Numpy array [index]) – The input sequence (e.g., some local network measure).
- n_bins (number (int)) – The number of bins for histogram.
Return type: tuple of three 1D Numpy arrays [bin]
Returns: the cumulative geographical distribution, statistical error, and lower bin boundaries.
-
geographical_distribution
(sequence, n_bins)[source]¶ Return a normalized geographical frequency distribution.
Also return the estimated statistical error and lower bin boundaries.
This function counts which percentage of total surface area falls into a bin and NOT which number of nodes does so.
Note
Be aware that this method only returns meaningful results for regular rectangular grids, where the representative area of each node is proportional to the cosine of its latitude.
Example:
>>> net = GeoNetwork.SmallTestNetwork() >>> r(net.geographical_distribution( ... sequence=net.degree(), n_bins=3)[0]) array([ 0.1565, 0.3367, 0.5068])
Parameters: - sequence (1D Numpy array [index]) – The input sequence (e.g., some local network measure).
- n_bins (number (int)) – The number of bins for histogram.
Return type: tuple of three 1D Numpy arrays [bin]
Returns: the geographical distribution, statistical error, and lower bin boundaries.
-
inarea_weighted_connectivity
()[source]¶ Return in-area weighted connectivity.
It gives the fractional area of the netwerk that connects to a given node. For undirected networks, it calculates total area weighted connectivity.
Example:
>>> r(GeoNetwork.SmallTestNetwork().inarea_weighted_connectivity()) array([ 0.4854, 0.499 , 0.3342, 0.3446, 0.5146, 0.1726])
Return type: 1D Numpy array [index] Returns: the in-area weighted connectivity sequence.
-
inarea_weighted_connectivity_cumulative_distribution
(n_bins)[source]¶ Return the cumulative in-area weighted connectivity distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). inarea_weighted_connectivity_cumulative_distribution( ... n_bins=4)[0]) array([ 1. , 0.8435, 0.5068, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the cumulative in-\(AWC\) distribution, statistical error, and lower bin boundaries.
-
inarea_weighted_connectivity_distribution
(n_bins)[source]¶ Return the in-area weighted connectivity frequency distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). inarea_weighted_connectivity_distribution(n_bins=4)[0]) array([ 0.1565, 0.3367, 0.3446, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the in-\(AWC\) distribution, statistical error, and lower bin boundaries.
Return in-average link distances.
Return regular average link distance for undirected networks.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). inaverage_link_distance(geometry_corrected=False)) array([ 0.3885, 0.1943, 0.1456, 0.2433, 0.2912, 0.4847])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the in-average link distance sequence.
-
inconnectivity_weighted_distance
()[source]¶ Return in-connectivity weighted link distances (CWD).
Example:
>>> r(GeoNetwork.SmallTestNetwork(). inconnectivity_weighted_distance()) array([ 0.0625, 0.0321, 0.0241, 0.0419, 0.05 , 0.0837])
Return type: 1D Numpy array [index] Returns: the in-connectivity weighted distance sequence.
-
intotal_link_distance
(geometry_corrected=False)[source]¶ Return the sequence of in-total link distances for all nodes.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). intotal_link_distance(geometry_corrected=False)) array([ 0.1886, 0.097 , 0.0486, 0.0838, 0.1498, 0.0837])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the in-total link distance sequence.
-
link_distance_distribution
(n_bins, grid_type='spherical', geometry_corrected=False)[source]¶ Return the normalized link distance distribution.
Correct for the geometry of the embedding space by default.
Examples:
>>> GeoNetwork.SmallTestNetwork().link_distance_distribution( ... n_bins=4, geometry_corrected=False)[0] array([ 0.14285714, 0.28571429, 0.28571429, 0.28571429]) >>> GeoNetwork.SmallTestNetwork().link_distance_distribution( ... n_bins=4, geometry_corrected=True)[0] array([ 0.09836066, 0.24590164, 0.32786885, 0.32786885])
Parameters: - n_bins (int) – The number of bins for histogram.
- grid_type (str) – Type of grid, used for distance calculation, can take values “euclidean” and “spherical”.
- geometry_corrected (bool) – Toggles correction for grid geometry.
Return type: tuple of three 1D arrays [bin]
Returns: the link distance distribution, statistical error, and lower bin boundaries.
-
local_distance_weighted_vulnerability
()[source]¶ Return local distance weighted vulnerability.
Return the sequence of vulnerabilities link-weighted by the angular great circle distance between nodes.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). local_distance_weighted_vulnerability()) array([ 0.0325, 0.3137, 0.2056, 0.028 , -0.0283, -0.288 ])
Return type: 1D Numpy array [index] Returns: the local distance weighted vulnerability sequence.
-
local_geographical_clustering
()[source]¶ Return local geographical clustering.
Returns the sequence of local clustering coefficients weighted by the inverse angular great circle distance between nodes. This guarantees, that short links between spatially neighboring nodes in a triangle are weighted higher than long links between nodes that are spatially far away.
Uses a definition of weighted clustering coefficient introduced in [Holme2007].
Note
Experimental measure!
Example:
>>> r(GeoNetwork.SmallTestNetwork().local_geographical_clustering()) Calculating local weighted clustering coefficient... array([ 0. , 0.0998, 0.1489, 0. , 0.2842, 0. ])
Return type: 1D Numpy array (index) Returns: the local geographical clustering sequence.
-
local_tsonis_clustering
()[source]¶ Return local Tsonis clustering.
This measure of local clustering was introduced in [Tsonis2008a].
Return type: 1D Numpy array (index) Returns: the local Tsonis clustering sequence.
-
max_link_distance
()[source]¶ Return maximum angular geodesic link distances.
Note
Does not use directionality information.
Example:
>>> r(GeoNetwork.SmallTestNetwork().max_link_distance()) array([ 0.4847, 0.2911, 0.1938, 0.292 , 0.3887, 0.4847])
Return type: 1D Numpy array [index] Returns: the maximum link distance sequence.
-
max_neighbor_area_weighted_connectivity
()[source]¶ Return maximum neighbor area weighted connectivity.
Note
Does not use directionality information.
>>> r(GeoNetwork.SmallTestNetwork(). max_neighbor_area_weighted_connectivity()) array([ 0.5146, 0.5146, 0.5146, 0.499 , 0.499 , 0.4854])
Return type: 1D Numpy array [index] Returns: the maximum neighbor area weighted connectivity sequence.
-
nsi_connected_hamming_cluster_tree
(lon_closed=True, lat_closed=False, alpha=0.01)[source]¶ Perform NSI agglomerative clustering.
Minimize in each step the Hamming distance between the original and the clustered network, but only joins connected clusters.
Return c,h where c[i,j] = i iff node j is in cluster no. i, and 0 otherwise, and h is the corresponding list of total resulting relative Hamming distance between 0 and 1. The cluster numbers for all nodes and a k clusters solution is then c[:2*N-k,:].max(axis=0)
Parameters: - lon_closed (bool) – TODO
- lat_closed (bool) – TODO
- alpha (float) – TODO
Return type: TODO
Returns: TODO
-
outarea_weighted_connectivity
()[source]¶ Return out-area weighted connectivity.
It gives the fractional area of the netwerk that a given node connects to. For undirected networks, it calculates total area weighted connectivity.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outarea_weighted_connectivity()) array([ 0.4854, 0.499 , 0.3342, 0.3446, 0.5146, 0.1726])
Return type: 1D Numpy array [index] Returns: the out-area weighted connectivity sequence.
-
outarea_weighted_connectivity_cumulative_distribution
(n_bins)[source]¶ Return the cumulative out-area weighted connectivity distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outarea_weighted_connectivity_cumulative_distribution( ... n_bins=4)[0]) array([ 1. , 0.8435, 0.5068, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the cumulative out-\(AWC\) distribution, statistical error, and lower bin boundaries.
-
outarea_weighted_connectivity_distribution
(n_bins)[source]¶ Return the out-area weighted connectivity frequency distribution.
Also return estimated statistical error and lower bin boundaries.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outarea_weighted_connectivity_distribution(n_bins=4)[0]) array([ 0.1565, 0.3367, 0.3446, 0.1622])
Parameters: n_bins (number (int)) – The number of bins for histogram. Return type: tuple of three 1D Numpy arrays [bin] Returns: the out-\(AWC\) distribution, statistical error, and lower bin boundaries.
-
outaverage_link_distance
(geometry_corrected=False)[source]¶ Return out-average link distances.
Return regular average link distance for undirected networks.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outaverage_link_distance(geometry_corrected=False)) array([ 0.3885, 0.1943, 0.1456, 0.2433, 0.2912, 0.4847])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the out-average link distance sequence.
-
outconnectivity_weighted_distance
()[source]¶ Return out-connectivity weighted link distances (CWD).
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outconnectivity_weighted_distance()) array([ 0.0625, 0.0321, 0.0241, 0.0419, 0.05 , 0.0837])
Return type: 1D Numpy array [index] Returns: the out-connectivity weighted distance sequence.
-
outtotal_link_distance
(geometry_corrected=False)[source]¶ Return the sequence of out-total link distances for all nodes.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). outtotal_link_distance(geometry_corrected=False)) array([ 0.1886, 0.097 , 0.0486, 0.0838, 0.1498, 0.0837])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the out-total link distance sequence.
-
randomly_rewire_geomodel_I
(distance_matrix, iterations, inaccuracy)[source]¶ Randomly rewire the current network in place using geographical model I.
Geographical model I preserves the degree sequence (exactly) and the link distance distribution \(p(l)\) (approximately).
A higher
inaccuracy
in the conservation of \(p(l)\) will lead to- less deterministic links in the network and, hence,
- more degrees of freedom for the random graph and
- a shorter runtime of the algorithm, since more pairs of nodes eligible for rewiring can be found.
Example (The degree sequence should be the same after rewiring):
>>> _i() >>> net = GeoNetwork.SmallTestNetwork() >>> net.randomly_rewire_geomodel_I( ... distance_matrix=net.grid.angular_distance(), ... iterations=100, inaccuracy=1.0) # >>> net.degree() array([3, 3, 2, 2, 3, 1])
Parameters: - distance_matrix (2D Numpy array [index, index]) – Suitable distance matrix between nodes.
- iterations (number (int)) – The number of rewirings to be performed.
- inaccuracy (number (float)) – The inaccuracy with which to conserve \(p(l)\).
-
randomly_rewire_geomodel_II
(distance_matrix, iterations, inaccuracy)[source]¶ Randomly rewire the current network in place using geographical model II.
Geographical model II preserves the degree sequence \(k_v\) (exactly), the link distance distribution \(p(l)\) (approximately), and the average link distance sequence \(<l>_v\) (approximately).
A higher
inaccuracy
in the conservation of \(p(l)\) and \(<l>_v\) will lead to:- less deterministic links in the network and, hence,
- more degrees of freedom for the random graph and
- a shorter runtime of the algorithm, since more pairs of nodes eligible for rewiring can be found.
Parameters: - distance_matrix (2D Numpy array [index, index]) – Suitable distance matrix between nodes.
- iterations (number (int)) – The number of rewirings to be performed.
- inaccuracy (number (float)) – The inaccuracy with which to conserve \(p(l)\).
-
randomly_rewire_geomodel_III
(distance_matrix, iterations, inaccuracy)[source]¶ Randomly rewire the current network in place using geographical model III.
Geographical model III preserves the degree sequence \(k_v\) (exactly), the link distance distribution \(p(l)\) (approximately), and the average link distance sequence \(<l>_v\) (approximately). Moreover, degree-degree correlations are also conserved exactly.
A higher
inaccuracy
in the conservation of \(p(l)\) and \(<l>_v\) will lead to:- less deterministic links in the network and, hence,
- more degrees of freedom for the random graph and
- a shorter runtime of the algorithm, since more pairs of nodes eligible for rewiring can be found.
Parameters: - distance_matrix (2D Numpy array [index, index]) – Suitable distance matrix between nodes.
- iterations (number (int)) – The number of rewirings to be performed.
- inaccuracy (number (float)) – The inaccuracy with which to conserve \(p(l)\).
-
save
(filename_network, filename_grid=None, fileformat=None, *args, **kwds)[source]¶ Save the GeoNetwork object to files.
Unified writing function for graphs. Relies on and partially extends the corresponding igraph function. Refer to igraph documentation for further details on the various writer methods for different formats.
This method tries to identify the format of the graph given in the first parameter (based on extension) and calls the corresponding writer method.
Existing node and link attributes/weights are also stored depending on the chosen file format. E.g., the formats GraphML and gzipped GraphML are able to store both node and link weights.
The grid is not stored if the corresponding filename is None.
The remaining arguments are passed to the writer method without any changes.
Parameters: - filename_network (str) – The name of the file where the Network object is to be stored.
- filename_grid (str) – The name of the file where the Grid object is to be stored (including ending).
- fileformat (str) – the format of the file (if one wants to override
the format determined from the filename extension, or the filename
itself is a stream).
None
means auto-detection. Possible values are:"ncol"
(NCOL format),"lgl"
(LGL format),"graphml"
,"graphmlz"
(GraphML and gzipped GraphML format),"gml"
(GML format),"dot"
,"graphviz"
(DOT format, used by GraphViz),"net"
,"pajek"
(Pajek format),"dimacs"
(DIMACS format),"edgelist"
,"edges"
or"edge"
(edge list),"adjacency"
(adjacency matrix),"pickle"
(Python pickled format),"svg"
(Scalable Vector Graphics).
-
save_for_cgv
(filename, fileformat='graphml')[source]¶ Save the GeoNetwork and its attributes for the CGV visualization software.
The node coordinates are stored as node attributes by default, likewise angular link distances are stored as edge attributes by default. All additional node and link properties are also stored for visualization.
This format is intended for being used by the spatial graph visualization software CGV developed in Rostock (contact Thomas Nocke, nocke@pik-potsdam.de). By default, the file includes the latitude and longitude vectors as node properties, as well as the geodesic angular distance as an link property.
Parameters: - file_name (str) – The file name should end with ”.dot” or ”.gml”.
- fileformat (str) – The file format: “graphml” - GraphML format “graphmlz” - gzipped GraphML format “graphviz” - GraphViz format
-
set_node_weight_type
(node_weight_type)[source]¶ Set node weights for calculation of n.s.i. measures according to requested type.
- Possible choices for
node_weight_type
: - None (constant unit weights)
- “surface” (cos lat)
- “irrigation” (cos² lat)
Parameters: node_weight_type (str) – The type of geographical node weight to be used. - Possible choices for
-
set_random_links_by_distance
(a, b)[source]¶ Reassign links independently with link probability = \(exp(a + b*angular distance)\).
Note
Modifies network in place, creates an undirected network!
Example (Repeat until a network with 5 links is created):
>>> net = GeoNetwork.SmallTestNetwork() >>> while (net.n_links != 5): ... net.set_random_links_by_distance(a=0., b=-4.) >>> net.n_links 5
Parameters: - a (number (float)) – The a parameter.
- b (number (float)) – The b parameter.
-
shuffled_by_distance_copy
()[source]¶ Return a copy of the network where all links in each node-distance class have been randomly re-assigned.
In other words, the result is a random network in which the link probability only depends on the nodes’ distance and is the same as in the original network.
Return type: GeoNetwork Returns: the distance shuffled copy.
-
total_link_distance
(geometry_corrected=False)[source]¶ Return the sequence of total link distances for all nodes.
Note
Does not use directionality information.
Example:
>>> r(GeoNetwork.SmallTestNetwork(). total_link_distance(geometry_corrected=False)) array([ 0.1886, 0.097 , 0.0486, 0.0838, 0.1498, 0.0837])
Parameters: geometry_corrected (bool) – Toggles geometry correction. Return type: 1D array [index] Returns: the total link distance sequence.
-
static