diff --git a/Analysis/report_graph.py b/Analysis/report_graph.py index 3d5c21b053a1f121790930430e9e24fff654dedd..5cb89ade2dbd532152954f7f113b01efacc1a886 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".')