In [1]:
%load_ext autoreload
%autoreload 2
import numpy as np
import graph_tool.all as gt
import pandas as pd
import hdfgraph
import pandas.util.testing as tm
In [2]:
graph, pos = gt.triangulation(np.random.random((10, 2)) * 4, type="delaunay")
ixs, wys = gt.ungroup_vector_property(pos, [0, 1])
graph.vertex_properties['ixs'] = ixs
graph.vertex_properties['wys'] = wys
dist = graph.new_edge_property('double')
for e in graph.edges():
dist[e] = np.hypot(ixs[e.target()] - ixs[e.source()],
wys[e.target()] - wys[e.source()])
graph.edge_properties['dist'] = dist
short_edges = graph.new_edge_property('bool')
short_edges.a = dist.a < dist.a.mean()
graph.edge_properties['short_edges'] = short_edges
In [3]:
%pdb
In [4]:
with pd.get_store('io_test.h5') as store:
for key in store.keys():
store.remove(key)
In [5]:
vertex_df, edge_df = hdfgraph.graph_to_dataframes(graph, stamp=0)
In [6]:
hdfgraph.frames_to_hdf(vertex_df, edge_df, 'io_test.h5', reset=True)
In [7]:
vertex_df, edge_df = hdfgraph.frames_from_hdf('io_test.h5', stamp=0)
In [8]:
hdfgraph.graph_to_hdf(graph, 'io_test.h5', stamp=1, reset=True)
In [17]:
graph_out = hdfgraph.graph_from_hdf('io_test.h5', stamp=1)
In [18]:
dif = graph_out.edge_properties['dist'].a - graph.edge_properties['dist'].a
In [19]:
dif
Out[19]:
In [15]:
with pd.get_store('io_test.h5') as store:
edge = store.select('edges', where="'stamp'=1")
In [16]:
edge.shape
Out[16]:
In [14]:
graph
Out[14]:
In [21]:
with pd.get_store('io_test.h5') as store:
vertex = store.select('vertices', where="'vertex_index'=1")
In [22]:
vertex
Out[22]:
In [ ]: