Import multigraph into Gephi from GML format - networkx

I use NetworkX to create a set of nodes and edges and export them into GML format so that I can view them on Gephi 0.9.1 version. When I import the following GML:
graph [
multigraph 1
directed 0
node [
id 0
label 1
]
node [
id 1
label 2
]
edge [
source 0
target 1
key "rel2"
]
edge [
source 0
target 1
key "rel1"
]
]
Gephi shows the following popup:
It said Multi Graph: no while in the GML it is stated multigraph 1.
Gephi automatically merges the edges, and sets the weight to 2, as below:
How can I configure Gephi to read a multigraph? Should I change my GML or any settings in Gephi? Or it is a bug?

How can I configure gephi to read multigraph?
Parallel edges can not be displayed by Gephi (will be merged unconditionally).

Related

Analysing proportion land coverage per raster cell from polygon layers in QGIS

I want to analyse the proportion of land use coverage of 12 different land use categories per raster cell. I want to do this for areas where a little owl was seen (owl location, value 1 in binary model) and areas where no owl was seen (owl absent, value 0 in binary model).I have a polygon layer that contains all values 0 (all areas where no owl was seen) and one for all values 1 (all areas where an owl was seen).
How can I extract the information I need from the data I have? Should I convert the polygon layers to rasters for example?
Absence layer:
Presence layer:
And this is a short example of what I want the output to look like:

How to read a text file in netlogo with as many characters as the world has patches and give the imported information to the patches?

patches-own[ a ]
to startup
set a []
file-open "test.txt"
while [ not file-at-end? ] [
set a lput file-read a
]
file-close
end
this is how my code looks like (the important part for that problem).
I have a text file with as many characters as patches are exist:
[
1 2 3
4 5 6
7 8 9
]
I now want to give the information from the text-file to the patches of my world. so the first patch (upper left end) should get the information 1. It should be really easy but it does not work. The code is just my test, probably there is a way nicer way to do it. I hope this is specific enough. Would be great if you guys can help me, thanks a lot.
sort patches will create a list of patches from top left to bottom right (row-major order). Then, you can use foreach to iterate through the patches and file contents together:
(foreach (sort patches) a [ [p x] ->
ask p [
; do stuff with x
]
])

Netlogo export-world format

I have been experimenting trying to work out how does the export-world work, in particular how does the DRAWING section work.
I created the following code to experiment using the default environment size of max-pxcor and max-pycor of 16. If you run this code shown at the end of this post, each file produced will be 5 megabytes, so it is easy to use up over a gigabyte of data after a minute of running.
Anyway, my question is this: How does the DRAWING section work? I have seen that the first entry is at -16.4, 16.4. I have summarised some of my observations in the simple table below. The first column is how much the turtle has moved, while the second column shows partial output in the CSV file.
0.001 FF1D9F78
0.016 FF1D9F78FF1D9F78
0.093 FF1D9F78FF1D9F78FF1D9F78
I have also seen that the first entry is created when the turtle moves by 0.001.The second entry seems to happen when the turtle has moved by 0.016 and the third entry is 0.093.
I am trying to work out what the pattern could be, but there doesn't seem to be one. How much turtle movement does one of the entries represent in the CSV file?
Thanks.
---- The code is below.
globals
[
totalAmount
]
to setup
ca
crt 1
[
setxy -16.4 16.4
pd
set heading 90
set color turquoise
]
set totalAmount 0
end
to go
ask turtles
[
fd moveAmount
]
set totalAmount moveAmount + totalAmount
export
end
to export
let filetemp word "turtletest" totalAmount
let filename word filetemp ".csv"
;print filename
export-world filename
end
The drawing layer is just a bitmap – a grid of pixels. It doesn't know what turtles moved and how far, it only knows what pixels the turtles colored in while moving. Internally, it's a java.awt.image.BufferedImage with TYPE_INT_ARGB encoding.
It's written to an exported world file by this code:
https://github.com/NetLogo/NetLogo/blob/533131ddb63da21ac35639e61d67601a3dae7aa2/src/main/org/nlogo/render/TrailDrawer.java#L217-L228
where colors is the array of ints backing the BufferedImage, and toHexString just writes bytes as hexadecimal digits (code).
If your image is mostly black, you'll mostly see a bunch of 00 bytes in the file.
As for your non-zero bytes, it appears to me that FF1D9F78 is a pixel with alpha = FF (opaque), red = 29, green = 159, blue = 120. At least, I think that's the right interpretation? Is that plausible for what you're seeing on screen? Maybe the A-R-G-B bytes are in the reverse order? To double check it, I'd need to do export-view and then look at the resulting PNG file in a program that could tell me the RGB values of individual pixels -- I don't have such a program handy right now. But hopefully this'll put you on the right track.

