From: W. Trevor King Date: Fri, 20 Jul 2012 19:22:34 +0000 (-0400) Subject: Update igorbinarywave.py to use dynamic structure interface. X-Git-Tag: v0.2~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e1ebd507208067303a0838e54ece88e76fef9691;p=igor.git Update igorbinarywave.py to use dynamic structure interface. --- diff --git a/bin/igorbinarywave.py b/bin/igorbinarywave.py index f3da1cd..9d0fa0e 100755 --- a/bin/igorbinarywave.py +++ b/bin/igorbinarywave.py @@ -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)