NILMTK工具包的使用(一)

您所在的位置:网站首页 nilm检查是什么意思 NILMTK工具包的使用(一)

NILMTK工具包的使用(一)

2024-01-22 09:11| 来源: 网络整理| 查看: 265

一、数据转换为NILMTK 格式并加载到NILMTK

NILMTK 使用基于HDF5 二进制文件格式的开放文件格式来存储电源数据和元数据。使用NILMTK 的第一步是将数据集转换为NILMTK HDF5 文件格式。以下三种方式都可以:

convert_redd('c:\\data\\REDD\\low_freq', r'c:\\data\\redd.h5') convert_redd('c:/data/REDD/low_freq', 'c:/data/redd.h5') convert_redd(r'c:\data\REDD\low_freq', r'c:\data\redd.h5')

Loading house 1… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Loading house 2… 1 2 3 4 5 6 7 8 9 10 11 Loading house 3… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Loading house 4… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Loading house 5… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Loading house 6… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Loaded metadata Done converting YAML metadata to HDF5! Done converting REDD to HDF5!

这样数据集就成功转化为HDF5格式

在NILMTK打开HDF5 from nilmtk import DataSet from nilmtk.utils import print_dict redd = DataSet('/data/redd.h5') 探索数据集对象

与数据集相关的元数据很多,包括关于作者用来记录REDD的两种型号的仪表装置的信息:

print(redd.metadata)

{‘name’: ‘REDD’, ‘long_name’: ‘The Reference Energy Disaggregation Data set’, ‘creators’: [‘Kolter, Zico’, ‘Johnson, Matthew’], ‘publication_date’: 2011, ‘institution’: ‘Massachusetts Institute of Technology (MIT)’, ‘contact’: ‘[email protected]’, ‘description’: ‘Several weeks of power data for 6 different homes.’, ‘subject’: ‘Disaggregated power demand from domestic buildings.’, ‘number_of_buildings’: 6, ‘timezone’: ‘US/Eastern’, ‘geo_location’: {‘locality’: ‘Massachusetts’, ‘country’: ‘US’, ‘latitude’: 42.360091, ‘longitude’: -71.09416}, ‘related_documents’: [‘http://redd.csail.mit.edu’, ‘J. Zico Kolter and Matthew J. Johnson. REDD: A public data set for energy disaggregation research. In proceedings of the SustKDD workshop on Data Mining Applications in Sustainability, 2011. http://redd.csail.mit.edu/kolter-kddsust11.pdf\n’], ‘schema’: ‘https://github.com/nilmtk/nilm_metadata/tree/v0.2’, ‘meter_devices’: {‘eMonitor’: {‘model’: ‘eMonitor’, ‘manufacturer’: ‘Powerhouse Dynamics’, ‘manufacturer_url’: ‘http://powerhousedynamics.com’, ‘description’: ‘Measures circuit-level power demand. Comes with 24 CTs. This FAQ page suggests the eMonitor measures real (active) power: http://www.energycircle.com/node/14103 although the REDD readme.txt says all channels record apparent power.\n’, ‘sample_period’: 3, ‘max_sample_period’: 50, ‘measurements’: [{‘physical_quantity’: ‘power’, ‘type’: ‘active’, ‘upper_limit’: 5000, ‘lower_limit’: 0}], ‘wireless’: False}, ‘REDD_whole_house’: {‘description’: ‘REDD’s DIY power meter used to measure whole-home AC waveforms at high frequency. To quote from their paper: “CTs from TED (http://www.theenergydetective.com) to measure current in the power mains, a Pico TA041 oscilloscope probe (http://www.picotechnologies.com) to measure voltage for one of the two phases in the home, and a National Instruments NI-9239 analog to digital converter to transform both these analog signals to digital readings. This A/D converter has 24 bit resolution with noise of approximately 70 µV, which determines the noise level of our current and voltage readings: the TED CTs are rated for 200 amp circuits and a maximum of 3 volts, so we are able to differentiate between currents of approximately ((200))(70 × 10−6)/(3) = 4.66mA, corresponding to power changes of about 0.5 watts. Similarly, since we use a 1:100 voltage stepdown in the oscilloscope probe, we can detect voltage differences of about 7mV.”\n’, ‘sample_period’: 1, ‘max_sample_period’: 30, ‘measurements’: [{‘physical_quantity’: ‘power’, ‘type’: ‘apparent’, ‘upper_limit’: 50000, ‘lower_limit’: 0}], ‘wireless’: False}}}

print(redd.buildings)

OrderedDict([ (1, Building(instance=1, dataset=‘REDD’)), (2,Building(instance=2, dataset=‘REDD’)), (3, Building(instance=3,dataset=‘REDD’)), (4, Building(instance=4, dataset=‘REDD’)), (5, Building(instance=5, dataset=‘REDD’)), (6, Building(instance=6,dataset=‘REDD’))])

print(redd.buildings[1].metadata)

MeterGroup(meters=ElecMeter(instance=1,building=1,dataset=‘REDD’, site_meter, appliances=[]) ElecMeter(instance=2, building=1, dataset=‘REDD’, site_meter, appliances=[]) ElecMeter(instance=5, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘fridge’, instance=1)]) ElecMeter(instance=6, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘dish washer’, instance=1)]) ElecMeter(instance=7, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘sockets’, instance=1)]) ElecMeter(instance=8, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘sockets’, instance=2)]) ElecMeter(instance=9, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘light’, instance=1)]) ElecMeter(instance=11, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘microwave’, instance=1)]) ElecMeter(instance=12, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘unknown’, instance=1)]) ElecMeter(instance=13, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘electric space heater’, instance=1)]) ElecMeter(instance=14, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘electric stove’, instance=1)]) ElecMeter(instance=15, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘sockets’, instance=3)]) ElecMeter(instance=16, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘sockets’, instance=4)]) ElecMeter(instance=17, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘light’, instance=2)]) ElecMeter(instance=18, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘light’, instance=3)]) ElecMeter(instance=19, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘unknown’, instance=2)]) MeterGroup(meters= ElecMeter(instance=3, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘electric oven’, instance=1)]) ElecMeter(instance=4, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘electric oven’, instance=1)]) ) MeterGroup(meters= ElecMeter(instance=10, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘washer dryer’, instance=1)]) ElecMeter(instance=20, building=1, dataset=‘REDD’, appliances=[Appliance(type=‘washer dryer’, instance=1)]) ) )

