changeset 133:8b120c7f0cf9

lets call it a night
author Jeff Hammel <k0scist@gmail.com>
date Mon, 16 Mar 2015 21:53:31 -0700
parents 2261362fe341
children b6242f916cef
files numerics/plot.py numerics/read.py
diffstat 2 files changed, 10 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/plot.py	Mon Mar 16 21:39:00 2015 -0700
+++ b/numerics/plot.py	Mon Mar 16 21:53:31 2015 -0700
@@ -21,6 +21,7 @@
 import numpy as np
 import os
 import sys
+from .manipulate import ManipulationParser
 
 # module globals
 __all__ = ['Plot', 'PlotParser', 'read', 'main']
@@ -93,33 +94,19 @@
     return retval
 
 
-class PlotParser(argparse.ArgumentParser):
+class PlotParser(ManipulationParser):
     """CLI option parser for the plotter"""
 
     types = (float,)
 
     def __init__(self, *args, **kwargs):
         kwargs.setdefault('description', __doc__)
-        argparse.ArgumentParser.__init__(self, *args, **kwargs)
-        self.add_argument('input',
-                          type=argparse.FileType('r'), nargs='*',
-                          default=(sys.stdin,),
-                          help='input file(s), or read from stdin if ommitted')
-        self.add_argument('-o', '--output', dest='output',
-                          help="file name to output to")
+        ManipulationParser.__init__(self, *args, **kwargs)
         self.add_argument('-s', '--scatter', dest='scatter',
                           action='store_true', default=False,
                           help="scatter plot")
         self.options = None
-
-    def parse_args(self, *args, **kwargs):
-        options = argparse.ArgumentParser.parse_args(self, *args, **kwargs)
-        self.validate(options)
-        self.options = options
-        return options
-
-    def validate(self, options):
-        """validate options"""
+        self.set_defaults(output=None)
 
 
 def main(args=sys.argv[1:]):
@@ -133,7 +120,8 @@
     plot_fcn = plt.scatter if options.scatter else plt.plot
 
     # read data
-    all_data = [read(f) for f in options.input]
+    all_data = [read(open(f)) # quick hack
+                for f in options.input]
 
     # color map
     # http://stackoverflow.com/questions/12236566/setting-different-color-for-each-series-in-scatter-plot-on-matplotlib
--- a/numerics/read.py	Mon Mar 16 21:39:00 2015 -0700
+++ b/numerics/read.py	Mon Mar 16 21:53:31 2015 -0700
@@ -95,8 +95,8 @@
         kwargs.setdefault('description', __doc__)
         kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
         argparse.ArgumentParser.__init__(self, **kwargs)
-        self.add_argument('csv', nargs='*',
-                          help="CSV files to read, or read from stdin")
+        self.add_argument('input', nargs='*',
+                          help="CSV input files to read, or read from stdin")
         self.add_argument('-+', '--add', dest='added_columns', nargs='+',
                           help="append this column")
         self.add_argument('-c', '--col', '--columns', dest='columns',
@@ -118,14 +118,12 @@
 
     def validate(self, options):
         """validate options"""
-
-        if not options.csv:
-            options.csv = [sys.stdin]
+        options.input = options.input or [sys.stdin]
 
     def read(self):
         """read and process CSV"""
 
-        data = read_csv(*self.options.csv)
+        data = read_csv(*self.options.input)
 
         if self.options.added_columns:
             # add columns
@@ -164,10 +162,6 @@
                         help="transpose columns and rows")
     options = parser.parse_args(args)
 
-    if not options.csv:
-        # read from stdin
-        options.csv = [sys.stdin]
-
     # read CSV
     if options.transpose:
         data = parser.columns()