processing
dsstools.processing
Copyright (C) 2024 dssTools Developers David Seseke david.seseke@uni-hamburg.de Katherine Shay katherine.shay@studium.uni-hamburg.de Professur Digitale Sozialwissenschaften Universität Hamburg.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Layouter
create_layout(graph, seed=None, **kwargs)
Create position dictionary according to set layout engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed |
|
None
|
|
graph |
DiGraph
|
Graph object |
required |
seed |
int
|
Set a default seed (default None) |
None
|
Returns: 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 |
DiGraph
|
|
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph |
Graph
|
Graph object including the node attributes. |
required |
pos_name |
tuple
|
Node attribute names to look for. This is often 'x' and 'y'. |
('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. |
SpringLayouter
Bases: Layouter
create_layout(graph, seed=None, pos=None, **kwargs)
Create position dictionary according to set layout engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph |
DiGraph
|
Graph object |
required |
seed |
int
|
Set a default seed (default None) |
None
|
pos |
Pre-populated positions |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of node and positions. |
calculate_betweenness_centrality(graph, **kwargs)
Updates the nodes in the graph with betweenness centrality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph |
Graph
|
nx.DiGraph The graph to calculate on. |
required |
**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, **kwargs)
Updates the nodes in the graph with closeness centrality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph |
Graph
|
nx.DiGraph The graph to calculate on. |
required |
**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. |