Browse Source

prep: only process intervals present in both raw & sinefit

tags/nilmtools-1.4.2^0
Jim Paris 10 years ago
parent
commit
6090dd6112
5 changed files with 24 additions and 7 deletions
  1. +2
    -1
      Makefile
  2. +1
    -1
      README.txt
  3. +6
    -2
      nilmtools/filter.py
  4. +14
    -2
      nilmtools/prep.py
  5. +1
    -1
      setup.py

+ 2
- 1
Makefile View File

@@ -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



+ 1
- 1
README.txt View File

@@ -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:



+ 6
- 2
nilmtools/filter.py View File

@@ -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)


+ 14
- 2
nilmtools/prep.py View File

@@ -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


+ 1
- 1
setup.py View File

@@ -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',


Loading…
Cancel
Save