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

Rename G to g and n to v

So the comparison with `segments.py` is easier.
parent 5583fa81
No related branches found
No related tags found
No related merge requests found
...@@ -4,34 +4,34 @@ import networkx as nx ...@@ -4,34 +4,34 @@ import networkx as nx
from networkx.drawing import nx_agraph from networkx.drawing import nx_agraph
import sys import sys
G = nx.read_edgelist(sys.argv[1], create_using = nx.DiGraph, nodetype = int) g = nx.read_edgelist(sys.argv[1], create_using = nx.DiGraph, nodetype = int)
nbunch = [] # list of nodes to remove nbunch = [] # list of nodes to remove
for n in G: G.nodes[n]["inst_eddies"] = [n] for v in g: g.nodes[v]["inst_eddies"] = [v]
# "inst_eddies" is the list of instantaneous eddies represented by a # "inst_eddies" is the list of instantaneous eddies represented by a
# node. At first, each node represents only itself. At the end of the # node. At first, each node represents only itself. At the end of the
# script, each node will be a segment and "inst_eddies" will contain # script, each node will be a segment and "inst_eddies" will contain
# the list of eddies in the segment. # the list of eddies in the segment.
for n in G: for v in g:
if G.in_degree[n] == 1: if g.in_degree[v] == 1:
n2 = next(G.predecessors(n)) n2 = next(g.predecessors(v))
if G.out_degree[n2] == 1: if g.out_degree[n2] == 1:
# n continues a segment, circumvent n: # v continues a segment, circumvent v:
nbunch.append(n) nbunch.append(v)
G.remove_edge(n2, n) g.remove_edge(n2, v)
for n3 in list(G.successors(n)): for n3 in list(g.successors(v)):
G.remove_edge(n, n3) g.remove_edge(v, n3)
G.add_edge(n2, n3) g.add_edge(n2, n3)
# Add the segments represented by n to the segments # Add the segments represented by v to the segments
# represented by n2: # represented by n2:
G.nodes[n2]["inst_eddies"] += G.nodes[n]["inst_eddies"] g.nodes[n2]["inst_eddies"] += g.nodes[v]["inst_eddies"]
G.remove_nodes_from(nbunch) g.remove_nodes_from(nbunch)
for k in sorted(G.nodes): print(k, G.nodes[k]) for k in sorted(g.nodes): print(k, g.nodes[k])
A = nx_agraph.to_agraph(G) A = nx_agraph.to_agraph(g)
A.write(sys.argv[2]) A.write(sys.argv[2])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment