NILMTK_UKDale使用说明

在NILMTK打开ukdale.h5

from nilmtk import DataSet
from nilmtk.utils import print_dict

ukdale=DataSet('D:/ukdale/ukdale.h5')

探索数据集对象

与数据集相关的元数据很多,记录了制作ukdale数据项目的情况(开始时间为2012-11-09T22:28:15,结束时间为2015-01-05T06:26:44):

print(ukdale.metadata)

{‘description_of_subjects’: ‘4 MSc students and 1 PhD student.’, ‘meter_devices’: {‘EcoManagerTxPlug’: {‘max_sample_period’: 120, ‘model_url’: ‘https://shop.edfenergy.com/Item.aspx?id=540’, ‘wireless_configuration’: {‘base’: ‘creators: [Jack Kelly] model: rfm_edf_ecomanager model_url: https://github.com/JackKelly/rfm_edf_ecomanager/\n’, ‘protocol’: ‘custom’, ‘carrier_frequency’: 434}, ‘brand’: ‘EcoManager’, ‘measurements’: [{‘lower_limit’: 0, ‘upper_limit’: 3300, ‘physical_quantity’: ‘power’, ‘type’: ‘active’}], ‘data_logger’: {‘model’: ‘rfm_ecomanager_logger’, ‘creators’: [‘Jack Kelly’], ‘model_url’: ‘https://github.com/JackKelly/rfm_ecomanager_logger’}, ‘sample_period’: 6, ‘wireless’: True, ‘brand_url’: ‘http://www.edfenergy.com/products-services/for-your-home/ecomanager’, ‘model’: ‘EcoManagerTxPlug’, ‘seller’: ‘EDF Energy’, ‘manufacturer’: ‘Current Cost / Sailwider’}, ‘CurrentCostTx’: {‘max_sample_period’: 120, ‘model_url’: ‘http://www.currentcost.com/product-transmitter.html’, ‘wireless_configuration’: {‘base’: ‘creators: [Jack Kelly] model: rfm_edf_ecomanager model_url: https://github.com/JackKelly/rfm_edf_ecomanager/\n’, ‘protocol’: ‘custom’, ‘carrier_frequency’: 434}, ‘measurements’: [{‘lower_limit’: 0, ‘upper_limit’: 25000, ‘physical_quantity’: ‘power’, ‘type’: ‘apparent’}], ‘data_logger’: {‘model’: ‘rfm_ecomanager_logger’, ‘creators’: [‘Jack Kelly’], ‘model_url’: ‘https://github.com/JackKelly/rfm_ecomanager_logger’}, ‘sample_period’: 6, ‘wireless’: True, ‘model’: ‘CurrentCost Tx’, ‘manufacturer’: ‘Current Cost’}, ‘SoundCardPowerMeter’: {‘max_sample_period’: 3, ‘wireless’: False, ‘model_url’: ‘https://github.com/JackKelly/snd_card_power_meter’, ‘model’: ‘Sound Card Power Meter’, ‘measurements’: [{‘lower_limit’: 0, ‘upper_limit’: 25000, ‘physical_quantity’: ‘power’, ‘type’: ‘active’}, {‘lower_limit’: 0, ‘upper_limit’: 25000, ‘physical_quantity’: ‘power’, ‘type’: ‘apparent’}, {‘lower_limit’: 180, ‘upper_limit’: 275, ‘physical_quantity’: ‘voltage’, ‘description’: ‘RMS voltage’}], ‘manufacturer’: ‘Jack Kelly / Imperial College London’, ‘sample_period’: 1}, ‘EcoManagerWholeHouseTx’: {‘max_sample_period’: 120, ‘model_url’: ‘https://shop.edfenergy.com/Item.aspx?id=547’, ‘wireless_configuration’: {‘base’: ‘creators: [Jack Kelly] model: rfm_edf_ecomanager model_url: https://github.com/JackKelly/rfm_edf_ecomanager/\n’, ‘protocol’: ‘custom’, ‘carrier_frequency’: 434}, ‘brand’: ‘EcoManager’, ‘measurements’: [{‘lower_limit’: 0, ‘upper_limit’: 25000, ‘physical_quantity’: ‘power’, ‘type’: ‘apparent’}], ‘data_logger’: {‘model’: ‘rfm_ecomanager_logger’, ‘creators’: [‘Jack Kelly’], ‘model_url’: ‘https://github.com/JackKelly/rfm_ecomanager_logger’}, ‘sample_period’: 6, ‘wireless’: True, ‘brand_url’: ‘http://www.edfenergy.com/products-services/for-your-home/ecomanager’, ‘model’: ‘EcoManagerWholeHouseTx’, ‘seller’: ‘EDF Energy’, ‘site_meter’: True, ‘manufacturer’: ‘Current Cost / Sailwider’}}, ‘description’: ‘Appliance-by-appliance and whole-home power demand for 5 UK homes. Appliance power demand was recorded once every 6 seconds. Whole-home power demand was recorded once every 6 seconds for all homes and additionally at 16kHz for homes 1, 2 and 5. Detailed metadata is included.’, ‘rights_list’: [{‘name’: ‘Creative Commons Attribution 4.0 International (CC BY 4.0)’, ‘uri’: ‘http://creativecommons.org/licenses/by/4.0/’}], ‘long_name’: ‘UK Domestic Appliance-Level Electricity’, ‘geo_location’: {‘latitude’: 51.464462, ‘country’: ‘GB’, ‘longitude’: -0.076544, ‘locality’: ‘London’}, ‘date’: ‘2015-01-05’, ‘timezone’: ‘Europe/London’, ‘institution’: ‘Imperial College London’, ‘subject’: ‘Disaggregated domestic electricity demand’, ‘publisher’: ‘UK Energy Research Centre Energy Data Centre (UKERC EDC)’, ‘funding’: [“Jack Kelly’s PhD is funded by an EPSRC DTA”, “Hardware necessary for this project was funded from Jack Kelly’s Intel EU PhD Fellowship”], ‘name’: ‘UK-DALE’, ‘number_of_buildings’: 5, ‘related_documents’: [‘Dataset is available for download from http://www.doc.ic.ac.uk/~dk3810/data/’, “Dataset is also available from the UK Energy Research Council’s Energy Data Centre: The 1-second data is available from http://data.ukedc.rl.ac.uk/cgi-bin/dataset_catalogue/view.cgi.py?id=19 and the 6-second data is available from http://data.ukedc.rl.ac.uk/cgi-bin/dataset_catalogue/view.cgi.py?id=18 but please note that this archive is updated less frequently than the data on www.doc.ic.ac.uk/~dk3810/data/”, ‘This research paper describes the data collection: http://arxiv.org/abs/1404.0284’, ‘The following poster describes the metering setup and provides some analyses: Jack Kelly and William Knottenbelt. Smart Meter Disaggregation: Data Collection & Analysis. UK Energy Research Council Summer School Ph.D. poster session. June 2013. PDF: http://www.doc.ic.ac.uk/~dk3810/writing/UKERC_poster2013_v2.pdf’], ‘contact’: ‘jack.kelly@imperial.ac.uk’, ‘timeframe’: {‘start’: ‘2012-11-09T22:28:15+00:00’, ‘end’: ‘2015-01-05T06:26:44+00:00’}, ‘geospatial_coverage’: ‘Southern England’, ‘creators’: [‘Kelly, Jack’], ‘schema’: ‘https://github.com/nilmtk/nilm_metadata/tree/v0.2’}

数据集中的房屋信息:

print(ukdale.buildings)

OrderedDict([(1, Building(instance=1, dataset=‘UK-DALE’)),
(2, Building(instance=2, dataset=‘UK-DALE’)),
(3, Building(instance=3, dataset=‘UK-DALE’)),
(4, Building(instance=4, dataset=‘UK-DALE’)),
(5, Building(instance=5, dataset=‘UK-DALE’))])

每个房屋的具体信息:

print(ukdale.buildings[1].metadata)

{‘description’: ‘Some individual appliance meters are switched off from the socket for significant portions of time.
These include (using original names): laptop, kettle, toaster, lcd_office, hifi_office, livingroom_s_lamp, soldering_iron, gigE_&_USBhub, hoover, iPad_charger, utilityrm_lamp, hair_dryer, straighteners, iron, childs_ds_lamp, office_lamp3, office_pc, gigE_switch’,
‘description_of_occupants’: ‘2 adults and 1 dog started living in the house in 2006 (i.e. before the dataset started recording). One child born 2011-08-27 and a second child born 2014-04-27.’,
‘original_name’: ‘house_1’, ‘heating’: [‘natural gas’], ‘instance’: 1, ‘building_type’: ‘end of terrace’,
‘energy_improvements’: [‘solar thermal’, ‘loft insulation’, ‘solid wall insulation’, ‘double glazing’],
‘rooms’: [{‘name’: ‘lounge’, ‘floor’: 0}, {‘instance’: 1, ‘name’: ‘hall’, ‘floor’: 0}, {‘instance’: 2, ‘name’: ‘hall’, ‘floor’: 1}, {‘name’: ‘kitchen’, ‘floor’: 0}, {‘name’: ‘utility’, ‘floor’: 0}, {‘name’: ‘dining room’, ‘floor’: 0}, {‘instance’: 1, ‘floor’: 1, ‘description’: ‘master bedroom’, ‘name’: ‘bedroom’}, {‘instance’: 2, ‘floor’: 1, ‘description’: “kid’s bedroom”, ‘name’: ‘bedroom’}, {‘instance’: 1, ‘floor’: 1, ‘description’: 'occasionally used as a spare bedroom ', ‘name’: ‘study’}, {‘instance’: 1, ‘floor’: 1, ‘description’: ‘shower + bath + toilet + sink + cupboards + hot water tank + boiler + solar thermal pumping station’, ‘name’: ‘bathroom’}],
‘ownership’: ‘bought’, ‘timeframe’: {‘start’: ‘2012-11-09T22:28:15+00:00’, ‘end’: ‘2015-01-05T06:26:44+00:00’},
‘construction_year’: 1905, ‘n_occupants’: 4, ‘dataset’: ‘UK-DALE’}

将数据加载到内存

先读取ukdale.h5文件,然后取第一间房屋的数据(设备类型数据):

elec=ukdale.buildings[1].elec
print(elec)

MeterGroup(meters=
ElecMeter(instance=2, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘boiler’, instance=1)])
ElecMeter(instance=3, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘solar thermal pumping station’, instance=1)])
ElecMeter(instance=4, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘laptop computer’, instance=1), Appliance(type=‘laptop computer’, instance=3)])
ElecMeter(instance=5, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘washer dryer’, instance=1)])
ElecMeter(instance=6, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘dish washer’, instance=1)])
ElecMeter(instance=7, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘television’, instance=1)])
ElecMeter(instance=8, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=1), Appliance(type=‘light’, instance=2)])
ElecMeter(instance=9, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘HTPC’, instance=1)])
ElecMeter(instance=10, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘kettle’, instance=1), Appliance(type=‘food processor’, instance=1), Appliance(type=‘toasted sandwich maker’, instance=1)])
ElecMeter(instance=11, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘toaster’, instance=1), Appliance(type=‘kitchen aid’, instance=1), Appliance(type=‘food processor’, instance=2)])
ElecMeter(instance=12, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘fridge freezer’, instance=1)])
ElecMeter(instance=13, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘microwave’, instance=1)])
ElecMeter(instance=14, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘computer monitor’, instance=1)])
ElecMeter(instance=15, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘audio system’, instance=1)])
ElecMeter(instance=16, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘breadmaker’, instance=1)])
ElecMeter(instance=17, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘audio amplifier’, instance=1)])
ElecMeter(instance=18, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘broadband router’, instance=1)])
ElecMeter(instance=19, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=3)])
ElecMeter(instance=20, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘soldering iron’, instance=1)])
ElecMeter(instance=21, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘ethernet switch’, instance=1), Appliance(type=‘USB hub’, instance=1)])
ElecMeter(instance=22, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘vacuum cleaner’, instance=1)])
ElecMeter(instance=23, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=4)])
ElecMeter(instance=24, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=5)])
ElecMeter(instance=25, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=16)])
ElecMeter(instance=26, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=6)])
ElecMeter(instance=27, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘tablet computer charger’, instance=1)])
ElecMeter(instance=28, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘active subwoofer’, instance=1)])
ElecMeter(instance=29, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=7)])
ElecMeter(instance=30, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘radio’, instance=1)])
ElecMeter(instance=31, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=8)])
ElecMeter(instance=32, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘wireless phone charger’, instance=1), Appliance(type=‘audio system’, instance=2)])
ElecMeter(instance=33, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=9)])
ElecMeter(instance=34, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘mobile phone charger’, instance=1)])
ElecMeter(instance=35, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=10)])
ElecMeter(instance=36, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘coffee maker’, instance=1)])
ElecMeter(instance=37, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘radio’, instance=2)])
ElecMeter(instance=38, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘mobile phone charger’, instance=2), Appliance(type=‘baby monitor’, instance=2), Appliance(type=‘radio’, instance=3)])
ElecMeter(instance=39, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘hair dryer’, instance=1)])
ElecMeter(instance=40, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘hair straighteners’, instance=1)])
ElecMeter(instance=41, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘clothes iron’, instance=1)])
ElecMeter(instance=42, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘oven’, instance=1)])
ElecMeter(instance=43, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘computer’, instance=1), Appliance(type=‘external hard disk’, instance=1)])
ElecMeter(instance=44, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=11)])
ElecMeter(instance=45, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=12)])
ElecMeter(instance=46, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘baby monitor’, instance=1)])
ElecMeter(instance=47, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘charger’, instance=1)])
ElecMeter(instance=48, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=13)])
ElecMeter(instance=49, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=14)])
ElecMeter(instance=50, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘light’, instance=15)])
ElecMeter(instance=51, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘desktop computer’, instance=1)])
ElecMeter(instance=52, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘fan’, instance=1)])
ElecMeter(instance=53, building=1, dataset=‘UK-DALE’, appliances=[Appliance(type=‘printer’, instance=1)])
ElecMeter(instance=54, building=1, dataset=‘UK-DALE’, site_meter, appliances=[Appliance(type=‘immersion heater’, instance=1), Appliance(type=‘water pump’, instance=1), Appliance(type=‘security alarm’, instance=1), Appliance(type=‘fan’, instance=2), Appliance(type=‘drill’, instance=1), Appliance(type=‘laptop computer’, instance=2)])
)

