In [6]:
from __future__ import print_function, division
import os
from os.path import join
from nilmtk.utils import check_directory_exists
from nilm_metadata import convert_yaml_to_hdf5

home_dir='/Users/GJWood/nilm_gjw_data' # path to input data

def refresh_gjw_metadata(gjw_path, output_filename, format="HDF"):
    """
    Parameters
    ----------
    gjw_path : str
        The root path of the gjw dataset.
    output_filename : str
        The destination filename (including path and suffix), will default if not specified
    directory and file structure
    nilm_gjw_data
        building<1>
            elec
                4-POWER_REAL_FINE <date> Dump.csv
                5-POWER_REACTIVE_STANDARD <date> Dump.csv
                ...
        ...
        building<n>
        HDF5
            nilm_gjw_data.hdf5
        metadata
            building1.yaml
            dataset.yaml
            meter_devices.yaml
        other files    
    """
    if gjw_path is None: gjw_path = home_dir
    check_directory_exists(gjw_path)
    os.chdir(gjw_path)
    gjw_path = os.getcwd()  # sort out potential issue with slashes or backslashes
    if output_filename is None:
        output_filename =join(home_dir,'HDF5','nilm_gjw_data.hdf5')
    convert_yaml_to_hdf5(join(gjw_path, 'metadata'),output_filename)
    print("Done refreshing metadata")
    
def main():
    refresh_gjw_metadata('c:/Users/GJWood/nilm_gjw_data', None)

if __name__ == '__main__':
    main()


---------------------------------------------------------------------------
NilmMetadataError                         Traceback (most recent call last)
<ipython-input-6-c46dd3cb7ad4> in <module>()
     45 
     46 if __name__ == '__main__':
---> 47     main()

<ipython-input-6-c46dd3cb7ad4> in main()
     42 
     43 def main():
---> 44     refresh_gjw_metadata('c:/Users/GJWood/nilm_gjw_data', None)
     45 
     46 if __name__ == '__main__':

<ipython-input-6-c46dd3cb7ad4> in refresh_gjw_metadata(gjw_path, output_filename, format)
     38     if output_filename is None:
     39         output_filename =join(home_dir,'HDF5','nilm_gjw_data.hdf5')
---> 40     convert_yaml_to_hdf5(join(gjw_path, 'metadata'),output_filename)
     41     print("Done refreshing metadata")
     42 

c:\users\gjwood\nilm_metadata\nilm_metadata\convert_yaml_to_hdf5.pyc in convert_yaml_to_hdf5(yaml_dir, hdf_filename)
     53         _set_data_location(elec_meters, building)
     54         _sanity_check_meters(elec_meters, meter_devices)
---> 55         _sanity_check_appliances(building_metadata)
     56         group._f_setattr('metadata', building_metadata)
     57 

c:\users\gjwood\nilm_metadata\nilm_metadata\convert_yaml_to_hdf5.pyc in _sanity_check_appliances(building_metadata)
    180                    .format(building_metadata['instance'], appliance_type,
    181                            len(instances), instances, correct_instances))
--> 182             raise NilmMetadataError(msg)

NilmMetadataError: In building 1, appliance 'electric space heater' appears 3 times. The list of instances is '[1, 1, 1]'.  It should be '[1, 2, 3]'.

In [ ]: