[GRASS-SVN] r71320 - in grass-addons/grass7/display: . d.explanation.plot

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 30 14:04:35 PDT 2017


Author: wenzeslaus
Date: 2017-07-30 14:04:34 -0700 (Sun, 30 Jul 2017)
New Revision: 71320

Added:
   grass-addons/grass7/display/d.explanation.plot/
   grass-addons/grass7/display/d.explanation.plot/Makefile
   grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.html
   grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.py
   grass-addons/grass7/display/d.explanation.plot/d_explanation_plot.png
Modified:
   grass-addons/grass7/display/Makefile
Log:
d.explanation.plot: help explaning functionality of raster modules with a picture (see e.g. r71319)

Modified: grass-addons/grass7/display/Makefile
===================================================================
--- grass-addons/grass7/display/Makefile	2017-07-30 04:15:07 UTC (rev 71319)
+++ grass-addons/grass7/display/Makefile	2017-07-30 21:04:34 UTC (rev 71320)
@@ -1,6 +1,7 @@
 MODULE_TOPDIR = ..
 
 SUBDIRS = \
+	d.explanation.plot \
 	d.frame \
 	d.mon2 \
 	d.vect.thematic2

Added: grass-addons/grass7/display/d.explanation.plot/Makefile
===================================================================
--- grass-addons/grass7/display/d.explanation.plot/Makefile	                        (rev 0)
+++ grass-addons/grass7/display/d.explanation.plot/Makefile	2017-07-30 21:04:34 UTC (rev 71320)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM=d.explanation.plot
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.html
===================================================================
--- grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.html	                        (rev 0)
+++ grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.html	2017-07-30 21:04:34 UTC (rev 71320)
@@ -0,0 +1,99 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.explantion.plot</em> creates a plot of rasters and their relations
+which can serve as an explanation of a raster operation performed by
+a module or function.
+
+<p>
+Currently three rasters with preset operators in between them are
+supported. The rasters are expected to have the following relation:
+
+<p><em>
+a + b -> c
+</em></p>
+
+
+<h2>EXAMPLES</h2>
+
+<h3>Complete example using artificial data</h3>
+
+<div class="code"><pre>
+r.in.ascii input=- output=input_1 <<EOF
+north: 103
+south: 100
+east: 103
+west: 100
+rows: 3
+cols: 3
+5 * 9
+* 5 *
+* 5 5
+EOF
+r.in.ascii input=- output=input_2 <<EOF
+north: 103
+south: 100
+east: 103
+west: 100
+rows: 3
+cols: 3
+3 4 4
+2 2 2
+2 1 1
+EOF
+r.colors map=input_1,input_2 color=viridis
+g.region raster=input_1
+r.patch input=input_1,input_2 output=result
+d.mon wx0 width=400 height=400 output=r_patch.png
+d.explanation.plot a=input_1 b=input_2 c=result
+</pre></div>
+
+<center>
+<img src="d_explanation_plot.png">
+<p><em>Figure: Resulting image</em></p>
+</center>
+
+<h2>KNOWN ISSUES</h2>
+
+<ul>
+    <li>
+        Issue <a href="https://trac.osgeo.org/grass/ticket/3381">#3381</a>
+        prevents d.rast.num to be used with <tt>d.mon cairo</tt>,
+        so <tt>d.mon wx0</tt> needs to be used with this module.
+    </li>
+    <li>
+        Issue <a href="https://trac.osgeo.org/grass/ticket/3382">#3382</a>
+        prevents usage of centered text with <tt>d.mon wx0</tt>, so the
+        hardcoded values for text does not work perfectly.
+    </li>
+    <li>
+        Issue <a href="https://trac.osgeo.org/grass/ticket/3383">#3383</a>
+        prevents d.rast.num to be saved to the image with
+        <tt>d.mon wx0</tt>, taking screenshot is necessary
+        (with powerful screenshot tool such as Shutter, this also
+        addresses the copping issue below).
+    </li>
+    <li>
+        The size of the display must be square to have rasters and their
+        cells as squares, i.e. <tt>d.mon wx0 width=400 height=400</tt>
+        must be used. The image needs to be cropped afterwards,
+        e.g. using ImageMagic's <tt>mogrify -trim image.png</tt>.
+    </li>
+</ul>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="g.region.html">g.region</a>,
+  <a href="d.frame.html">d.frame</a>,
+  <a href="d.rast.num.html">d.rast.num</a>,
+  <a href="d.grid.html">d.grid</a>,
+  <a href="d.mon.html">d.mon</a>,
+  <a href="v.mkgrid.html">v.mkgrid</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Vaclav Petras, <a href="http://gis.ncsu.edu/osgeorel/">NCSU GeoForAll Lab</a>
+
+<p><i>Last changed: $Date: 2013-11-22 00:37:02 -0500 (Fri, 22 Nov 2013) $</i>

