[GRASS-SVN] r73602 - grass-addons/grass7/raster/r.width.funct

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 23 03:26:54 PDT 2018


Author: madi
Date: 2018-10-23 03:26:54 -0700 (Tue, 23 Oct 2018)
New Revision: 73602

Modified:
   grass-addons/grass7/raster/r.width.funct/r.width.funct.py
Log:
fixed findint function to handle the case in which the function presents two min, similarly to what was done for r.hypso

Modified: grass-addons/grass7/raster/r.width.funct/r.width.funct.py
===================================================================
--- grass-addons/grass7/raster/r.width.funct/r.width.funct.py	2018-10-22 21:31:49 UTC (rev 73601)
+++ grass-addons/grass7/raster/r.width.funct/r.width.funct.py	2018-10-23 10:26:54 UTC (rev 73602)
@@ -47,6 +47,7 @@
 import matplotlib.pyplot as plt
 import grass.script as grass
 import numpy as np
+from operator import itemgetter
 
 def main():
     stats = grass.read_command('r.stats', input = options['map'], sep = 'space', nv = '*', nsteps = '255', flags = 'Anc').split('\n')[:-1]
@@ -120,8 +121,10 @@
     plt.close('all')
 
 def findint(kl,f):
-    Xf = np.abs(kl-f); Xf = np.where(Xf==Xf.min())
-    #z1, z2, f1, f2 = kl[float(Xf[0])][0], kl[float(Xf[0]-1)][0], kl[float(Xf[0])][1], kl[float(Xf[0]-1)][1]
+    Xf = np.abs(kl-f); 
+    Xf = np.where(Xf==Xf.min())
+    item = itemgetter(0)(Xf)
+    Xf = item[0]
     z1, z2, f1, f2 = kl[int(Xf[0])][0], kl[int(Xf[0]-1)][0], kl[int(Xf[0])][1], kl[int(Xf[0]-1)][1]
     z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
     return z



More information about the grass-commit mailing list