Update igorbinarywave.py to use dynamic structure interface.
authorW. Trevor King <wking@tremily.us>
Fri, 20 Jul 2012 19:22:34 +0000 (15:22 -0400)
committerW. Trevor King <wking@tremily.us>
Fri, 20 Jul 2012 19:22:34 +0000 (15:22 -0400)
bin/igorbinarywave.py

index f3da1cd79a243f4b1de79bc45f67164d66c81d3b..9d0fa0eb87d336529eb21d7cbdaf2bbb6d8d023d 100755 (executable)
@@ -4,14 +4,15 @@
 
 "IBW -> ASCII conversion"
 
+import logging
 import optparse
 import pprint
 import sys
 
 import numpy
 
-from igor import __version__
-from igor.binarywave import loadibw
+from igor import __version__, LOG
+from igor.binarywave import load
 
 
 p = optparse.OptionParser(version=__version__)
@@ -22,8 +23,6 @@ p.add_option('-o', '--outfile', dest='outfile', metavar='FILE',
              default='-', help='File for ASCII output.')
 p.add_option('-v', '--verbose', dest='verbose', default=0,
              action='count', help='Increment verbosity')
-p.add_option('-n', '--not-strict', dest='strict', default=True,
-             action='store_false', help='Attempt to parse invalid IBW files.')
 
 options,args = p.parse_args()
 
@@ -34,8 +33,13 @@ if options.infile == '-':
 if options.outfile == '-':
     options.outfile = sys.stdout
 
-data,bin_info,wave_info = loadibw(options.infile, strict=options.strict)
-numpy.savetxt(options.outfile, data, fmt='%g', delimiter='\t')
+if options.verbose > 1:
+    log_levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
+    log_level = log_levels[min(options.verbose-1, len(log_levels)-1)]
+    LOG.setLevel(log_level)
+
+wave = load(options.infile)
+numpy.savetxt(options.outfile, wave['wave']['wData'], fmt='%g', delimiter='\t')
 if options.verbose > 0:
-    pprint.pprint(bin_info)
-    pprint.pprint(wave_info)
+    wave['wave'].pop('wData')
+    pprint.pprint(wave)