processing
dsstools.processing
Layouter
create_layout(graph, seed=None, pos=None, **kwargs)
Create position dictionary according to set layout engine. Default layout is Spring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph object |
required |
seed
|
int
|
Set a default seed (default None) |
None
|
pos
|
Pre-populated positions |
None
|
Returns:
Type | Description |
---|---|
None
|
Dictionary of node and positions. |
read_from_file(filename, **kwargs)
Reads position from JSON file under filepath.
The following structure for the JSON is expected, where each key contains an array of length 2 containing the coordinates. Coordinates should be in the range [-1,1]:
{
"domain1": [-0.1467271130230262, 0.25512246449304427],
"domain2": [-0.3683594304205127, 0.34942480334119136],
}
This structure is generated through dsstools.Layouter().write_to_file()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
Union[Path]
|
Path to file to be read. |
required |
graph
|
Graph
|
|
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary of nodes and positions. |
read_from_graph(graph, pos_name=('x', 'y'))
Read positions from node attributes in the graph.
This is relevant when importing from Pajek or GEXF files where the positions are already set with another tool. Imported values are normalized onto [-1,1] in all directions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph object including the node attributes. |
required |
pos_name
|
tuple
|
Node attribute names to look for. These depend on the imported file format. |
('x', 'y')
|
Returns:
Type | Description |
---|---|
Dictionary of positions per Node. |
read_or_create_layout(filepath, graph, seed, overwrite=False, **kwargs)
Read positions from file. If non-existant create pos and write to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
Union[str, Path]
|
Filename to read positions from |
required |
graph
|
Graph
|
Graph object to update |
required |
overwrite
|
bool
|
Overwrite existing file (default False) |
False
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary of positions per Node. Will return an empty dict if creation |
dict
|
failed. |
calculate_betweenness_centrality(graph, name='_betweenness', **kwargs)
Updates the nodes in the graph with betweenness centrality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
nx.Graph The graph to calculate on. |
required |
name
|
str
|
Name of the centrality type. |
'_betweenness'
|
**kwargs
|
All arguments passed onto nx.betweenness_centrality (see https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.betweenness_centrality.html#betweenness-centrality) |
{}
|
Returns:
Type | Description |
---|---|
Graph including the closeness centrality. |
calculate_closeness_centrality(graph, name='_closeness', **kwargs)
Updates the nodes in the graph with closeness centrality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
nx.Graph The graph to calculate on. |
required |
name
|
str
|
Name of the centrality type. |
'_closeness'
|
**kwargs
|
All arguments passed onto nx.closeness_centrality (see https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.closeness_centrality.html#closeness-centrality) |
{}
|
Returns:
Type | Description |
---|---|
Graph including the betweenness centrality. |