Skip to content
Snippets Groups Projects
Commit 96e8df68 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Allow import of `report_graph`

For `read_eddy_graph`.
parent a9687151
No related branches found
No related tags found
No related merge requests found
......@@ -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".')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment