From 6090dd6112268dfcaf58cc8542fbb963a010a35f Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 30 Jul 2013 14:54:11 -0400 Subject: [PATCH] prep: only process intervals present in both raw & sinefit --- Makefile | 3 ++- README.txt | 2 +- nilmtools/filter.py | 8 ++++++-- nilmtools/prep.py | 16 ++++++++++++++-- setup.py | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 0fc773d..0f8a896 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,8 @@ test_prep: /tmp/raw.dat nilmtool create /test/sinefit float32_3 nilmtool create /test/prep float32_8 nilmtool insert -s '@0' -t -r 8000 /test/raw /tmp/raw.dat - nilmtools/sinefit.py -a 0.5 -c 1 /test/raw /test/sinefit + nilmtools/sinefit.py -a 0.5 -c 1 -s '@0' -e '@5000000' /test/raw /test/sinefit + nilmtools/prep.py -c 2 /test/raw /test/sinefit /test/prep nilmtools/prep.py -c 2 /test/raw /test/sinefit /test/prep nilmtool extract -s min -e max /test/prep | head -20 diff --git a/README.txt b/README.txt index 7746037..405c60f 100644 --- a/README.txt +++ b/README.txt @@ -8,7 +8,7 @@ Prerequisites: sudo apt-get install python2.7 python2.7-dev python-setuptools sudo apt-get install python-numpy python-scipy python-daemon - nilmdb (1.8.1+) + nilmdb (1.8.5+) Install: diff --git a/nilmtools/filter.py b/nilmtools/filter.py index d00f29d..b3e058a 100644 --- a/nilmtools/filter.py +++ b/nilmtools/filter.py @@ -316,7 +316,8 @@ class Filter(object): self._client_dest.stream_update_metadata(self.dest.path, data) # The main filter processing method. - def process_numpy(self, function, args = None, rows = 100000): + def process_numpy(self, function, args = None, rows = 100000, + intervals = None): """Calls process_numpy_interval for each interval that currently exists in self.src, but doesn't exist in self.dest. It will process the data in chunks as follows: @@ -325,6 +326,9 @@ class Filter(object): corresponding to the data. The data is converted to a Numpy array in chunks of 'rows' rows at a time. + If 'intervals' is not None, process those intervals instead of + the default list. + 'function' should be defined as: # def function(data, interval, args, insert_func, final) @@ -358,7 +362,7 @@ class Filter(object): maxrows = rows) inserter_func = functools.partial(inserter, self.dest.path) - for interval in self.intervals(): + for interval in (intervals or self.intervals()): print "Processing", interval.human_string() process_numpy_interval(interval, extractor_func, inserter_func, rows * 3, function, args) diff --git a/nilmtools/prep.py b/nilmtools/prep.py index da89e2f..99f21fa 100755 --- a/nilmtools/prep.py +++ b/nilmtools/prep.py @@ -12,6 +12,7 @@ import scipy.fftpack import scipy.signal #from matplotlib import pyplot as p import bisect +from nilmdb.utils.interval import Interval def main(argv = None): # Set up argument parser @@ -82,9 +83,20 @@ def main(argv = None): "prep_column": args.column, "prep_rotation": repr(rotation) }) - # Run the processing function on all data + # Find the intersection of the usual set of intervals we'd filter, + # and the intervals actually present in sinefit data. This is + # what we will process. + filter_int = f.intervals() + sinefit_int = ( Interval(start, end) for (start, end) in + client_sinefit.stream_intervals( + args.sinepath, start = f.start, end = f.end) ) + intervals = nilmdb.utils.interval.intersection(filter_int, sinefit_int) + + # Run the process (using the helper in the filter module) f.process_numpy(process, args = (client_sinefit, sinefit.path, args.column, - args.nharm, rotation, args.nshift)) + args.nharm, rotation, args.nshift), + intervals = intervals) + def process(data, interval, args, insert_function, final): (client, sinefit_path, column, nharm, rotation, nshift) = args diff --git a/setup.py b/setup.py index 2052ecd..3bcf09b 100755 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ setup(name='nilmtools', long_description = "NILM Database Tools", license = "Proprietary", author_email = 'jim@jtan.com', - install_requires = [ 'nilmdb >= 1.8.1', + install_requires = [ 'nilmdb >= 1.8.5', 'numpy', 'scipy', 'python-daemon >= 1.5',