How to add an annotation outside of a node in Graphviz' dot?

I am very new to Dot and trying to visualize a callgraph with Dot and Zest in Eclipse. And I would like to annotate nodes with kind of annotation (OK and Failed on the pic.).
Is there any common way to do this for Dot or Zest?
xlabel
Have a look at xlabel (external label).
main.dot
graph {
node [shape=square];
1 [xlabel="a"]
2 [xlabel="b"]
1 -- 2;
}
Convert:
dot -Tpng main.dot > main.png
Output:
Not sure however how easily you can control exact label placement with this method: even overlaps can happen by default. See:
Graphviz graph positioning xlabels
xlabels for nodes overlap with edges in dot
shape=record
I just tend to prefer the shape=record approach mentioned by https://stackoverflow.com/a/23031506/895245 or their generalization, HTML-like labels, as it makes it clearer what label belongs to each node:
graph {
rankdir=LR
node [shape=record];
1 [label="1|a"]
2 [label="2|b"]
1 -- 2;
}
Output:
TODO can you avoid typing 1 and 2 twice?
Tested on Ubuntu 16.10, graphviz 2.38.
It's not supported by the Zest rendering, but on the DOT level you could use record-based nodes:
rankdir=LR;
node [shape=record];
m1[label="void m1()|OK"];
m1[label="void m2()|Failed"];
For details see http://www.graphviz.org/doc/info/shapes.html#record

Networkx: Importing graph with node values and edges information

I am generating random Geometric graph using networkx. I am exporting all the node and edges information into file.
I want to generate the same graph by importing all the node and edges information from file.
Code to export the node values and edge information.
G=nx.random_geometric_graph(10,0.5)
filename = "ipRandomGrid.txt"
fh=open(filename,'wb')
nx.write_adjlist(G, fh)
nx.draw(G)
plt.show()
I am trying to export it with below code and trying to change the color of some nodes. But it is generating different graph.
filename = "ipRandomGrid.txt"
fh=open(filename, 'rb')
G=nx.Graph()
G=nx.read_adjlist("ipRandomGrid.txt")
pos=nx.random_layout(G)
nx.draw_networkx_nodes(G,pos,nodelist=['1','2'],node_color='b')
nx.draw(G)
plt.show()
How to generate the same graph with few changes in color of some nodes?
If I understand the problem you're having correctly, the trouble is here:
pos=nx.random_layout(G)
nx.draw_networkx_nodes(G,pos,nodelist=['1','2'],node_color='b')
nx.draw(G)
You create a random layout of the graph in the first line, and use it to draw nodes '1' and '2' in the second line. You then draw the graph again in the third line without specifying the positions, which uses a spring model to position the nodes.
Your graph has no extra nodes, you've just drawn two of them in two different positions. If you want to consistently draw a graph the same way, you need to consistently use the pos you calculated. If you want it to be the same after storing and reloading, then save pos as well.
The easiest way to store node position data for your case might be using Python pickles. NetworkX has a write_gpickle() function that will do this for you. Note that the positions are already available as node attributes when you generate a random geometric graph so you probably want to use those when drawing. Here is an example of how to generate, save, load, and draw the same graph.
In [1]: import networkx as nx
In [2]: G=nx.random_geometric_graph(10,0.5)
In [3]: pos = nx.get_node_attributes(G,'pos')
In [4]: nx.draw(G,pos)
In [5]: nx.write_gpickle(G,'rgg.gpl')
In [6]: H=nx.read_gpickle('rgg.gpl')
In [7]: pos = nx.get_node_attributes(H,'pos')
In [8]: nx.draw(H,pos)