Visualization of electricity consumption with focus on night time


In [ ]:
import os, sys
import time
import inspect
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

script_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
# add the path to opengrid to sys.path
sys.path.append(os.path.join(script_dir, os.pardir, os.pardir))
from opengrid.library import config, plotting
c=config.Config()

# find tmpo
sys.path.append(c.get('tmpo', 'folder'))
sys.path.append(c.get('tmpo', 'folder'))

try:
    if os.path.exists(c.get('tmpo', 'data')):
        path_to_tmpo_data = c.get('tmpo', 'data')
except:
    path_to_tmpo_data = None
    
from opengrid.library.houseprint import houseprint

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

# path to data
path_to_data = c.get('data', 'folder')
if not os.path.exists(path_to_data):
    raise IOError("Provide your path to the data in your config.ini file.  This is a folder containing a 'zip' and 'csv' subfolder.")
else:
    path_to_fig = os.path.join(path_to_data, 'figures')
    if not os.path.isdir(path_to_fig): os.makedirs(path_to_fig)

In [ ]:
hp = houseprint.load_houseprint_from_file('new_houseprint.pkl')
hp.init_tmpo(path_to_tmpo_data=path_to_tmpo_data)

#set start date
number_of_days = 60
start = pd.Timestamp(time.time() - number_of_days*86400, unit='s')

In [ ]:
sensor = hp.get_sensors(sensortype='electricity')[0]
df = sensor.get_data(head = start)
df = df.diff()*60 #from Wh/min to W

In [ ]:
plotting.carpet(df, title=sensor.device.key, zlabel=r'Power [W]')

In [ ]:
plotting.fanchart(df, title=sensor.device.key, ylabel=r'Power [W]', start_hour=0, end_hour=3)

In [ ]:
begin = pd.Timestamp('20150701')
end = begin + pd.Timedelta('1 day')
df.truncate(begin,end).plot(title=sensor.device.key)
plt.xlabel(begin)

In [ ]: