In [1]:
import sys
sys.path.append('/Users/erickpeirson/tethne')
In [2]:
from tethne.persistence.hdf5.graphcollection import HDF5Graph
In [3]:
from networkx import Graph
In [4]:
import tables
In [5]:
from tethne.persistence.hdf5.util import get_h5file, get_or_create_group
In [6]:
h5file,a,b = get_h5file('test')
In [7]:
group = get_or_create_group(h5file, 'testgroup')
In [8]:
g = Graph()
In [9]:
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 [10]:
g.node[0]
Out[10]:
In [11]:
hg = HDF5Graph(h5file, group, 'test', g)
In [12]:
g.nodes(data=True)
Out[12]:
In [13]:
hg.nodes(data=True)
Out[13]:
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 [18]:
len(hg.edge)
Out[18]:
In [19]:
Out[19]:
In [29]:
g.edges(data=True)
Out[29]:
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 [ ]: