[GRASS-SVN] r65098 - grass-addons/grass7/raster/r.hypso

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 19 07:53:08 PDT 2015


Author: madi
Date: 2015-04-19 07:53:08 -0700 (Sun, 19 Apr 2015)
New Revision: 65098

Modified:
   grass-addons/grass7/raster/r.hypso/r.hypso.py
Log:
fixed findint function to handle the case in which the function presents two min

Modified: grass-addons/grass7/raster/r.hypso/r.hypso.py
===================================================================
--- grass-addons/grass7/raster/r.hypso/r.hypso.py	2015-04-19 11:20:56 UTC (rev 65097)
+++ grass-addons/grass7/raster/r.hypso/r.hypso.py	2015-04-19 14:53:08 UTC (rev 65098)
@@ -53,6 +53,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 = 'inc').split('\n')[:-1]
@@ -115,8 +116,14 @@
 
 
 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]  # added this further step to handle the case the function has 2 min
+    z1 = kl[float(Xf)][0] 
+    z2 = kl[float(Xf-1)][0]
+    f1 = kl[float(Xf)][1] 
+    f2 = kl[float(Xf-1)][1] 
     z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
     return z
 



More information about the grass-commit mailing list