Geometric generators for geometric graphs
When trying to run a simulation with a geometric graph generator as random_geometric_graph
and saving the output as gexf, next error is shown:
Traceback (most recent call last):
File "/home/tmendez/anaconda3/bin/soil", line 11, in <module>
sys.exit(main())
File "/home/tmendez/PycharmProjects/soil/soil/__init__.py", line 50, in main
simulation.run_from_config(args.file, dump=(not args.dry_run), results_dir=args.output)
File "/home/tmendez/PycharmProjects/soil/soil/simulation.py", line 255, in run_from_config
results = sim.run_simulation()
File "/home/tmendez/PycharmProjects/soil/soil/simulation.py", line 138, in run_simulation
return self.run()
File "/home/tmendez/PycharmProjects/soil/soil/simulation.py", line 141, in run
return list(self.run_simulation_gen())
File "/home/tmendez/PycharmProjects/soil/soil/simulation.py", line 148, in run_simulation_gen
res.dump_gexf(self.dir_path)
File "/home/tmendez/PycharmProjects/soil/soil/environment.py", line 230, in dump_gexf
nx.write_gexf(G, graph_path, version="1.2draft")
File "<decorator-gen-388>", line 2, in write_gexf
File "/home/tmendez/anaconda3/lib/python3.6/site-packages/networkx/utils/decorators.py", line 224, in _open_file
result = func(*new_args, **kwargs)
File "/home/tmendez/anaconda3/lib/python3.6/site-packages/networkx/readwrite/gexf.py", line 88, in write_gexf
writer.add_graph(G)
File "/home/tmendez/anaconda3/lib/python3.6/site-packages/networkx/readwrite/gexf.py", line 305, in add_graph
self.add_nodes(G, graph_element)
File "/home/tmendez/anaconda3/lib/python3.6/site-packages/networkx/readwrite/gexf.py", line 340, in add_nodes
node_data, default)
File "/home/tmendez/anaconda3/lib/python3.6/site-packages/networkx/readwrite/gexf.py", line 415, in add_attributes
for val, start, end in v:
TypeError: 'float' object is not iterable
A solution for this error could be iterating over the graph to change the name of the attribute and save it as viz:position
instead of pos
.
import networkx as nx
G = nx.random_geometric_graph(20,0.1)
for node in G.nodes():
G.node[node]['viz'] = {"position": {"x": G.node[node]['pos'][0], "y": G.node[node]['pos'][1], "z": 0.0}}
del (G.node[node]['pos'])
nx.write_gexf(G, 'path/to/file.gexf', version='1.2draft')