In [1]:
import pandas as pd
import numpy as np
from dataobject import DataObject
In [28]:
class MyObject(DataObject):
_tables = ['data']
_params = ['noise']
defaults = {'noise':0.5}
def __init__(self, npts=100, noise=0.5, **kwargs):
t = np.arange(npts)
f = np.random.randn(npts)*noise
data = pd.DataFrame({'t':t, 'f':f})
kwargs['noise'] = noise
kwargs['data'] = data
super(MyObject, self).__init__(**kwargs)
class AnotherObject(MyObject):
_tables = ['moredata'] + MyObject._tables
def __init__(self, npts=50, **kwargs):
f = np.random.random(npts)
kwargs['moredata'] = pd.DataFrame({'f':f})
super(AnotherObject, self).__init__(**kwargs)
In [40]:
AnotherObject._tables
Out[40]:
In [36]:
d3 = AnotherObject()
In [18]:
d3.save_hdf('testd.h5')
In [19]:
d4 = AnotherObject.load_hdf('testd.h5')
In [24]:
d3.data.head()
Out[24]:
In [25]:
d4.data.head()
Out[25]:
In [3]:
d = MyObject()
In [4]:
d.save_hdf('testd.h5', overwrite=True)
In [5]:
d2 = MyObject.load_hdf('testd.h5')
In [6]:
d2.noise
Out[6]:
In [7]:
d2.data.head()
Out[7]:
In [8]:
d.data.head()
Out[8]:
In [ ]: