[GRASS-SVN] r72332 - grass-addons/grass7/imagery/i.segment.uspo

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 8 05:00:42 PST 2018


Author: mlennert
Date: 2018-03-08 05:00:42 -0800 (Thu, 08 Mar 2018)
New Revision: 72332

Modified:
   grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
Log:
i.segment.uspo: make output optional


Modified: grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
===================================================================
--- grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2018-03-07 14:10:29 UTC (rev 72331)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2018-03-08 13:00:42 UTC (rev 72332)
@@ -50,6 +50,7 @@
 #
 #%option G_OPT_F_OUTPUT
 #% description: Name for output file (- for standard output)
+#% required : no
 #%end
 #
 #%option G_OPT_R_OUTPUT
@@ -664,7 +665,9 @@
     rg = False
     if method == 'region_growing':
         rg = True
-    output = options['output']
+    output = False
+    if options['output']:
+        output = options['output']
     indicator = options['autocorrelation_indicator']
     parms['indicator'] = indicator
     opt_function = options['optimization_function']
@@ -870,24 +873,25 @@
     else:
         header_string = "region,threshold,hr,radius,minsize,variance,spatial_autocorrelation,optimization_criteria\n"
 
-    if output == '-':
-        sys.stdout.write(header_string)	
-	for region, resultslist in regiondict.iteritems():
-	    for result in resultslist:
-                output_string = "%s," % region
-		output_string += ",".join(map(str, result))
-                output_string += "\n"
-	    	sys.stdout.write(output_string)	
-    else:
-	of = open(output, 'w')
-        of.write(header_string)
-        for region, resultslist in regiondict.iteritems():
-	    for result in resultslist:
-                output_string = "%s," % region
-		output_string += ",".join(map(str, result))
-                output_string += "\n"
-                of.write(output_string)
-        of.close()
+    if output:
+        if output == '-':
+            sys.stdout.write(header_string)	
+            for region, resultslist in regiondict.iteritems():
+                for result in resultslist:
+                    output_string = "%s," % region
+                    output_string += ",".join(map(str, result))
+                    output_string += "\n"
+                    sys.stdout.write(output_string)	
+        else:
+            of = open(output, 'w')
+            of.write(header_string)
+            for region, resultslist in regiondict.iteritems():
+                for result in resultslist:
+                    output_string = "%s," % region
+                    output_string += ",".join(map(str, result))
+                    output_string += "\n"
+                    of.write(output_string)
+            of.close()
 
     # Output of best values found
     msg = "Best values:\n"



More information about the grass-commit mailing list