Merge branch 'binary'
This commit is contained in:
commit
4e64c804bf
2
setup.py
2
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.4.6',
|
||||
install_requires = [ 'nilmdb >= 1.4.8',
|
||||
'numpy',
|
||||
'scipy',
|
||||
'matplotlib',
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import nilmtools.filter
|
||||
import nilmdb.client
|
||||
from nilmdb.client.numpyclient import NumpyClient
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
|
@ -27,14 +28,14 @@ def main(argv = None):
|
|||
meta = f.client_src.stream_get_metadata(f.src.path)
|
||||
f.check_dest_metadata(meta)
|
||||
|
||||
# Copy all rows of data as ASCII strings
|
||||
extractor = nilmdb.client.Client(f.src.url).stream_extract
|
||||
inserter = nilmdb.client.Client(f.dest.url).stream_insert_context
|
||||
# Copy all rows of data using the faster Numpy interfaces
|
||||
extractor = NumpyClient(f.src.url).stream_extract_numpy
|
||||
inserter = NumpyClient(f.dest.url).stream_insert_numpy_context
|
||||
for i in f.intervals():
|
||||
print "Processing", f.interval_string(i)
|
||||
with inserter(f.dest.path, i.start, i.end) as insert_ctx:
|
||||
for row in extractor(f.src.path, i.start, i.end):
|
||||
insert_ctx.insert(row + "\n")
|
||||
for data in extractor(f.src.path, i.start, i.end):
|
||||
insert_ctx.insert(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -71,7 +71,7 @@ def decimate(data, interval, args, insert_function, final):
|
|||
data = data[:n,:]
|
||||
|
||||
# Reshape it into 3D so we can process 'factor' rows at a time
|
||||
data.shape = (n // factor, factor, m)
|
||||
data = data.reshape(n // factor, factor, m)
|
||||
|
||||
# Fill the result
|
||||
out = np.c_[ np.mean(data[:,:,mean_col], axis=1),
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import absolute_import
|
|||
|
||||
import nilmdb.client
|
||||
from nilmdb.client import Client
|
||||
from nilmdb.client.numpyclient import NumpyClient
|
||||
from nilmdb.utils.printf import *
|
||||
from nilmdb.utils.time import (parse_time, timestamp_to_human,
|
||||
timestamp_to_seconds)
|
||||
|
@ -277,8 +278,8 @@ class Filter(object):
|
|||
"""
|
||||
if args is None:
|
||||
args = []
|
||||
extractor = Client(self.src.url).stream_extract
|
||||
inserter = Client(self.dest.url).stream_insert_context
|
||||
extractor = NumpyClient(self.src.url).stream_extract_numpy
|
||||
inserter = NumpyClient(self.dest.url).stream_insert_numpy_context
|
||||
|
||||
# Format output data.
|
||||
formatter = lambda row: " ".join([repr(x) for x in row]) + "\n"
|
||||
|
@ -292,22 +293,12 @@ class Filter(object):
|
|||
print "Processing", self.interval_string(interval)
|
||||
with inserter(self.dest.path,
|
||||
interval.start, interval.end) as insert_ctx:
|
||||
def insert_function(array):
|
||||
s = cStringIO.StringIO()
|
||||
if len(np.shape(array)) != 2:
|
||||
raise Exception("array must be 2-dimensional")
|
||||
np.savetxt(s, array)
|
||||
insert_ctx.insert(s.getvalue())
|
||||
|
||||
extract = extractor(self.src.path, interval.start, interval.end)
|
||||
insert_function = insert_ctx.insert
|
||||
old_array = np.array([])
|
||||
for batched in batch(extract, rows):
|
||||
# Read in this batch of data. This turns out to
|
||||
# be a very fast way to read and convert it (order
|
||||
# of magnitude faster than numpy.loadtxt)
|
||||
new_array = np.fromstring("\n".join(batched), sep=' ')
|
||||
new_array = new_array.reshape(-1, self.src.total_count)
|
||||
|
||||
for new_array in extractor(self.src.path,
|
||||
interval.start, interval.end,
|
||||
layout = self.src.layout,
|
||||
maxrows = rows):
|
||||
# If we still had old data left, combine it
|
||||
if old_array.shape[0] != 0:
|
||||
array = np.vstack((old_array, new_array))
|
||||
|
|
Loading…
Reference in New Issue
Block a user