From 96e8df68311992f01a072e125a941f084a2dbc14 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Fri, 24 Jul 2020 17:04:59 +0200 Subject: [PATCH] Allow import of `report_graph` For `read_eddy_graph`. --- Analysis/report_graph.py | 68 +++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/Analysis/report_graph.py b/Analysis/report_graph.py index 3d5c21b0..5cb89ade 100755 --- a/Analysis/report_graph.py +++ b/Analysis/report_graph.py @@ -2,7 +2,6 @@ import networkx as nx import csv -import shapefile def read_eddy_graph(): G = nx.DiGraph() @@ -21,46 +20,49 @@ def read_eddy_graph(): return G -G = read_eddy_graph() -print("Number of nodes:", len(G)) -print("Number of edges:", G.number_of_edges()) -n1 = 0 -n2 = 0 -print("Merging:") +if __name__ == "__main__": + import shapefile -for n, d in G.in_degree(): - if d >= 1: - n2 += 1 - if d >= 2: print(list(G.predecessors(n)), "->", n) + G = read_eddy_graph() + print("Number of nodes:", len(G)) + print("Number of edges:", G.number_of_edges()) + n1 = 0 + n2 = 0 + print("Merging:") -print("---") -print("Splitting:") + for n, d in G.in_degree(): + if d >= 1: + n2 += 1 + if d >= 2: print(list(G.predecessors(n)), "->", n) -for n, d in G.out_degree(): - if d >= 1: - n1 += 1 - if d >= 2: print(n, "->", list(G.successors(n))) + print("---") + print("Splitting:") -print("---") -print("number of nodes with at least one successor =", n1) -print("number of nodes with at least one predecessor =", n2) + for n, d in G.out_degree(): + if d >= 1: + n1 += 1 + if d >= 2: print(n, "->", list(G.successors(n))) -my_subgraphs = {} + print("---") + print("number of nodes with at least one successor =", n1) + print("number of nodes with at least one predecessor =", n2) + + my_subgraphs = {} -for n in G: - if n[0] not in my_subgraphs: my_subgraphs[n[0]] = [] - my_subgraphs[n[0]].append(n) + for n in G: + if n[0] not in my_subgraphs: my_subgraphs[n[0]] = [] + my_subgraphs[n[0]].append(n) -A = nx.nx_agraph.to_agraph(G) + A = nx.nx_agraph.to_agraph(G) -for k, s in my_subgraphs.items(): - A.add_subgraph(s, rank="same") + for k, s in my_subgraphs.items(): + A.add_subgraph(s, rank="same") -sr = shapefile.Reader("SHP_triplet/extremum") + sr = shapefile.Reader("SHP_triplet/extremum") -for rec in sr.iterRecords(): - n = A.get_node((rec.date_index, rec.eddy_index)) - n.attr["shape"] = "box" + for rec in sr.iterRecords(): + n = A.get_node((rec.date_index, rec.eddy_index)) + n.attr["shape"] = "box" -A.write("eddy_graph.gv") -print('Created file "eddy_graph.gv".') + A.write("eddy_graph.gv") + print('Created file "eddy_graph.gv".') -- GitLab