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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 18 10:24:16 PDT 2018


Author: mlennert
Date: 2018-03-18 10:24:16 -0700 (Sun, 18 Mar 2018)
New Revision: 72382

Modified:
   grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
Log:
i.segment.uspo: avoid zero division errors


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-18 17:13:01 UTC (rev 72381)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2018-03-18 17:24:16 UTC (rev 72382)
@@ -610,6 +610,12 @@
 
     maxval = max(crit_list)
     minval = min(crit_list)
+
+    # If maxval = minval then results are not useful so set
+    # all value to 0
+    if float(maxval) - float(minval) == 0:
+        return [0]*len(crit_list)
+
     if direction == 'low':
         normlist = [float(maxval - x) / float(maxval - minval) for x in crit_list]
     else:
@@ -625,7 +631,10 @@
     if opt_function == 'sum':
         optlist = [normvariance[x] + normautocor[x] for x in range(len(normvariance))]
     if opt_function == 'f':
-        optlist = [( 1 + alpha**2 ) * ( ( normvariance[x] * normautocor[x] ) / float( alpha**2 * normautocor[x] + normvariance[x] ) ) for x in range(len(normvariance))]
+        optlist = [( 1 + alpha**2 ) * ( ( normvariance[x] * normautocor[x] ) / 
+                    float( alpha**2 * normautocor[x] + normvariance[x] ) ) 
+                    if (normautocor[x] + normvariance[x]) > 0 else 0 
+                    for x in range(len(normvariance))]
     return optlist
 
 



More information about the grass-commit mailing list