You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.4 KiB

  1. #!/usr/bin/python
  2. # This is called copy_one instead of copy to avoid name conflicts with
  3. # the Python standard library.
  4. import nilmtools.filter
  5. import nilmdb.client
  6. from nilmdb.client.numpyclient import NumpyClient
  7. import numpy as np
  8. import sys
  9. def main(argv = None):
  10. f = nilmtools.filter.Filter()
  11. parser = f.setup_parser("Copy a stream")
  12. # Parse arguments
  13. try:
  14. args = f.parse_args(argv)
  15. except nilmtools.filter.MissingDestination as e:
  16. print "Source is %s (%s)" % (e.src.path, e.src.layout)
  17. print "Destination %s doesn't exist" % (e.dest.path)
  18. print "You could make it with a command like:"
  19. print " nilmtool -u %s create %s %s" % (e.dest.url,
  20. e.dest.path, e.src.layout)
  21. raise SystemExit(1)
  22. # Copy metadata
  23. meta = f.client_src.stream_get_metadata(f.src.path)
  24. f.check_dest_metadata(meta)
  25. # Copy all rows of data using the faster Numpy interfaces
  26. extractor = NumpyClient(f.src.url).stream_extract_numpy
  27. inserter = NumpyClient(f.dest.url).stream_insert_numpy_context
  28. for i in f.intervals():
  29. print "Processing", i.human_string()
  30. with inserter(f.dest.path, i.start, i.end) as insert_ctx:
  31. for data in extractor(f.src.path, i.start, i.end):
  32. insert_ctx.insert(data)
  33. if __name__ == "__main__":
  34. main()