In [8]:
import sys
sys.path.append('/Users/erickpeirson/tethne')
In [9]:
from tethne.persistence.hdf5.graphcollection import HDF5Graph, HDF5GraphCollection
In [10]:
from networkx import Graph
In [24]:
In [11]:
import tables
In [12]:
from tethne.persistence.hdf5.util import get_h5file, get_or_create_group
In [13]:
G = HDF5GraphCollection(None)
In [14]:
h5file,a,b = get_h5file('test')
In [15]:
group = get_or_create_group(h5file, 'testgroup')
In [16]:
g = Graph()
In [17]:
g.add_edge(0,1)
g.add_edge(1,2, weight=5)
g.add_edge(5,0, {'weight':3, 'girth':'wtf'})
g.add_node(0, {'size':0.5, 'label':'bob'})
In [20]:
g[0]
Out[20]:
In [19]:
hpath = '/var/folders/f9/g7lw23jx7z3fw72byy3l11p80000gn/T/tmpLV2uaP/test-4baf66ef-44f7-4470-82b9-4f719a3a83b8.h5'
In [16]:
h5file2 = tables.openFile(hpath, mode = 'a', title='test')
In [17]:
group2 = get_or_create_group(h5file2, 'testgroup')
In [18]:
hg2 = HDF5Graph(h5file2, group2, 'test', g)
In [23]:
hg2.edges(data=True)
Out[23]:
In [12]:
hg = HDF5Graph(h5file, group, 'test', g)
In [13]:
g.nodes(data=True)
Out[13]:
In [14]:
hg.nodes(data=True)
Out[14]:
In [14]:
g.edges(data=True)
Out[14]:
In [15]:
hg.edges(data=True)
Out[15]:
In [16]:
hg.node[0]['asdf'] = 'wtf'
In [17]:
hg.node[0]
Out[17]:
In [7]:
g[0]
In [18]:
len(hg.edge)
Out[18]:
In [19]:
import networkx as nx
In [23]:
nx.edge_betweenness_centrality(hg)
Out[23]:
In [21]:
for n in iter(hg.node):
print n
In [22]:
for n in g:
print n
for n in hg:
print n
In [15]:
from scipy.sparse import coo_matrix
In [20]:
array(hg.edge.neighbors.I), array(hg.edge.neighbors.J), array(hg.edge.neighbors.K)
Out[20]:
In [16]:
A = coo_matrix(hg.edge.neighbors.K, (hg.edge.neighbors.I, hg.edge.neighbors.J))
In [25]:
A.data
Out[25]:
In [23]:
for i, n in g.edge.iteritems():
for j, attr in n.iteritems():
print i, j
In [23]:
zip(array(hg.edge.neighbors.I), array(hg.edge.neighbors.J))
Out[23]:
In [26]:
B = A.tocsr()
In [27]:
B.nonzero()
Out[27]:
In [39]:
r = hg.edges()
r_ = []
while len(r) > 0:
t = r.pop()
t_ = (min(t), max(t))
if t_ not in r_:
r_.append(t_)
In [40]:
g.edges()
Out[40]:
In [41]:
r_
Out[41]:
In [17]:
list(numpy.array([2,3])).index(3)
Out[17]:
In [36]:
list(group._v_children.items()[0][1])[0]
Out[36]:
In [52]:
group._v_children.keys()
Out[52]:
In [21]:
import networkx as nx
In [22]:
nx.edge_betweenness(g)
Out[22]:
In [ ]: