diff python/utils.py @ 332:a6ca86107f27

reorganized utils module
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 14 Jun 2013 09:53:32 -0400
parents 99ca91a46007
children c9201f6b143a
line wrap: on
line diff
--- a/python/utils.py	Fri Jun 14 08:56:54 2013 -0400
+++ b/python/utils.py	Fri Jun 14 09:53:32 2013 -0400
@@ -22,39 +22,6 @@
     return result
 
 #########################
-# CLI utils
-#########################
-
-def parseCLIOptions(helpMessage, options, cliArgs, optionalOptions=[]):
-    ''' Simple function to handle similar argument parsing
-    Returns the dictionary of options and their values
-
-    * cliArgs are most likely directly sys.argv 
-    (only the elements after the first one are considered)
-    
-    * options should be a list of strings for getopt options, 
-    eg ['frame=','correspondences=','video=']
-    A value must be provided for each option, or the program quits'''
-    import sys, getopt
-    from numpy.core.fromnumeric import all
-    optionValues, args = getopt.getopt(cliArgs[1:], 'h', ['help']+options+optionalOptions)
-    optionValues = dict(optionValues)
-
-    if '--help' in optionValues.keys() or '-h' in optionValues.keys():
-        print(helpMessage+
-              '\n - Compulsory options: '+' '.join([opt.replace('=','') for opt in options])+
-              '\n - Non-compulsory options: '+' '.join([opt.replace('=','') for opt in optionalOptions]))
-        sys.exit()
-
-    missingArgument = [('--'+opt.replace('=','') in optionValues.keys()) for opt in options]
-    if not all(missingArgument):
-        print('Missing argument')
-        print(optionValues)
-        sys.exit()
-
-    return optionValues
-
-#########################
 # simple statistics
 #########################
 
@@ -287,6 +254,15 @@
 # plotting section
 #########################
 
+def plotPolygon(poly, options = ''):
+    'Plots shapely polygon poly'
+    from numpy.core.multiarray import array
+    from matplotlib.pyplot import plot
+    from shapely.geometry import Polygon
+
+    tmp = array(poly.exterior)
+    plot(tmp[:,0], tmp[:,1], options)
+
 def stepPlot(X, firstX, lastX, initialCount = 0, increment = 1):
     '''for each value in X, increment by increment the initial count
     returns the lists that can be plotted 
@@ -420,14 +396,6 @@
     else:
         print(filename+' does not exist')
 
-def plotPolygon(poly, options = ''):
-    from numpy.core.multiarray import array
-    from matplotlib.pyplot import plot
-    from shapely.geometry import Polygon
-
-    tmp = array(poly.exterior)
-    plot(tmp[:,0], tmp[:,1], options)
-
 def line2Floats(l, separator=' '):
     '''Returns the list of floats corresponding to the string'''
     return [float(x) for x in l.split(separator)]
@@ -437,6 +405,41 @@
     return [int(x) for x in l.split(separator)]
 
 #########################
+# CLI utils
+#########################
+
+def parseCLIOptions(helpMessage, options, cliArgs, optionalOptions=[]):
+    ''' Simple function to handle similar argument parsing
+    Returns the dictionary of options and their values
+
+    * cliArgs are most likely directly sys.argv 
+    (only the elements after the first one are considered)
+    
+    * options should be a list of strings for getopt options, 
+    eg ['frame=','correspondences=','video=']
+    A value must be provided for each option, or the program quits'''
+    import sys, getopt
+    from numpy.core.fromnumeric import all
+    optionValues, args = getopt.getopt(cliArgs[1:], 'h', ['help']+options+optionalOptions)
+    optionValues = dict(optionValues)
+
+    if '--help' in optionValues.keys() or '-h' in optionValues.keys():
+        print(helpMessage+
+              '\n - Compulsory options: '+' '.join([opt.replace('=','') for opt in options])+
+              '\n - Non-compulsory options: '+' '.join([opt.replace('=','') for opt in optionalOptions]))
+        sys.exit()
+
+    missingArgument = [('--'+opt.replace('=','') in optionValues.keys()) for opt in options]
+    if not all(missingArgument):
+        print('Missing argument')
+        print(optionValues)
+        sys.exit()
+
+    return optionValues
+
+
+
+#########################
 # sqlite
 #########################