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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 26 05:10:18 PDT 2018


Author: mlennert
Date: 2018-10-26 05:10:18 -0700 (Fri, 26 Oct 2018)
New Revision: 73611

Modified:
   grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
Log:
i.segment.uspo: handle case where segmentation leads to one single segment

Modified: grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
===================================================================
--- grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2018-10-26 07:36:50 UTC (rev 73610)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2018-10-26 12:10:18 UTC (rev 73611)
@@ -365,6 +365,11 @@
                         len(autocor_per_raster)
                     result_queue.put([mapname, mean_lv, mean_autocor,
                                       threshold, minsize])
+            else:
+                # If resulting map contains only one segment, then give high
+                # value of variance and 0 for spatial autocorrelation in order
+                # to give this map a low priority
+                result_queue.put([mapname, 999999, 0, threshold, minsize])
 
     except:
         exc_info = sys.exc_info()
@@ -401,6 +406,11 @@
                     len(autocor_per_raster)
                 result_queue.put(
                     [mapname, mean_lv, mean_autocor, threshold, minsize])
+            else:
+                # If resulting map contains only one segment, then give high
+                # value of variance and 0 for spatial autocorrelation in order
+                # to give this map a low priority
+                result_queue.put([mapname, 999999, 0, threshold, minsize])
 
     except:
         exc_info = sys.exc_info()
@@ -910,31 +920,43 @@
 
         maplist += regional_maplist
         # Calculate optimization function values and get indices of best values
-        optlist = create_optimization_list(variancelist,
-                                           autocorlist,
-                                           opt_function,
-                                           alpha,
-                                           directions[indicator])
-        if rg:
-            regiondict[region] = zip(
-                threshlist, minsizelist, variancelist, autocorlist, optlist)
+        if max(variancelist) > min(variancelist) and max(autocorlist) > min(autocorlist):
+            optlist = create_optimization_list(variancelist,
+                                               autocorlist,
+                                               opt_function,
+                                               alpha,
+                                               directions[indicator])
+            if rg:
+                regiondict[region] = zip(
+                    threshlist, minsizelist, variancelist, autocorlist, optlist)
+            else:
+                regiondict[region] = zip(
+                    threshlist, hrlist, radiuslist, minsizelist, variancelist, autocorlist, optlist)
+
+            optimal_indices = find_optimal_value_indices(optlist, nb_best)
+            best_values[region] = []
+            rank = 1
+            for optind in optimal_indices:
+                if rg:
+                    best_values[region].append(
+                        [threshlist[optind], minsizelist[optind], optlist[optind]])
+                else:
+                    best_values[region].append([threshlist[optind], hrlist[optind],
+                                                radiuslist[optind], minsizelist[optind], optlist[optind]])
+                maps_to_keep.append([regional_maplist[optind], rank,
+                                     parms['region']])
+                rank += 1
         else:
-            regiondict[region] = zip(
-                threshlist, hrlist, radiuslist, minsizelist, variancelist, autocorlist, optlist)
-
-        optimal_indices = find_optimal_value_indices(optlist, nb_best)
-        best_values[region] = []
-        rank = 1
-        for optind in optimal_indices:
+            best_values[region] = []
             if rg:
                 best_values[region].append(
-                    [threshlist[optind], minsizelist[optind], optlist[optind]])
+                        [threshlist[0], minsizelist[0], -1])
             else:
-                best_values[region].append([threshlist[optind], hrlist[optind],
-                                            radiuslist[optind], minsizelist[optind], optlist[optind]])
-            maps_to_keep.append([regional_maplist[optind], rank,
-                                 parms['region']])
-            rank += 1
+                best_values[region].append([threshlist[0], hrlist[0],
+                                                radiuslist[0], minsizelist[0],
+                                                -1])
+                maps_to_keep.append([regional_maplist[0], -1,
+                                     parms['region']])
 
     # Create output
 



More information about the grass-commit mailing list