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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 7 05:12:20 PDT 2017


Author: madi
Date: 2017-08-07 05:12:20 -0700 (Mon, 07 Aug 2017)
New Revision: 71333

Modified:
   grass-addons/grass7/raster/r.width.funct/r.width.funct.py
Log:
fixed warning: VisibleDeprecationWarning?: using a non-integer number instead of an integer will result in an error in the future

Modified: grass-addons/grass7/raster/r.width.funct/r.width.funct.py
===================================================================
--- grass-addons/grass7/raster/r.width.funct/r.width.funct.py	2017-08-06 21:56:32 UTC (rev 71332)
+++ grass-addons/grass7/raster/r.width.funct/r.width.funct.py	2017-08-07 12:12:20 UTC (rev 71333)
@@ -3,10 +3,10 @@
 #
 # MODULE:       r.width.funct
 #
-# AUTHOR(S):    Massimo Di Stefano, Francesco Di Stefano, Margherita Di Leo 
+# AUTHOR(S):    Massimo Di Stefano, Francesco Di Stefano, Margherita Di Leo
 #
-# PURPOSE:      The module produces the Width Function of a basin. The Width 
-#               Function W(x) gives the number of the cells in a basin at a 
+# PURPOSE:      The module produces the Width Function of a basin. The Width
+#               Function W(x) gives the number of the cells in a basin at a
 #               flow distance x from the outlet (distance-area function)
 #
 # COPYRIGHT:    (c) 2010 Massimo Di Stefano, Francesco Di Stefano, Margherita Di Leo
@@ -17,8 +17,8 @@
 #
 # REQUIRES:     Matplotlib
 #                 http://matplotlib.sourceforge.net/
-#               
 #
+#
 ################################################################################
 #%module
 #% description: Calculates the Width Function of a watershed basin.
@@ -28,7 +28,7 @@
 
 #%option G_OPT_R_INPUT
 #% key: map
-#% description: Distance to outlet map (from r.stream.distance) 
+#% description: Distance to outlet map (from r.stream.distance)
 #% required: yes
 #%end
 
@@ -52,7 +52,7 @@
     stats = grass.read_command('r.stats', input = options['map'], sep = 'space', nv = '*', nsteps = '255', flags = 'Anc').split('\n')[:-1]
 
     # res = cellsize
-    res = float(grass.read_command('g.region', raster = options['map'], flags = 'm').strip().split('\n')[4].split('=')[1])    
+    res = float(grass.read_command('g.region', raster = options['map'], flags = 'm').strip().split('\n')[4].split('=')[1])
     zn = np.zeros((len(stats),4),float)
     kl = np.zeros((len(stats),2),float)
     prc = np.zeros((9,2),float)
@@ -64,23 +64,23 @@
             zn[i,2] = zn[i,1] * res
         if i != 0:
             zn[i,0],  zn[i,1] = map(float, stats[i].split(' '))
-            zn[i,2] = zn[i,1] + zn[i-1,2] 
+            zn[i,2] = zn[i,1] + zn[i-1,2]
             zn[i,3] = zn[i,1] * (res**2)
-            
+
     totcell = sum(zn[:,1])
     print "Tot. cells", totcell
     totarea = totcell * (res**2)
     print "Tot. area", totarea
     maxdist = max(zn[:,0])
     print "Max distance", maxdist
- 
+
     for i in range(len(stats)):
-        kl[i,0] = zn[i,0] 
-        kl[i,1] = zn[i,2] / totcell 
+        kl[i,0] = zn[i,0]
+        kl[i,1] = zn[i,2] / totcell
 
     # quantiles
-    prc[0,0] , prc[0,1] = findint(kl,0.05) , 0.05   
-    prc[1,0] , prc[1,1] = findint(kl,0.15) , 0.15    
+    prc[0,0] , prc[0,1] = findint(kl,0.05) , 0.05
+    prc[1,0] , prc[1,1] = findint(kl,0.15) , 0.15
     prc[2,0] , prc[2,1] = findint(kl,0.3) , 0.3
     prc[3,0] , prc[3,1] = findint(kl,0.4) , 0.4
     prc[4,0] , prc[4,1] = findint(kl,0.5) , 0.5
@@ -88,7 +88,7 @@
     prc[6,0] , prc[6,1] = findint(kl,0.7) , 0.7
     prc[7,0] , prc[7,1] = findint(kl,0.85) , 0.85
     prc[8,0] , prc[8,1] = findint(kl,0.95) , 0.95
- 
+
     # plot
     plotImage(zn[:,0], zn[:,3], options['image']+'_width_function.png','-','x','W(x)','Width Function')
 
@@ -116,11 +116,11 @@
     plt.title(title)
     plt.grid(True)
     plt.savefig(image)
-    plt.close('all') 
+    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]
+    z1, z2, f1, f2 = kl[(Xf[0])][0], kl[(Xf[0]-1)][0], kl[(Xf[0])][1], kl[(Xf[0]-1)][1]
     z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
     return z
 
@@ -128,4 +128,3 @@
 if __name__ == "__main__":
     options, flags = grass.parser()
     sys.exit(main())
-



More information about the grass-commit mailing list