[GRASS-SVN] r58570 - in grass-addons/grass7/raster: . r.width.funct

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 31 11:17:53 PST 2013


Author: madi
Date: 2013-12-31 11:17:53 -0800 (Tue, 31 Dec 2013)
New Revision: 58570

Added:
   grass-addons/grass7/raster/r.width.funct/
   grass-addons/grass7/raster/r.width.funct/Makefile
   grass-addons/grass7/raster/r.width.funct/r.width.funct
   grass-addons/grass7/raster/r.width.funct/r.width.funct.html
Log:
replacing r.wf

Added: grass-addons/grass7/raster/r.width.funct/Makefile
===================================================================
--- grass-addons/grass7/raster/r.width.funct/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.width.funct/Makefile	2013-12-31 19:17:53 UTC (rev 58570)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.width.funct
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/raster/r.width.funct/r.width.funct
===================================================================
--- grass-addons/grass7/raster/r.width.funct/r.width.funct	                        (rev 0)
+++ grass-addons/grass7/raster/r.width.funct/r.width.funct	2013-12-31 19:17:53 UTC (rev 58570)
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+################################################################################
+#
+# MODULE:       r.width.funct
+#
+# 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 
+#               flow distance x from the outlet (distance-area function)
+#
+# COPYRIGHT:    (c) 2010 Massimo Di Stefano, Francesco Di Stefano, Margherita Di Leo
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+# REQUIRES:     Matplotlib
+#                 http://matplotlib.sourceforge.net/
+#               
+#
+################################################################################
+#%module
+#% description: 
+#% keywords: raster
+#%end
+
+#%option G_OPT_R_INPUT
+#% key: map
+#% description: Distance to outlet map (from r.stream.distance) 
+#% required: yes
+#%end
+
+#%option G_OPT_F_OUTPUT
+#% key: image
+#% key_desc: image
+#% description: Name for output graph file (png)
+#% required: yes
+#%END
+
+
+import sys
+import os
+import matplotlib #required by windows
+matplotlib.use('wx') #required by windows
+import matplotlib.pyplot as plt
+import grass.script as grass
+import numpy as np
+
+def main():
+    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', rast = 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)
+
+    for i in range(len(stats)):
+        if i == 0:
+            zn[i,0],  zn[i,1] = map(float, stats[i].split(' '))
+            zn[i,1] = zn[i,1]
+            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,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 
+
+    # 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[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
+    prc[5,0] , prc[5,1] = findint(kl,0.6) , 0.6
+    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')
+
+    print "==========================="
+    print "Whidth Function | quantiles"
+    print "==========================="
+    print '%.0f' %findint(kl,0.05) , "|", 0.05
+    print '%.0f' %findint(kl,0.15) , "|", 0.15
+    print '%.0f' %findint(kl,0.3) , "|", 0.3
+    print '%.0f' %findint(kl,0.4) , "|", 0.4
+    print '%.0f' %findint(kl,0.5) , "|", 0.5
+    print '%.0f' %findint(kl,0.6) , "|", 0.6
+    print '%.0f' %findint(kl,0.7) , "|", 0.7
+    print '%.0f' %findint(kl,0.85) , "|", 0.85
+    print '%.0f' %findint(kl,0.95) , "|", 0.95
+    print '\n'
+    print 'Done!'
+
+def plotImage(x,y,image,type,xlabel,ylabel,title):
+    plt.plot(x, y, type)
+    plt.ylabel(ylabel)
+    plt.xlabel(xlabel)
+    plt.xlim( min(x), max(x) )
+    plt.ylim( min(y), max(y) )
+    plt.title(title)
+    plt.grid(True)
+    plt.savefig(image)
+    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]
+    z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
+    return z
+
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
+


Property changes on: grass-addons/grass7/raster/r.width.funct/r.width.funct
___________________________________________________________________
Added: svn:executable
   + *

Added: grass-addons/grass7/raster/r.width.funct/r.width.funct.html
===================================================================
--- grass-addons/grass7/raster/r.width.funct/r.width.funct.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.width.funct/r.width.funct.html	2013-12-31 19:17:53 UTC (rev 58570)
@@ -0,0 +1,53 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.width.funct</em> 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 (it is also referred as distance-area 
+function). It is important to underline the fact that the distance 
+is not the euclidean one, but it is measured along the flowpath 
+towards the outlet.
+
+<h3>Input</h3>
+
+<em>Distance to outlet map: </em>Input map, required. It is obtained 
+by r.stream.distance (with the option: distance to outlet, flag -o).
+<p>	
+<em>Output plot: </em> Path and name of the plot.
+
+<h3>Output</h3>
+
+It provides the quantiles of the area - distance distribution and 
+the plot of the Width Function. In x axis is reported the distance 
+and in y axis is the area.
+
+<h3>Dependencies</h3>
+<ul>
+<li>Matplotlib</li>
+</ul>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.stream.distance.html">r.stream.distance</a>,
+<a href="r.basin.html">r.basin</a>,
+</em>
+
+<h2>REFERENCES</h2>
+<ul>
+<li><em>Rodriguez-Iturbe I., Rinaldo A. — Fractal River 
+Basins, Chance and Self-Organization. Cambridge Press (2001)</em>
+<li><em>In Italian: Di Leo M., Di Stefano M., Claps P., Sole A. 
+— Caratterizzazione morfometrica del bacino idrografico in 
+GRASS GIS (Morphometric characterization of the catchment in GRASS 
+GIS environment),
+<a href="http://geomatica.como.polimi.it/workbooks/">Geomatics Workbooks</a>,
+n. 9 (2010)</em>
+</ul>
+        
+<h2>AUTHORS</h2>
+
+Margherita Di Leo (dileomargherita AT gmail DOT com), Massimo Di 
+Stefano, Francesco Di Stefano
+
+<p>
+<i>Last changed: $Date: 2013-07-13 16:00:03 +0200 (Sat, 13 Jul 2013) $</i>



More information about the grass-commit mailing list