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]:
{'label': 'bob', 'size': 0.5}

In [11]:
hg = HDF5Graph(h5file, group, 'test', g)

In [12]:
g.nodes(data=True)


Out[12]:
[(0, {'label': 'bob', 'size': 0.5}), (1, {}), (2, {}), (5, {})]

In [13]:
hg.nodes(data=True)


Out[13]:
[(0, {'label': 'bob', 'size': 0.5}), (1, {}), (2, {}), (5, {})]

In [14]:
g.edges(data=True)


Out[14]:
[(0, 1, {}), (0, 5, {'girth': 'wtf', 'weight': 3}), (1, 2, {'weight': 5})]

In [15]:
hg.edges(data=True)


Out[15]:
[(0, 1, {}), (0, 5, {'girth': 'wtf', 'weight': 3}), (1, 2, {'weight': 5})]

In [16]:
hg.node[0]['asdf'] = 'wtf'

In [17]:
hg.node[0]


Out[17]:
{'label': 'bob', 'size': 0.5}

In [18]:
len(hg.edge)


Out[18]:
3

In [19]:



Out[19]:
4

In [29]:
g.edges(data=True)


Out[29]:
[(0, 1, {}), (0, 3, {'weight': 3}), (1, 2, {'weight': 5})]

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]:
(array([0, 0, 1, 1, 2, 3]),
 array([1, 3, 0, 2, 1, 0]),
 array([1, 2, 3, 4, 5, 6]))

In [16]:
A = coo_matrix(hg.edge.neighbors.K, (hg.edge.neighbors.I, hg.edge.neighbors.J))

In [25]:
A.data


Out[25]:
array([1, 2, 3, 4, 5, 6])

In [23]:
for i, n in g.edge.iteritems():
    for j, attr in n.iteritems():
        print i, j


0 1
0 3
1 0
1 2
2 1
3 0

In [23]:
zip(array(hg.edge.neighbors.I), array(hg.edge.neighbors.J))


Out[23]:
[(0, 1), (0, 3), (1, 0), (1, 2), (2, 1), (3, 0)]

In [26]:
B = A.tocsr()

In [27]:
B.nonzero()


Out[27]:
(array([0, 0, 0, 0, 0, 0], dtype=int32),
 array([0, 1, 2, 3, 4, 5], dtype=int32))

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_)


223 [0 0 1 1 2 3] [1 3 0 2 1 0]
229 [(0, 1), (0, 3), (1, 0), (1, 2), (2, 1), (3, 0)]
[(0, 1), (0, 3), (1, 0), (1, 2), (2, 1), (3, 0)]
[(0, 1), (0, 3), (1, 0), (1, 2), (2, 1), (3, 0)]

In [40]:
g.edges()


Out[40]:
[(0, 1), (0, 3), (1, 2)]

In [41]:
r_


Out[41]:
[(0, 3), (1, 2), (0, 1)]

In [17]:
list(numpy.array([2,3])).index(3)


Out[17]:
1

In [ ]: