Zum Inhalt

utils

dsstools.utils

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/.

filter_graph_labels(graph, keyword, by_domain=lambda : True, by_value=lambda : True)

Return filtered graph labels by keyword, domain and value.

Parameters:

Name Type Description Default
graph DiGraph

Graph where to get the node names from

required
keyword str

Keyword to be parsed by parse_keyword_arg()

required
by_domain function

Function to filter domains by. Should return True/False.

lambda : True
by_value function

Function to filter values by. Should return True/False.

lambda : True
Return

Returns key-value-iterator.

map_qualitative_colors(data)

Maps qualitative colors according to the given values onto a colormap.

Parameters:

Name Type Description Default
node_values dict

Dict with node names as keys and values to map as keys.

required

Returns:

Type Description
tuple[dict[str, str], list[Line2D]]

Dict of node names and HEX color mapping; legend handles

map_sequential_colors(data)

Maps qualitative colors according to the given values onto a colormap.

Parameters:

Name Type Description Default
node_values dict

Dict with node names as keys and values to map as keys.

required

Returns:

Type Description
tuple[dict[str, str], ScalarMappable]

Dict of node names and HEX color mapping; color map

parse_keyword_attribute(graph, keyword, search_edges=False)

Try to guess what size mapping the user wants by the given keyword.

Parameters:

Name Type Description Default
graph DiGraph

Graph

required
keyword (str, int)

keyword to look for.

required
search_edges bool

If to search in "edges" instead of nodes.

False

Returns:

Type Description
dict[str, float]

Dict of nodes and radii.

parse_keyword_colors(graph, keyword, search_edges=False)

Try to guess what color mapping the user wants by the given value.

Parameters:

Name Type Description Default
graph DiGraph

Graph

required
keyword (str, int)

keyword to look for. '[_,in,out]degree',

required
search_edges bool

If to search in "edges" instead of nodes.

False

Returns:

Type Description
tuple[dict[str, str], Union[list, ScalarMappable, None]]

Dict of Node and hex color; A list of handles, a colormap or None

parse_keyword_sizes(graph, keyword, size_range=settings.node_size_range, threshold=None, target_range=None, search_edges=False, scaling_function=lambda : x)

Try to guess what size mapping the user wants by the given keyword. Use for nodes, labels, and alpha

Parameters:

Name Type Description Default
graph DiGraph

Graph

required
keyword (str, int)

keyword to look for. '[_,in,out]degree',

required
size_range(tuple[int, int]

max and min values for scaling (out_range)

required
threshold(int)

cutoff value for values displayed using _percentile_dict

required
target_range

max and min values for scaling (in_range)

None
search_edges bool

If to search in "edges" instead of nodes.

False
scaling_function(float, float

lambda with function used for scaling

required

Returns:

Type Description
dict[str, float]

Dict of attributes and size or transparency value (float)

print_overview(graph)

Print a basic overview over the network to STDOUT.