Added: grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.py
===================================================================
--- grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.py	                        (rev 0)
+++ grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.py	2017-07-30 21:04:34 UTC (rev 71320)
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       d.explanation.plot
+# AUTHOR(S):    Vaclav Petras <wenzeslaus gmail com>
+#
+# PURPOSE:      Draw plot for manual explaining a raster operation
+# COPYRIGHT:    (C) 2017 by Vaclav Petras 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: Draw a plot of multiple rasters to explain a raster operation for example a + b = c
+#% keyword: display
+#% keyword: manual
+#% keyword: raster
+#%end
+#%option G_OPT_R_INPUT
+#% key: a
+#%end
+#%option G_OPT_R_INPUT
+#% key: b
+#%end
+#%option G_OPT_R_INPUT
+#% key: c
+#%end
+#%option
+#% key: label_a
+#% type: string
+#% required: no
+#% description: Label above the raster
+#%end
+#%option
+#% key: label_b
+#% type: string
+#% required: no
+#% description: Label above the raster
+#%end
+#%option
+#% key: label_c
+#% type: string
+#% required: no
+#% description: Label above the raster
+#%end
+
+
+import sys
+import os
+import grass.script as gs
+
+# i18N
+import gettext
+gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'))
+
+
+def main():
+    options, flags = gs.parser()
+
+    raster_1 = options['a']
+    raster_2 = options['b']
+    raster_3 = options['c']
+
+    # TODO: add also labels below the images
+    label_1 = options['label_a']
+    label_2 = options['label_b']
+    label_3 = options['label_c']
+
+    # TODO: make fonts customizable
+    label_font = 'FreeSans:Regular'
+    rast_num_font = 'FreeMono:Regular'
+    operator_font = 'FreeMono:Regular'
+
+    # TODO: make sizes customizable
+    label_font_size = 6
+    operator_font_size = 10
+
+    # although we set things explicitly for customization,
+    # set font also globally (for the process) for things we don't set
+    os.environ['GRASS_FONT'] = label_font
+
+    # TODO: move the positions to variables, esp. the centered things
+    # and the initial vertical position
+
+    # TODO: add operators/text before and after the raster images
+    # TODO: make the operators customizable
+    gs.run_command('d.text', text='+', color='black',
+                   at=(33, 40), align='cc',
+                   font=operator_font, size=operator_font_size)
+    gs.run_command('d.text', text='->', color='black',
+                   at=(66, 40), align='cc',
+                   font=operator_font, size=operator_font_size)
+
+    if label_1:
+        gs.run_command('d.text', text=label_1, color='black',
+                       at=(10, 60), align='cc',
+                       font=label_font, size=label_font_size)
+    if label_2:
+        gs.run_command('d.text', text=label_2, color='black',
+                       at=(45, 60), align='cc',
+                       font=label_font, size=label_font_size)
+    if label_3:
+        gs.run_command('d.text', text=label_3, color='black',
+                       at=(80, 60), align='cc',
+                       font=label_font, size=label_font_size)
+
+    # TODO: create frames internally using the env variable so that the
+    # subsequent commands are not influenced
+
+    gs.run_command('d.frame', frame='f1', at=(25, 50, 5, 30), flags='c')
+    gs.run_command('d.rast', map=raster_1)
+    gs.run_command('d.rast.num', map=raster_1, font=rast_num_font)
+    gs.run_command('d.frame', frame='f2', at=(25, 50, 40, 65), flags='c')
+    gs.run_command('d.rast', map=raster_2)
+    gs.run_command('d.rast.num', map=raster_2, font=rast_num_font)
+    # TODO: third one should be optional for: a -> b
+    gs.run_command('d.frame', frame='f3', at=(25, 50, 75, 100), flags='c')
+    gs.run_command('d.rast', map=raster_3)
+    gs.run_command('d.rast.num', map=raster_3, font=rast_num_font)
+    # TODO: add fourth one for: a + b + c -> d
+    # (more seems to be too much for this method and style)
+
+
+if __name__ == "__main__":
+    sys.exit(main())


Property changes on: grass-addons/grass7/display/d.explanation.plot/d.explanation.plot.py
___________________________________________________________________
Added: svn:executable
   + *

Added: grass-addons/grass7/display/d.explanation.plot/d_explanation_plot.png
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/display/d.explanation.plot/d_explanation_plot.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream



More information about the grass-commit mailing list