Commit e2dfe3ce authored by dirk.wintergruen's avatar dirk.wintergruen
Browse files

unify attributes allows to define attributes wich can be overwritte.

parent b83e67e7
__version__ = ""
__version__ = ""
......@@ -775,7 +775,7 @@ class MultiLayerGraph(OrderedDict):
# data=[intralayer_trace,trace2]
self._multilayer_fig = go.Figure(data=data, layout=layout)
def unify_attributes(self):
def unify_attributes(self,allow_overwrite=[]):
adds the attributes of every node to every layer, if it exists there, creates also a unified node list.
......@@ -794,7 +794,7 @@ class MultiLayerGraph(OrderedDict):
for ln,gr in self.items():
for n in gr.vs:
for k, v in n.attributes().items():
if k == "id":
if k == "id" or k in allow_overwrite:
continue ## id is normally graph specific
if v and not v == "None":
oldValue = self._all_nodes[(n["label"], n["typ"])].get(k, None)
......@@ -806,9 +806,9 @@ class MultiLayerGraph(OrderedDict):
elif oldValue and not oldValue == v:
if float(oldValue) != float(v): # could just be the same value but different types - in the case of floats or ints
raise ValueError("layer %s not all values %s the same for: %s was (%s)" % (ln, k, n, oldValue))
raise ValueError("layer %s: not all values %s the same for: %s was (%s)" % (ln, k, n, oldValue))
raise ValueError("layer %s not all values %s the same for: %s was (%s)" % (ln,k, n, oldValue))
raise ValueError("layer %s: not all values %s the same for: %s was (%s)" % (ln,k, n, oldValue))
self._all_nodes[(n["label"], n["typ"])][k] = v
......@@ -938,7 +938,7 @@ class MultiLayerGraph(OrderedDict):
return self._ynws_multilayer_figs
def update_multilayer(self, v_attr_name=None):
def update_multilayer(self, v_attr_name=None,allow_overwrite=[]):
if v_attr_name is None:
......@@ -956,7 +956,7 @@ class MultiLayerGraph(OrderedDict):
logger.debug("Step2a: Unify attributes.")
logger.debug("Step3: Update all")
......@@ -4,6 +4,8 @@ from network_extensions import igraphx
from network_extensions.igraphx import multilayer
from network_extensions.igraphx.multilayer import MultiLayerGraph
import logging
logging.basicConfig(level = logging.DEBUG)
class TestMultiLayerGraph(TestCase):
def test_writeGraphsToFile(self):
......@@ -93,6 +95,25 @@ class TestMultiLayerGraph(TestCase):
with open("/tmp/out.tgz", "wb") as outf:
def test_filter_edge_by_vertices_ynw(self):
pt = "data/co-author-social_years_simplified_3.tgz"
with open(pt, "rb") as outf:
ynw_load = igraphx.loadGraphsFromFile(outf)
ynw = multilayer.MultiLayerGraph.YearNetwork()
ynw = ynw.filter_edge_by_vertices("MISNER Charles W.","MATZNER Richard A.")
def test_filter_edge_by_vertices(self):
ma = MultiLayerGraph.load("data/co_author.pickle")
ma2 = ma.filter_edge_by_vertices("USHAKOV Evgeny Alekseevich", "MINKEVICH Albert Vitoldovich")
ma2 = ma2.filter_edge_by_vertices("MINKEVICH Albert Vitoldovich", "USHAKOV Evgeny Alekseevich")
with open("/tmp/out.tgz", "wb") as outf:
with open("/tmp/in.tgz", "wb") as outf:
def test_filter(self):
ma = MultiLayerGraph.load("data/co_author.pickle")
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