Skip to content

Commit

Permalink
convert_ukdale appears to work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackKelly committed Sep 18, 2014
1 parent f4871d4 commit fd5ebde
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 138 deletions.
37 changes: 13 additions & 24 deletions nilmtk/dataset_converters/redd/convert_redd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import pandas as pd
import numpy as np
from copy import deepcopy
from os.path import join, isdir, isfile, dirname, abspath
from os import listdir, getcwd
from os.path import join, isdir, isfile
from os import listdir
import re
from sys import stdout, getfilesystemencoding
from sys import stdout
from nilmtk.datastore import Key
from nilmtk.timeframe import TimeFrame
from nilmtk.measurement import LEVEL_NAMES
from nilmtk.utils import get_module_directory
from nilm_metadata import convert_yaml_to_hdf5
from inspect import currentframe, getfile, getsourcefile

"""
TODO:
Expand All @@ -36,6 +36,15 @@ def _redd_measurement_mapping_func(house_id, chan_id):

_convert(redd_path, hdf_filename, _redd_measurement_mapping_func, 'US/Eastern')

# Add metadata
convert_yaml_to_hdf5(join(get_module_directory(),
'dataset_converters',
'redd',
'metadata'),
hdf_filename)

print("Done converting REDD to HDF5!")


def _convert(input_path, hdf_filename, measurement_mapping_func, tz):
"""
Expand Down Expand Up @@ -77,12 +86,6 @@ def _convert(input_path, hdf_filename, measurement_mapping_func, tz):

store.close()

# Add metadata
convert_yaml_to_hdf5(join(_get_module_directory(), 'metadata'),
hdf_filename)

print("Done converting to HDF5!")


def _find_all_houses(input_path):
"""
Expand Down Expand Up @@ -172,17 +175,3 @@ def _load_chan(input_path, key_obj, columns, tz):
df = df.tz_convert(tz)

return df


def _get_module_directory():
# Taken from http://stackoverflow.com/a/6098238/732596
path_to_this_file = dirname(getfile(currentframe()))
if not isdir(path_to_this_file):
encoding = getfilesystemencoding()
path_to_this_file = dirname(unicode(__file__, encoding))
if not isdir(path_to_this_file):
abspath(getsourcefile(lambda _: None))
if not isdir(path_to_this_file):
path_to_this_file = getcwd()
assert isdir(path_to_this_file), path_to_this_file + ' is not a directory'
return path_to_this_file
15 changes: 14 additions & 1 deletion nilmtk/dataset_converters/ukdale/convert_ukdale.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import print_function, division
from nilmtk.dataset_converters.redd.convert_redd import _convert
from os.path import join
from nilmtk.dataset_converters.redd.convert_redd import _convert
from nilmtk.utils import get_module_directory
from nilm_metadata import convert_yaml_to_hdf5


def convert_ukdale(ukdale_path, hdf_filename):
"""
Expand All @@ -18,3 +22,12 @@ def _ukdale_measurement_mapping_func(house_id, chan_id):

_convert(ukdale_path, hdf_filename, _ukdale_measurement_mapping_func,
'Europe/London')

# Add metadata
convert_yaml_to_hdf5(join(get_module_directory(),
'dataset_converters',
'ukdale',
'metadata'),
hdf_filename)

print("Done converting UK-DALE to HDF5!")

0 comments on commit fd5ebde

Please sign in to comment.