Quick Tmpo demo

To get started, clone the tmpo-py repository from the opengrid github page. Then specify the path to this repo on your hard drive in your opengrid.cfg file.


In [1]:
import tmpo
import matplotlib.pyplot as plt

%matplotlib inline
plt.rcParams['figure.figsize'] = 14,8

Create a tmpo session, and enter debug mode to get more output.


In [2]:
s = tmpo.Session()
s.debug = False

Add a sensor and token to start tracking the data for this given sensor. You only have to do this once for each sensor.


In [3]:
s.add('d209e2bbb35b82b83cc0de5e8b84a4ff','e16d9c9543572906a11649d92f902226')

Sync all available data to your hard drive. All sensors previously added will be synced.


In [ ]:
s.sync()

Now you can create a pandas timeseries with all data from a given sensor.


In [ ]:
ts = s.series('d209e2bbb35b82b83cc0de5e8b84a4ff')
print(ts)

When plotting the data, you'll notice that this ts contains cumulative data, and the time axis (= pandas index) contains seconds since the epoch. Not very practical.


In [ ]:
ts.ix[:1000].plot()
plt.show()

To show differential data (eg instantaneous power), we first have to resample this cumulative data to the interval we want to obtain. We use linear interpolation to approximate the cumulative value between two datapoints. In the example below, we resample to hourly values. Then, we take the difference between the cumulative values at hourly intervals in order to get the average power (per hour). As the original data is in Wh, we obtain W.


In [ ]:
tsmin = ts.resample(rule='H')
tsmin=tsmin.interpolate(method='linear')
tsmin=tsmin.diff()
tsmin.plot()

If we want to plot only a specific period, we can slice the data with the .ix[from:to] method.


In [ ]:
tsmin.ix['20141016':'20141018'].plot()

In [ ]:
ts.name

Note

All of the functionality illustrated above is now included in the houseprint module. See the notebook Demo_houseprint.ipynb for a demo.

TMPO support is now included in the new houseprint. After loading the houseprint just call houseprint.init_tmpo() to initialize. After that, accessing data is as easy as calling sensor.get_data(), houseprint.get_data()... there are many options, such as houseprint.get_data(sensortype='gas', resample='min').