<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 General Imports
!! IMPORTANT !!
If you did NOT install opengrid with pip, 
make sure the path to the opengrid folder is added to your PYTHONPATH
Step1:  Houseprint
Step2:  A Houseprint object can be saved as a pickle. It loses its tmpo session however (connections cannot be pickled)
Step3:  TMPO
The houseprint, sites, devices and sensors all have a get_data method. In order to get these working for the fluksosensors, the houseprint creates a tmpo session.
Step4:  Lookup sites, devices, sensors based on key
These methods return a single object
Step5:  Lookup sites, devices, sensors based on search criteria
These methods return a list with objects satisfying the criteria
Step6:  Get Data
Step7:  Site
Step8:  Device
Step9:  Sensor
Step10:  Getting data for a selection of sensors
<ASSISTANT_TASK:>
Python Code:
import os
import inspect
import sys
import pandas as pd
import charts
from opengrid.library import houseprint
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = 16,8
Explanation: General Imports
!! IMPORTANT !!
If you did NOT install opengrid with pip, 
make sure the path to the opengrid folder is added to your PYTHONPATH
End of explanation
hp = houseprint.Houseprint()
# for testing:
# hp = houseprint.Houseprint(spreadsheet='unit and integration test houseprint')
hp
hp.sites[:5]
hp.get_devices()[:4]
hp.get_sensors('water')[:3]
Explanation: Houseprint
End of explanation
hp.save('new_houseprint.pkl')
hp = houseprint.load_houseprint_from_file('new_houseprint.pkl')
Explanation: A Houseprint object can be saved as a pickle. It loses its tmpo session however (connections cannot be pickled)
End of explanation
hp.init_tmpo()
hp._tmpos.debug = False
hp.sync_tmpos()
Explanation: TMPO
The houseprint, sites, devices and sensors all have a get_data method. In order to get these working for the fluksosensors, the houseprint creates a tmpo session.
End of explanation
hp.find_site(1)
hp.find_device('FL03001556')
sensor = hp.find_sensor('d5a747b86224834f745f4c9775d70241')
print(sensor.site)
print(sensor.unit)
Explanation: Lookup sites, devices, sensors based on key
These methods return a single object
End of explanation
hp.search_sites(inhabitants=5)
hp.search_sensors(type='electricity', direction='Import')
Explanation: Lookup sites, devices, sensors based on search criteria
These methods return a list with objects satisfying the criteria
End of explanation
head = pd.Timestamp('20151102')
tail = pd.Timestamp('20151103')
df = hp.get_data(sensortype='water', head=head,tail=tail, diff=True, resample='min', unit='l/min')
charts.plot(df, stock=True, show='inline')
Explanation: Get Data
End of explanation
site = hp.find_site(1)
site
print(site.size)
print(site.inhabitants)
print(site.postcode)
print(site.construction_year)
print(site.k_level)
print(site.e_level)
print(site.epc_cert)
site.devices
site.get_sensors('electricity')
head = pd.Timestamp('20150617')
tail = pd.Timestamp('20150628')
df=site.get_data(sensortype='electricity', head=head,tail=tail, diff=True, unit='kW')
charts.plot(df, stock=True, show='inline')
Explanation: Site
End of explanation
device = hp.find_device('FL03001552')
device
device.key
device.get_sensors('gas')
head = pd.Timestamp('20151101')
tail = pd.Timestamp('20151104')
df = hp.get_data(sensortype='gas', head=head,tail=tail, diff=True, unit='kW')
charts.plot(df, stock=True, show='inline')
Explanation: Device
End of explanation
sensor = hp.find_sensor('53b1eb0479c83dee927fff10b0cb0fe6')
sensor
sensor.key
sensor.type
sensor.description
sensor.system
sensor.unit
head = pd.Timestamp('20150617')
tail = pd.Timestamp('20150618')
df=sensor.get_data(head,tail,diff=True, unit='W')
charts.plot(df, stock=True, show='inline')
Explanation: Sensor
End of explanation
sensors = hp.search_sensors(type='electricity', system='solar')
print(sensors)
df = hp.get_data(sensors=sensors, head=head, tail=tail, diff=True, unit='W')
charts.plot(df, stock=True, show='inline')
Explanation: Getting data for a selection of sensors
End of explanation
<END_TASK>