Commit 957965b6 authored by dirk.wintergruen's avatar dirk.wintergruen
Browse files

more debug

parent 86660fe0
__version__ = "0.9.6.0"
__version__ = "0.9.6.3"
......@@ -117,6 +117,7 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
@returns vereinigten Graphen
"""
logger.debug("start union")
assert v_attr_name in g_1.vs.attribute_names(), "attribute must be in vertex attributelist of graph_1"
assert v_attr_name in g_2.vs.attribute_names(), "attribute must be in vertex attributelist of graph_2"
......@@ -144,6 +145,7 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
v_attr_1 = g_1.vs[v_attr_name]
v_attr_2 = g_2.vs[v_attr_name]
attrs = [x for x in g_1.es.attributes() if x != "weight"] #TODO have to deal with weights
attrs += [x for x in g_2.es.attributes() if x != "weight"]
attrs = list(set(attrs)) #make unique
......@@ -171,7 +173,8 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
#logger.debug("dict graph_merged %s:" % graph_merged.__dict__)
add_edges = defaultdict(defaultdict)
for a in attrs:
logger.debug("create add_edges dict")
for a in tqdm(attrs):
for (e,vs),edge in zip(mergedEdges.items(),graph_merged.es):
cnt = 0
for v in vs:
......@@ -187,7 +190,8 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
#graph_merged.es[a]=[mergedEdges[e][a] for e in mergedEdgesList]
for e,n_vs in add_edges.items():
logger.debug("now we add_edges")
for e,n_vs in tqdm(add_edges.items()):
for k,vs in n_vs.items():
d = {x:y for x,y in vs}
......@@ -206,8 +210,8 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
common_attrs = set(g_2.vs.attributes()).union(set(g_1.vs.attributes())).difference([v_attr_name])
logging.debug(common_attrs)
for attr_name_other in common_attrs:
logger.debug("now we attributes to nodes")
for attr_name_other in tqdm(common_attrs):
attr_other = dict()
if attr_name_other in g_2.vertex_attributes():
......@@ -222,6 +226,8 @@ def union(g_1, g_2, v_attr_name,e_attr_name = None, typ_field = None):
attrs_set = defaultdict(set)
dels = []
logger.debug("now we attributes to edges")
if e_attr_name is not None:
for e in graph_merged.es:
......@@ -558,7 +564,7 @@ def projectBipartiteProcess(data):
new_edge_attributes["m_e_%s" % k] = v
if safe:
add_edge_safe(ng, s_n["name"], e_n["name"], new_edge_attributes)
add_edge_safe(new_edges, s_n["name"], e_n["name"], new_edge_attributes)
else:
#ng.add_edge(s_n, e_n, **new_edge_attributes)
new_edges.append((s_n["name"], e_n["name"], new_edge_attributes))
......
......@@ -6,7 +6,8 @@ import plotly.graph_objs as go
import numpy as np
import igraph
def createSizeFromFunc(gr: igraph.Graph, func: str = "betweenness", min_size: float = 2, scale_size: float = 10) -> np.array:
def \
createSizeFromFunc(gr: igraph.Graph, func: str = "betweenness", min_size: float = 2, scale_size: float = 10) -> np.array:
"""
Creates an numpy array with sizes for each vertex in the graph.
......@@ -26,7 +27,7 @@ def createSizeFromFunc(gr: igraph.Graph, func: str = "betweenness", min_size: fl
return sizes
def createFigGraph(gr: igraph.Graph, title: str, hover_field: str = "label", sizes: object = 2, typ_field: str = None, pos: list = None) -> go.Figure:
def createFigGraph(gr: igraph.Graph, title: str, hover_field:str = "label", sizes: object = 2, typ_field: str = None, pos: list = None) -> go.Figure:
"""
create figure for plotly
......
......@@ -109,7 +109,11 @@ class MultiLayerGraph(OrderedDict):
a unconnected network of nodes.
:return: dict with name of the layer -> graph
"""
typs = set(self.vs[self._typ_field])
try:
typs = set(self.vs[self._typ_field])
except KeyError:
logger.error("Vertices have no attribute: %s" % self._typ_field)
logger.error("Field can be changed by changed the propertie '_typ_field'")
simpleLayers = {}
for t in typs:
......@@ -481,6 +485,7 @@ class MultiLayerGraph(OrderedDict):
continue
if len(gr.vs) > 0:
multi_layer = igraphx.union(multi_layer, gr, v_attr_name=v_attr_name, typ_field=None)
##TODO unterscheide label in different layers
multi_layer._components.add(k)
logging.debug("added: %s" % multi_layer._components)
else:
......@@ -906,7 +911,24 @@ class MultiLayerGraph(OrderedDict):
bipartite=False,
years_selected=None,
only_in_layer=False,
disable=True):
disable=True,
merged_years = None):
"""
:param name:
:param layers:
:param func:
:param size_mult:
:param size_offset:
:param bipartite:
:param years_selected:
:param only_in_layer:
:param disable:
:param merged_years:
:return:
"""
figs = {}
if logger.getEffectiveLevel() >= logging.DEBUG:
......@@ -914,7 +936,12 @@ class MultiLayerGraph(OrderedDict):
else:
disable = disable
# print(logger.level,logging.DEBUG)
for y, nw in tqdm(self._ynws.items(), disable=disable):
if not merged_years:
ynw = self._ynws
else:
ynw = self.merged_ynws[merged_years].ynws
for y, nw in tqdm(ynw.items(), disable=disable):
if years_selected and not y in years_selected:
logger.info("skip: %s"%y)
continue
......@@ -1051,15 +1078,26 @@ class MultiLayerGraph(OrderedDict):
return ynw
def createFigLayeredGraphBip(self, name, layers, sizes, only_in_layer=False, scale_positions=True, layer_typ={}, nolines = False):
def createFigLayeredGraphBip(self, name, layers, sizes,
only_in_layer=False,
scale_positions=True,
layer_typ={},
nolines = False,
poss_layers = None,
colors_layers = None):
layer_graphs = self
pos_ml = self.multi_layer.layout_fruchterman_reingold()
poss = {}
if only_in_layer:
for l, gr in self.items():
poss[l] = gr.layout_fruchterman_reingold()
if not poss_layers:
poss[l] = gr.layout_fruchterman_reingold()
else:
poss = poss_layers
if scale_positions:
poss_neu = {}
......@@ -1297,9 +1335,9 @@ class MultiLayerGraph(OrderedDict):
Yn = []
Zn = []
text = []
scale = []
color_scale = []
for l in range(0, len(layer), 10): # color will repeat every 10 layers
scale += colorlover.scales['10']["qual"]["Paired"]
color_scale += colorlover.scales['10']["qual"]["Paired"]
color = []
......@@ -1335,7 +1373,14 @@ class MultiLayerGraph(OrderedDict):
Zn += [layer for k in pos_tmp]
# text += gr.vs["label"]
text += text_temp
color += [scale[layers.index(layer)] for x in pos_tmp]
if layer in colors_layers:
assert len(colors_layers[layer]) == len(pos_tmp), "length (%s) of colors_layers[%s] not the same as the number of nodes (%s)!" % (layer.len(colors_layers[layer]),
layer,
len(pos_tmp))
color += colors_layers[layer]
else:
color += [color_scale[layers.index(layer)] for x in pos_tmp]
if isinstance(sizes, dict):
sizes_joined = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment