[GRASS-SVN] r40851 - in grass-addons/raster: . r.ipso r.wf

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 7 19:11:28 EST 2010


Author: epifanio
Date: 2010-02-07 19:11:27 -0500 (Sun, 07 Feb 2010)
New Revision: 40851

Added:
   grass-addons/raster/r.ipso/
   grass-addons/raster/r.ipso/Makefile
   grass-addons/raster/r.ipso/description.html
   grass-addons/raster/r.ipso/r.ipso.py
   grass-addons/raster/r.wf/
   grass-addons/raster/r.wf/Makefile
   grass-addons/raster/r.wf/description.html
   grass-addons/raster/r.wf/r.wf.py
Log:
Added two new addons, r.ipso.py and r.wf.py (output ipsometric, ipsographic and width function graphs)

Added: grass-addons/raster/r.ipso/Makefile
===================================================================
--- grass-addons/raster/r.ipso/Makefile	                        (rev 0)
+++ grass-addons/raster/r.ipso/Makefile	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.ipso
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/raster/r.ipso/description.html
===================================================================
--- grass-addons/raster/r.ipso/description.html	                        (rev 0)
+++ grass-addons/raster/r.ipso/description.html	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,60 @@
+<H2>DESCRIPTION</H2>
+
+
+<EM><B>r.ipso</B></EM> outputs the Ipsometric and Ipsographic curve from elevation dataset and print out percentiles.
+
+
+<H2>Options</H2>
+
+<B>[-a]</B> Output ipsometric graph.
+
+<Br>
+<Br>
+<B>[-b]</B> Output ipsographic graph.
+
+</B>
+
+<H2>NOTES</H2>
+
+This curve gives the distribution of surfaces in different altitude ranges. Each
+ipsografica point on the curve has a value of quota as ordered and as the abscissa
+proportion of the surface of the basin placed above the share in question. Having to
+provide a DEM, the curve that is obtained simply as a vector, ordered
+decreasing effect of allowances of pixels. Representing the carrier on a diagram
+Descartes, no ordinal is proportional to the area above the quota and is given
+the abscissa.
+The curve is represented by the shares corresponding to percentages of area dominated
+(2.5%, 5%, 10%, 25%, 50%, 75%, 90%, 95%, 97.5%).
+The ipsometric graph is the same as ipsographic graph but using adimensional axes.
+
+<H2>EXAMPLE</H2>
+
+Generate iposographic graph
+
+<div class="code"><pre>
+r.ipso.py -b map=elevation.10m image=path/to/output/prefix
+</pre></div>
+<p>
+
+Generate iposmetric graph
+
+<div class="code"><pre>
+r.ipso.py -a map=elevation.10m image=path/to/output/prefix
+</pre></div>
+
+
+
+<H2>REFERENCES</H2>
+ 
+Fractal River Basins - Chance and self organization ( Igatio Rodriguez-Iturbe & Andrea Rinaldo ).
+
+<H2>SEE ALSO</H2>
+
+<EM><A HREF="r.wf.html">r.wf.py</A></EM>
+
+<H2>AUTHOR</H2>
+
+Massimo Di Stefano, Francesco Di Stefano <br>
+
+
+<p><i>Last changed: $Date: 2010-02-07 00:45:10 +0200 (Mon, 7 Feb 2010) $</i>

Added: grass-addons/raster/r.ipso/r.ipso.py
===================================================================
--- grass-addons/raster/r.ipso/r.ipso.py	                        (rev 0)
+++ grass-addons/raster/r.ipso/r.ipso.py	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+################################################################################
+#
+# MODULE:       r.ipso.py
+#
+# AUTHOR(S):    Massimo Di Stefano, Francesco Di Stefano 2010-02-7
+#               
+#
+# PURPOSE:      Output a Ipsometric and ipsographic graph 
+#
+# COPYRIGHT:    (c) 2010 by the GRASS Development Team
+#
+#               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
+#% key: map
+#% type: string
+#% gisprompt: old,raster,raster
+#% key_desc: name
+#% description: Name of raster map 
+#% required: yes
+#%end
+#%option
+#% key: image
+#% type: string
+#% gisprompt: new_file,file,input
+#% key_desc: image
+#% description: output graph
+#% required: yes
+#%end
+#%flag
+#% key: a
+#% description: generate ipsometric curve
+#%END
+#%flag
+#% key: b
+#% description: generate ipsographic curve
+#%END
+
+import sys
+import os
+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'], fs = 'space', nv = '*', nsteps = '255', flags = 'inc').split('\n')[:-1]
+    res = float(grass.read_command('g.region', rast = options['map'], flags = 'm').strip().split('\n')[4].split('=')[1])
+    zn = np.zeros((len(stats),6),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,2] = zn[i,1]
+        if i != 0:
+            zn[i,0], zn[i, 1] = map(float, stats[i].split(' '))
+            zn[i,2] = zn[i,1] + zn[i-1,2]
+    totcell = sum(zn[:,1])
+    for i in range(len(stats)):
+        zn[i,3] = 1 - (zn[i,2] / sum(zn[:,1]))
+        zn[i,4] = zn[i,3] * (((res**2)/1000000)*sum(zn[:,1]))
+        zn[i,5] = ((zn[i,0] - min(zn[:,0])) / (max(zn[:,0]) - min(zn[:,0])) )
+        kl[i,0] = zn[i,0]
+        kl[i,1] = 1 - (zn[i,2] / totcell)
+    prc[0,0] , prc[0,1] = findint(kl,0.025) , 0.025
+    prc[1,0] , prc[1,1] = findint(kl,0.05) , 0.05
+    prc[2,0] , prc[2,1] = findint(kl,0.1) , 0.1
+    prc[3,0] , prc[3,1] = findint(kl,0.25) , 0.25
+    prc[4,0] , prc[4,1] = findint(kl,0.5) , 0.5
+    prc[5,0] , prc[5,1] = findint(kl,0.75) , 0.75
+    prc[6,0] , prc[6,1] = findint(kl,0.9) , 0.9
+    prc[7,0] , prc[7,1] = findint(kl,0.95) , 0.95
+    prc[8,0] , prc[8,1] = findint(kl,0.975) , 0.975
+    if flags['a']:
+        plotImage(zn[:,3], zn[:,5],options['image']+'_Ipsometric.png','-','A(i) / A','Z(i) / Zmax','Ipsometric Curve')
+    if flags['b']:
+        plotImage(zn[:,4], zn[:,0],options['image']+'_Ipsographic.png','-','A [km^2]','Z [m.slm]','Ipsographic Curve')
+    print prc
+
+
+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
+
+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') 
+    
+if __name__ == "__main__":
+	options, flags = grass.parser()
+	sys.exit(main())
+
+