取第一间房屋dish washer的数据,并查看dish washer的可用测量值:

dish_washer=elec['dish washer']
print(dish_washer.available_columns())

[(‘power’, ‘active’)]

加载所有列

load 函数根据指定的条件返回从数据存储加载的数据帧生成器。如果未指定任何条件,则加载所有列中的所有数据。

df=next(dish_washer.load())
print(df.head())

physical_quantity power
type active
2012-11-09 22:28:18+00:00 1.0
2012-11-09 22:28:24+00:00 1.0
2012-11-09 22:28:30+00:00 1.0
2012-11-09 22:28:36+00:00 1.0
2012-11-09 22:28:42+00:00 1.0

加载一列数据

使用dish_washer.power_series() 返回一维pandas 序列对象:

series=next(dish_washer.power_series())
print(series.head())

2012-11-09 22:28:18+00:00 1.0
2012-11-09 22:28:24+00:00 1.0
2012-11-09 22:28:30+00:00 1.0
2012-11-09 22:28:36+00:00 1.0
2012-11-09 22:28:42+00:00 1.0
Name: (power, active), dtype: float32

指定物理量

df=next(dish_washer.load(physical_quantity='power',ac_type='active'))
print(df.head())

physical_quantity power
type active
2012-11-09 22:28:18+00:00 1.0
2012-11-09 22:28:24+00:00 1.0
2012-11-09 22:28:30+00:00 1.0
2012-11-09 22:28:36+00:00 1.0
2012-11-09 22:28:42+00:00 1.0

通过重新采样到指定时间段进行加载

df=next(dish_washer.load(ac_type='active',sample_period=60))
print(df.head())

physical_quantity power
type active
2012-11-09 22:28:00+00:00 1.0
2012-11-09 22:29:00+00:00 1.0
2012-11-09 22:30:00+00:00 1.0
2012-11-09 22:31:00+00:00 1.0
2012-11-09 22:32:00+00:00 1.0

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值