In [1]:
import numpy as np
import pandas as pd
from os.path import join

from pylab import rcParams
import matplotlib.pyplot as plt
%matplotlib inline
rcParams['figure.figsize'] = (16, 8)

import nilmtk
from nilmtk import DataSet, TimeFrame, MeterGroup, HDFDataStore
from nilmtk.disaggregate import CombinatorialOptimisation
from nilmtk.utils import print_dict
from nilmtk.metrics import f1_score

import seaborn as sns

import warnings
warnings.filterwarnings("ignore")

In [2]:
data_dir = '/home/nipun/datasets/'
we = DataSet(join(data_dir, 'wikienergy.h5'))
print('loaded ' + str(len(we.buildings)) + ' buildings')


loaded 239 buildings

In [3]:
building_number = 11
print_dict(we.buildings[building_number].metadata)


  • instance: 11
  • dataset: WikiEnergy
  • original_name: 434

In [4]:
elec = we.buildings[building_number].elec
elec.appliances


Out[4]:
[Appliance(type='fridge', instance=1),
 Appliance(type='dish washer', instance=1),
 Appliance(type='electric water heating appliance', instance=1),
 Appliance(type='spin dryer', instance=1),
 Appliance(type='electric furnace', instance=1),
 Appliance(type='sockets', instance=1),
 Appliance(type='sockets', instance=2),
 Appliance(type='air conditioner', instance=1),
 Appliance(type='sockets', instance=3),
 Appliance(type='sockets', instance=4)]

In [5]:
submeters = elec.submeters().meters
submeters


Out[5]:
[ElecMeter(instance=2, building=11, dataset='WikiEnergy', appliances=[Appliance(type='air conditioner', instance=1)]),
 ElecMeter(instance=3, building=11, dataset='WikiEnergy', appliances=[Appliance(type='sockets', instance=1)]),
 ElecMeter(instance=4, building=11, dataset='WikiEnergy', appliances=[Appliance(type='sockets', instance=2)]),
 ElecMeter(instance=5, building=11, dataset='WikiEnergy', appliances=[Appliance(type='dish washer', instance=1)]),
 ElecMeter(instance=6, building=11, dataset='WikiEnergy', appliances=[Appliance(type='spin dryer', instance=1)]),
 ElecMeter(instance=7, building=11, dataset='WikiEnergy', appliances=[Appliance(type='electric furnace', instance=1)]),
 ElecMeter(instance=8, building=11, dataset='WikiEnergy', appliances=[Appliance(type='sockets', instance=3)]),
 ElecMeter(instance=9, building=11, dataset='WikiEnergy', appliances=[Appliance(type='sockets', instance=4)]),
 ElecMeter(instance=10, building=11, dataset='WikiEnergy', appliances=[Appliance(type='fridge', instance=1)]),
 ElecMeter(instance=11, building=11, dataset='WikiEnergy', appliances=[Appliance(type='electric water heating appliance', instance=1)])]

In [6]:
simultaneous_switches = elec.simultaneous_switches()

In [7]:
simultaneous_switches


Out[7]:
1391265720000000000    2
1391269980000000000    2
1391274000000000000    2
1391274060000000000    2
1391275080000000000    4
1391275140000000000    3
1391275620000000000    2
1391278680000000000    2
1391293080000000000    2
1391293140000000000    2
1391293320000000000    2
1391293380000000000    2
1391317920000000000    2
1391357640000000000    2
1391358360000000000    2
...
1401552180000000000    2
1401552900000000000    2
1401552960000000000    3
1401553980000000000    2
1401554400000000000    3
1401554460000000000    2
1401555600000000000    3
1401556680000000000    2
1401556740000000000    2
1401569040000000000    3
1401569100000000000    2
1401574680000000000    2
1401574740000000000    2
1401580500000000000    2
1401580560000000000    2
Length: 5153, dtype: int64

In [8]:
simultaneous_switches.hist()
plt.xlabel("Number of appliances switching")
plt.ylabel("Instances")
plt.title("Simultaneous switches for threshold =  40W");


Simultaneous switches as a function of threshold


In [9]:
violations = {}
for threshold in [5, 50, 100, 500, 1000]:
    violations[threshold] = len(elec.simultaneous_switches(threshold))

In [10]:
violations


Out[10]:
{5: 23067, 50: 4461, 100: 2890, 500: 320, 1000: 147}

In [12]:
pd.Series(violations).plot(kind='bar');
plt.xlabel("Threshold")
plt.ylabel("Number of simultaneous switches");