Property changes on: grass-addons/raster/r.ipso/r.ipso.py
___________________________________________________________________
Added: svn:executable
   + *

Added: grass-addons/raster/r.wf/Makefile
===================================================================
--- grass-addons/raster/r.wf/Makefile	                        (rev 0)
+++ grass-addons/raster/r.wf/Makefile	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.ipso
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/raster/r.wf/description.html
===================================================================
--- grass-addons/raster/r.wf/description.html	                        (rev 0)
+++ grass-addons/raster/r.wf/description.html	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,37 @@
+<H2>DESCRIPTION</H2>
+
+
+<EM><B>r.wf</B></EM> outputs the Width function from the outlet distance map (r.stream.distance output) and print out percentiles.
+
+
+<H2>NOTES</H2>
+
+The width function defined as the number of pixels having equal
+metric distance from the closing section measured by following the directions of drainage.
+They are calculated as a synthesis of the first 4 statistical moments (mean, variance, skewness,
+kurtosis) and percentiles, or the percentage of pixels within a certain distance from section
+closure (5%, 15%, 30%, 40%, 50%, 60%, 70%, 85%, 95%).
+
+<H2>EXAMPLE</H2>
+
+
+<div class="code"><pre>
+r.wf.py map=dst2out image=path/to/output/prefix
+</pre></div>
+<p>
+
+
+<H2>REFERENCES</H2>
+ 
+Fractal River Basins - Chance and self organization ( Igatio Rodriguez-Iturbe & Andrea Rinaldo ).
+
+<H2>SEE ALSO</H2>
+
+<EM><A HREF="r.ipso.html">r.ipso.py</A></EM>
+
+<H2>AUTHOR</H2>
+
+Massimo Di Stefano, Francesco Di Stefano <br>
+
+
+<p><i>Last changed: $Date: 2010-02-07 00:45:10 +0200 (Mon, 7 Feb 2010) $</i>

Added: grass-addons/raster/r.wf/r.wf.py
===================================================================
--- grass-addons/raster/r.wf/r.wf.py	                        (rev 0)
+++ grass-addons/raster/r.wf/r.wf.py	2010-02-08 00:11:27 UTC (rev 40851)
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+################################################################################
+#
+# MODULE:       r.wf.py
+#
+# AUTHOR(S):    Massimo Di Stefano, Francesco Di Stefano 2010-02-7
+#               
+#
+# PURPOSE:      Output a Width function graph 
+#
+# COPYRIGHT:    (c) 2010 by the GRASS Development Team
+#
+#               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
+#% key: map
+#% type: string
+#% gisprompt: old,raster,raster
+#% key_desc: name
+#% description: Name of raster map 
+#% required: yes
+#%end
+#%option
+#% key: image
+#% type: string
+#% gisprompt: new_file,file,input
+#% key_desc: image
+#% description: output graph
+#% required: yes
+#%end
+
+
+import sys
+import os
+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'], fs = 'space', nv = '*', nsteps = '255', flags = 'inc').split('\n')[:-1]
+    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])
+    for i in range(len(stats)):
+        kl[i,0] = zn[i,0]
+        kl[i,1] = 1 - (zn[i,2] / totcell)
+    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
+    plotImage(zn[:,0], zn[:,3],options['image']+'_width_function.png','-','L [m]','A [m^2]','Width Function')
+    print prc
+
+
+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/raster/r.wf/r.wf.py
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list