[GRASS-SVN] r69768 - in grass-addons/grass7/vector: . v.faultdirections

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 4 02:41:11 PDT 2016


Author: mlennert
Date: 2016-11-04 02:41:11 -0700 (Fri, 04 Nov 2016)
New Revision: 69768

Added:
   grass-addons/grass7/vector/v.faultdirections/
   grass-addons/grass7/vector/v.faultdirections/Makefile
   grass-addons/grass7/vector/v.faultdirections/v.faultdirections.html
   grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py
Log:
v.faultdirections: first commit


Added: grass-addons/grass7/vector/v.faultdirections/Makefile
===================================================================
--- grass-addons/grass7/vector/v.faultdirections/Makefile	                        (rev 0)
+++ grass-addons/grass7/vector/v.faultdirections/Makefile	2016-11-04 09:41:11 UTC (rev 69768)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.faultdirections
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/vector/v.faultdirections/v.faultdirections.html
===================================================================
--- grass-addons/grass7/vector/v.faultdirections/v.faultdirections.html	                        (rev 0)
+++ grass-addons/grass7/vector/v.faultdirections/v.faultdirections.html	2016-11-04 09:41:11 UTC (rev 69768)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+<p>
+<em>v.faultdirections</em> draws a polar barplot of fault directions, with
+values binned according to the <em>step</em> parameter. Directions have to 
+be stored in an attribute column of the vector map containing the faults.
+
+<p>
+The parameter <em>legend_angle</em> allows positioning the radial axis. By
+setting the flag <em>a</em> the user can choose to display absolute number
+of lines as radial axis labels instead of the default percentages.
+
+<h2>NOTES</h2>
+
+The module <a href="v.to.db.html">v.to.db</a> can be used to load azimuth 
+directions into the attribute table.
+<p>
+The plot can be saved to a graphics file interactively from the matplotlib
+window.
+
+<h2>DEPENDENCIES</h2>
+
+This module depends on matplotlib and on tkinter (aka python-tk). It is the
+users responsibility to make sure both are installed.
+
+
+<h2>EXAMPLE</h2>
+
+Load azimuth directions into the attribute map and draw plot:
+
+<div class="code"><pre>
+v.db.addcolumn faultmap col="azimuth double precision"
+v.to.db faultmap option=azimuth colum=azimuth
+v.faultdirections faultmap column=azimuth step=10
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.to.db.html">v.to.db</a>
+</em>
+
+<h2>AUTHOR</h2>
+ Moritz Lennert
+
+<p><i>Last changed: $Date: 2014-10-20 12:38:08 +0200 (lun 20 oct 2014) $</i>

Added: grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py
===================================================================
--- grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py	                        (rev 0)
+++ grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py	2016-11-04 09:41:11 UTC (rev 69768)
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:       v.faultdirections
+# AUTHOR:       Moritz Lennert
+# PURPOSE:      Creates a polar plot of fault directions
+#
+# COPYRIGHT:    (c) 2016 Moritz Lennert, and 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.
+#
+#############################################################################
+
+#%module
+#% description: Creates a polar plot of fault directions
+#% keyword: display
+#% keyword: vector
+#% keyword: geology
+#%end
+#%option G_OPT_V_MAP
+#%end
+#%option G_OPT_DB_COLUMN
+#% key: column
+#% description: Attribute column containing azimuth
+#% required: yes
+#%end
+#%option
+#% key: step
+#% type: integer
+#% description: Step of binning (in degrees)
+#% answer: 10
+#% required: no
+#%end
+#%option
+#% key: legend_angle
+#% type: double
+#% description: Angle at which to put the axis labels
+#% answer: 0.0
+#% required: no
+#%end
+#%flag
+#% key: a
+#% description: Use absolute values in legend, instead of percentages
+#%end
+
+
+import sys
+import numpy as np
+import matplotlib.pyplot as plt
+import grass.script as gscript
+
+
+def main():
+    vector = options['map']
+    column = options['column']
+    step = int(options['step'])
+    legend_angle = float(options['legend_angle'])
+
+    azimuth = []
+    for line in gscript.read_command('v.db.select',
+                                     map_=vector,
+                                     column=column,
+                                     flags='c').splitlines():
+	azimuth.append(float(line))
+   
+    bins = 360/step
+    az_bins = np.histogram(azimuth, bins=bins, range=(0,360))
+    if flags['a']:
+        radii = az_bins[0]
+        label = ''
+    else:
+        radii = [100.0*x/sum(az_bins[0]) for x in az_bins[0]]
+        label = '%'
+    theta = az_bins[1][:-1]
+    theta = theta * (np.pi/180)
+    width = 2 * np.pi / bins
+
+    ax = plt.subplot(111, projection='polar')
+    ax.set_theta_direction(-1)
+    ax.set_theta_offset(np.pi/2.0)
+    base = 5 if max(radii) > 10 else 2
+    labelstep = round((max(radii) - min(radii)) / 5)
+    labelstep = int(base * round(float(labelstep) / base))
+    labelradii = [x for x in np.arange(0, int(np.ceil(max(radii))), labelstep) if x > 0]
+    ax.set_rgrids(labelradii, angle=legend_angle)
+    ax.text(legend_angle*(np.pi/180), max(radii)*1.1, label)
+    bars = ax.bar(theta, radii, width=width, bottom=0.0)
+
+    # Use custom colors and opacity
+    for r, bar in zip(radii, bars):
+	bar.set_alpha(0.5)
+
+    plt.show()
+
+if __name__ == "__main__":
+    options, flags = gscript.parser()
+    sys.exit(main())
+


Property changes on: grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list