Closed gjwo closed 9 years ago
Any clues on how to find instance errors in a 700+ line metadata file? :confounded:
KeyError Traceback (most recent call last)
<ipython-input-1-352366a75b30> in <module>()
132 df = df.sort_index()
133 return df
--> 134 convert_gjw('C:/Users/GJWood/nilm_gjw_data',None)
<ipython-input-1-352366a75b30> in convert_gjw(gjw_path, output_filename, format)
109 break # only 1 folder with .csv files at present
110 store.close()
--> 111 convert_yaml_to_hdf5(join(gjw_path, 'metadata'),output_filename)
112 print("Done converting gjw to HDF5!")
113
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)
170 appl_type = appliance['type']
171 instances = appliance_instances.setdefault(appl_type, [])
--> 172 instances.append(appliance['instance'])
173
174 for appliance_type, instances in appliance_instances.iteritems():
KeyError: 'instance'
Can you validate your YAML using YAMLlint?
Thanks Nipun I will try that, but I am past the syntax errors now, and the error above looks like it is in the sanity check code, I looked at the code, and the next section would have output some clues, but this looks like something wasn't initialised. Is there something I should have called prior to the converter code?
YAMLint - Valid YAML!
Here is the current code and errors in an iPython Notebook https://github.com/gjwo/nilm_gjw_data/blob/master/gjw_converter_test.ipynb I could do with some help on this, it does look like the toolkit metadata code failing
OK I have found what the problem was by putting print(appliance) at line 172 of convert_yaml_to_hd5.py. The issue was I was missing an "instance: 1" in several places, this caused a KeyError exception which did not have a handler at line 173.
I seem to recall reading that if there was only one instance of a type then the instance key was optional, clearly this is not the case, doh!
@JackKelly @nipunreddevil I think making clear which keys are mandatory in the documentation, and adding an exception handler which prints the device where the checking failed would help those who follow
I seem to recall reading that if there was only one instance of a type then the instance key was optional
Do you remember where you read that? As you say, that is wrong and so we should change the docs if necessary. Perhaps our various discussions about simplifying the schema are causing confusion here? Or perhaps NILMTK's behaviour is causing confusion here: in NILMTK you can do elec['fridge']
and you'll get fridge 1
.
I think making clear which keys are mandatory in the documentation
We do try to do that. The required keys have '(required)' written next to them in the documentation (for example, here's the Appliance docs). Perhaps '(required)' should be in bold or a different colour or something?
adding an exception handler which prints the device where the checking failed would help those who follow
Absolutely right. I'll do that now and report back when I'm done. Sorry the code is not very friendly in (lots of) places ;)
OK, I have added more sanity checks. And added some simple unit tests for these sanity checks. I'll close this issue for now. Please re-open if necessary.
Can anybody tell me what is wrong with this section of yaml (starts at line 549 of building.yaml), 559 is the components line, error traceback given below from a call to convert_yaml_to_hdf5 I do know appliances don't yet contain a cassette deck but I don't think it got that far.