I am using Yed to paint some graphs as shown in the picture below. Is there a way I can use python to compute a Depth-First exploration on these?
I would like the algorithm to protocol the Edges he has traveled and the nodes he visited.
Example graph:
Edit:
I would like to use this method to record actions of people in a sports game. At first you start at a base/Root, then you can run or jump (c or d). Running brings you to point 2, jumping to point 5.
The result that I need then is:
1. root, ([c,2] ,[b,3]), Descript_3
2. root, ([c,2] ,[a,4]), Descript_4
3. root, ([c,2] ,[b,2], [a,4]), Descript_4
...
I am just using yed, so I can use a graphical interface. If there is something better in pure python, I am all up for it. But lets stick to yed for now. Can I get additional attributes to the nodes?
Edit:
Since I cannot get this thing to work for myself, I am setting a bounty for an example program. The example program should do the following:
1. Parse the graphml-File and build up the tree
2. Compute all Roundtrip-Path with Node-Coverage
3. write all paths into a table: Name of the node, Text on the arrow
From there I can figure the rest out myself. If its done by using librarys, then that's cool too, but I need to be able to extend it myself. I would also have it to be able to handle graphs, instead of trees.
You can use the networkx module (need to be installed pip install networkx). This module is a powerfull library for working with graphs. It can read the graphml format which yed produces and has algorithems for traversing a graph. Have a look at the documentation of it: networkx
Related
I am reading the source code of a game written in Python, which involves a lot of methods under many classes tangles together. I want to start with a graph which gives an overview of the whole package. Something like Class1.methodA uses Class2.methodA and Class2.methodC; Class2.methodC uses Class2.methodB.... And presented in a graph with nodes and arrows so that I can see the dependencies clearly.
I can certainly do that manually level by level, but that will take a lot of time and might mess up when it gets complex.
I've seen a tool called "snakefood" which visualize dependencies. I tried but failed (does not work for Python3? I am not sure why. And therefore also not sure if it is what I am looking for). Any suggestions?
I'm working on a problem where I have a bunch of directed graphs with a single source/sink for each and the edges are probabilistic connections (albeit with 90% of the nodes having only 1 input and 1 output). There also is a critical node in each graph and I'd like to determine if there is any way to traverse the graph that bypasses this node. Ideally I'd also like to enumerate the specific paths which would bypass this node. I've been able to import an example graph into NetworkX and can run some of the functions on the graph without difficulty, but I'm not sure if what I'm looking for is a common request and I just don't know the right terminology to find it in the help files, or if this is something I'll need to code by hand. I'm also open to alternative tools or methods.
First, you might want some way to quantify critical nodes. For that you can use some measure of centrality, probably betweenness centrality in your case. Read more here.
Next, if you know the two nodes you want to travel between you can use this as a kind of psuedocode to help you get there. You can also loop through all possible pairs of nodes that could be traveled through, but that might take a while.
import NetworkX as nx
important_nodes=[]#list of important nodes
paths = nx.all_simple_paths(G, source, target)
paths=list(paths)
#This is pseudocode, next four lines could be done with list comprehension
exclusive_paths=[]
for path in paths:
if important_nodes not in path:
exclusive_paths.append(path)
Read more on all_simple_paths here.
list comprehension might look like this
exclusive_paths=[x for x in paths if important_nodes not in x]
are there any tools or examples for how to visualize things like linked lists and decisions trees using matplotlib?
I ask because I wrote a linked list type of class (each node can have multiple inputs/outputs, and there's a class variable that stores node names), and want to visualize it. Unfortunately, my computer at work is locked down so much that I can't download other packages, so I've got to use whatever is on hand- which is matplotlib
I've started reading it, and if I do it by hand, I can probably make something that visualizes one-directional linked lists (just give it the root node, and plop down a square with text for each operation). But if there's branching, or multiple inputs into a node things get a bit more complicated- for example is it possible to expand a figure after creating it?
Yes, you can use networkx library and the draw_networkx method. There are plenty of examples on Stack Overflow. Here is one example: https://stackoverflow.com/a/52683100/6361531
I have just found out about GephiStreamer. https://pypi.python.org/pypi/GephiStreamer
Using this package one can send instructions from python to Gephi to create nodes and edges in Gephi.
# Create a node with a custom_property
node_a = graph.Node("A",custom_property=1)
# Create edge
edge_ab = graph.Edge(node_a,node_b,custom_property="hello")
stream.add_edge(edge_ab)
Similarly I want to do everything in Gephi through Python. Here is what I typically do.
ex:
steps:
load nodes
load edges
calculate betweeness centrality
change the size/color of nodes as per their centrality scores
change the graph layout (such as forceatlas2)
give the output graph
Below is the output I have got manually, but I want to produce the same by sending instructions from python to Gephi. Documentation doesn't tell anything beyond creating nodes, edges and graphs.
I have also found out about NetworKit. https://networkit.iti.kit.edu/data/uploads/docs/NetworKit-Doc/python/html/gephi.html
This is slightly better than gephistramer, but this requires python 3.4 or higher and most of the packages like pandas, numpy or sickit are in 2.7.
also Is there a way to send the file I have created in gephi back to python.
Please suggest.
PS: I have edited the entire question details so that it's easier to understand now (hopefully).
I found this question while looking for the answer myself. I picked Gephi as my visualizer and then wanted to build a graph that was well supported by the tool by pulling data from around my org with Python.
I found GephiStreamer and it looks a simple yet comprehensive way to build graphs in Gephi from an external python environment (command line, or IDE)
The other options at this point are:
The Gephi Python Scripting Console
Any Graph Lib that can export in a Gephi readable format
NetworkX
python-igraph
graph-tool
Any of the python GEFX writers (Google "python GEFX")
There is no simple answer to that. The people at the Facebook group might be knowing something but IMO the best way to do it would be to call the Gephi toolkit, i.e. the available jar, from jython, check here for an example use. The thing is that jython doesn't allow to install numpy and a series of other libraries but I guess you could get around this issue by piping the output of one script to the other or using a queue like Celery.
So I would write a script let's call it graph_construction.py that uses networkx, construct the graph and then write it in the standard output in gexf. Then I would write a second script, gephi.py that would execute things in gephi and let's say write the graph to a pdf and then do something like:
python graph_construction.py | jython gephi.py output.pdf
and pray for it to work.
I am a meteorologist, and lately I am trying to investigate the possibility of building my one sondes.
In order to do that, I have the following work plan :
I would like to generate 3D models pyformex. An alternative is openSCAD. But I start with pyformex - to generate simple cylindrical sonde shapes with associated extra features, e.g. intake tube or such.
Next, I will like to split it in Meshes, using PyDistMesh; as well as prepare a raytraced point cloud model with Xrt.
In the third step, I would like to perform the CFD works.
Now, my questions :
Are there some other simple Python Libraries to generate 3D models? I would like a very simple system, where i can issue commands like p = Parallelogram (length, height, width), or p.position(x,y,z) etc. It would be nice to have built in mouse interaction - that is, a built in drawing component, which I can use to display the model, and rotate/ zoom/pan with mouse.
Any other mesh generation tools?
For this step, I would need a multiphysics system. I tried to use OpenFOAM, it is too huge (to hack through). I have taken a look at SU2, but it seems to focus more on aerospace engineering, than Fluid Dynamics (I would like to simulate the flight of the sonde - which is closer to aerospace engineering, as well as the state of the atmosphere). Fluidity seems to suit my needs better, but I dont find a python fork thereof. So are there some general purpose, not too bloated up, multiphysics python library for geophysical and general hydrodynamic simulations? I have taken a look a MOOSE, also dont find a python binding for it.
Scientific visualization : Are there some 3 or 4 (or may be higher dimensional) visualization libraries? I would prefer to issue simple commands as Plot instead of first generating a window / form, and then putting the graphs on it, if possible.
FINALLY, and most importantly, if the same can be done by C++ or Fortan, or some other language besides java, I would also consider using those.
Have a look at http://freecadweb.org/. This seems to be under active development. It is a fairly complete open source CAD package written in python. I believe it also has tools for meshing.
For cfd, you might want to consider openfoam - http://www.openfoam.com/. This is an open source cfd package with the obligatory steep learning curve. There seem to be some python libraries to be available that link to it, however I'm not sure how active these are:
http://openfoamwiki.net/index.php/Contrib/PyFoam
http://pythonflu.wikidot.com/