二、将数据加载到内存

加载API 是许多nilmtk 操作的核心,并提供了很大的灵活性。让我们看看如何将NILMTK 数据存储中的数据加载到内存中。为了查看所有可能的查询,我们将使用iAWE数据集(其HDF5 文件可以在这里下载)。

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

先读取iawe.h5文件,然后取第一个家庭的数据

from nilmtk import DataSet iawe = DataSet('/data/iawe.h5') elec = iawe.buildings[1].elec print(elec)

MeterGroup(meters= ElecMeter(instance=1, building=1, dataset=‘iAWE’, site_meter, appliances=[]) ElecMeter(instance=2, building=1, dataset=‘iAWE’, site_meter, appliances=[]) ElecMeter(instance=3, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘fridge’, instance=1)]) ElecMeter(instance=4, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘air conditioner’, instance=1)]) ElecMeter(instance=5, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘air conditioner’, instance=2)]) ElecMeter(instance=6, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘washing machine’, instance=1)]) ElecMeter(instance=7, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘computer’, instance=1)]) ElecMeter(instance=8, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘clothes iron’, instance=1)]) ElecMeter(instance=9, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘unknown’, instance=1)]) ElecMeter(instance=10, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘television’, instance=1)]) ElecMeter(instance=11, building=1, dataset=‘iAWE’, appliances=[Appliance(type=‘wet appliance’, instance=1)]) )

取第一个家庭冰箱的数据,并查看冰箱的可用测量值:

fridge = elec['fridge'] print(fridge.available_columns())

[(‘current’, None), (‘power’, ‘active’), (‘frequency’, None), (‘power factor’, None), (‘power’, ‘apparent’), (‘power’, ‘reactive’), (‘voltage’, None)]

加载数据 1.加载所有列 df = next(fridge.load()) print(df.head())

在这里插入图片描述

2 加载一列电源数据

使用fridge.power_series() 返回一维pandas 序列对象,每个对象包含使用最“敏感” AC类型的电源数据:

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

2013-07-13 05:30:00+05:30 0.166925 2013-07-13 05:31:00+05:30 0.169385 2013-07-13 05:32:00+05:30 0.177887 2013-07-13 05:33:00+05:30 0.175929 2013-07-13 05:34:00+05:30 0.177044 Name: (power, active), dtype:float32

或者,要获得无功功率:

series = next(fridge.power_series(ac_type='reactive')) print(series.head())

2013-07-13 05:30:00+05:30 2.652679 2013-07-13 05:31:00+05:30 2.640115 2013-07-13 05:32:00+05:30 2.666358 2013-07-13 05:33:00+05:30 2.677607 2013-07-13 05:34:00+05:30 2.688200 Name: (power, reactive), dtype: float32

3 指定物理量或AC 类型

通过load 指定物理量和AC 类型加载无功功率:

df = next(fridge.load(physical_quantity='power', ac_type='reactive')) print(df.head())

在这里插入图片描述

加载电压数据:

df = next(fridge.load(physical_quantity='voltage')) print(df.head())

在这里插入图片描述

指定物理量不指定类型:

df = next(fridge.load(physical_quantity = 'power')) print(df.head())

在这里插入图片描述

4 通过指定AC 类型加载 df = next(fridge.load(ac_type='active')) print(df.head())

在这里插入图片描述

5 通过重新采样到指定时间段进行加载 df = next(fridge.load(ac_type='active', sample_period=60)) print(df.head())

在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3