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

Import file

May be useful for comparison with `segments.py`.
parent c4a8b1d8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import networkx as nx
from networkx.drawing import nx_agraph
import sys
G = nx.read_edgelist(sys.argv[1], create_using = nx.DiGraph, nodetype = int)
nbunch = [] # list of nodes to remove
for n in G: G.nodes[n]["inst_eddies"] = [n]
for n in G:
if G.in_degree[n] == 1:
n2 = next(G.predecessors(n))
if G.out_degree[n2] == 1:
# n continues a segment, circumvent n
nbunch.append(n)
G.remove_edge(n2, n)
G.nodes[n2]["inst_eddies"] += G.nodes[n]["inst_eddies"]
for n3 in list(G.successors(n)):
G.remove_edge(n, n3)
G.add_edge(n2, n3)
G.remove_nodes_from(nbunch)
print(G.nodes.data())
A = nx_agraph.to_agraph(G)
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