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.
 
 
 
 

45 lines
1.5 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. parser.add_argument('-n', '--nometa', action='store_true',
  13. help="Don't copy or check metadata")
  14. # Parse arguments
  15. try:
  16. args = f.parse_args(argv)
  17. except nilmtools.filter.MissingDestination as e:
  18. print "Source is %s (%s)" % (e.src.path, e.src.layout)
  19. print "Destination %s doesn't exist" % (e.dest.path)
  20. print "You could make it with a command like:"
  21. print " nilmtool -u %s create %s %s" % (e.dest.url,
  22. e.dest.path, e.src.layout)
  23. raise SystemExit(1)
  24. # Copy metadata
  25. if not args.nometa:
  26. meta = f.client_src.stream_get_metadata(f.src.path)
  27. f.check_dest_metadata(meta)
  28. # Copy all rows of data using the faster Numpy interfaces
  29. extractor = NumpyClient(f.src.url).stream_extract_numpy
  30. inserter = NumpyClient(f.dest.url).stream_insert_numpy_context
  31. for i in f.intervals():
  32. print "Processing", i.human_string()
  33. with inserter(f.dest.path, i.start, i.end) as insert_ctx:
  34. for data in extractor(f.src.path, i.start, i.end):
  35. insert_ctx.insert(data)
  36. if __name__ == "__main__":
  37. main()