[GRASS-SVN] r59013 - in grass/trunk/temporal: . t.rast.mapcalc2 t.rast3d.mapcalc2

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 12 13:25:39 PST 2014


Author: huhabla
Date: 2014-02-12 13:25:39 -0800 (Wed, 12 Feb 2014)
New Revision: 59013

Added:
   grass/trunk/temporal/t.rast.mapcalc2/
   grass/trunk/temporal/t.rast.mapcalc2/Makefile
   grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.html
   grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.py
   grass/trunk/temporal/t.rast.mapcalc2/test.t.rast.mapcalc2.sh
   grass/trunk/temporal/t.rast3d.mapcalc2/
   grass/trunk/temporal/t.rast3d.mapcalc2/Makefile
   grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.html
   grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.py
   grass/trunk/temporal/t.rast3d.mapcalc2/test.t.rast3d.mapcalc2.sh
Modified:
   grass/trunk/temporal/Makefile
Log:
New temporal raster algebra modules added.


Modified: grass/trunk/temporal/Makefile
===================================================================
--- grass/trunk/temporal/Makefile	2014-02-12 21:19:59 UTC (rev 59012)
+++ grass/trunk/temporal/Makefile	2014-02-12 21:25:39 UTC (rev 59013)
@@ -21,6 +21,7 @@
 	t.rast.univar \
 	t.rast.list \
 	t.rast.mapcalc \
+	t.rast.mapcalc2 \
 	t.rast.neighbors \
 	t.rast.series \
 	t.rast.export \
@@ -31,6 +32,7 @@
 	t.rast3d.list \
 	t.rast3d.extract \
 	t.rast3d.mapcalc \
+	t.rast3d.mapcalc2 \
 	t.rast3d.univar \
 	t.rename \
 	t.select \

Added: grass/trunk/temporal/t.rast.mapcalc2/Makefile
===================================================================
--- grass/trunk/temporal/t.rast.mapcalc2/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.rast.mapcalc2/Makefile	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.rast.mapcalc2
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.html
===================================================================
--- grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.html	                        (rev 0)
+++ grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.html	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,344 @@
+<h2>DESCRIPTION</h2>
+
+t.rast.mapcalc2 performs temporal and spatial map algebra operations on space time raster datasets (STRDS)
+by using the temporal raster algebra.
+
+<h3>PROGRAM USE</h3>
+The module expects an <b>expression</b> as input parameter in the following form: <br>
+<br>
+<b> "result = expression" </b>
+<br>
+<br>
+
+The statement structure is similar to r.mapcalc, see <a href="r.mapcalc.html">r.mapcalc</a>.
+Where <b>result</b> represents the name of a space time raster dataset (STRDS)that will
+contain the result of the calculation that is given as <b>expression</b>
+on the right side of the equality sign.
+These expression can be any valid or nested combination of temporal
+operations and spatial overlay or buffer functions that are provided by the temporal algebra.  <br>
+The temporal raster algebra works with space time raster datasets only (STRDS).
+The algebra provides methods for map selection from STRDS based on their temporal relations.
+It is also possible to temporally shift maps, to create temporal buffer and to snap time
+instances to create a valid temporal topology. Furthermore expressions can be nested and
+evaluated in conditional statements (if, else statements). Within if-statements the algebra
+provides temporal variables like start time, end time, day of year, time differences or
+number of maps per time interval to build up conditions.
+<br>
+In addition the algebra provides
+a subset of the spatial operations from <a href="r.mapcalc.html">r.mapcalc</a>.
+All these operations can be assigned to STRDS or to the resulting map lists of operations between STRDS.
+<br>
+<br>
+As default, topological relationships between space time datasets will be
+evaluated only temporal. Use the <b>s</b> flag to activate the
+additionally evaluate the spatial topology based on the spatial extents of maps.
+<br>
+<br>
+The expression option must be passed as <b>quoted</b>
+expression, for example: <br>
+<div class="code"><pre>t.rast.mapcalc2 expression="C = A + B" basename=result</pre></div>
+Where <b>C</b> is the new space time raster dataset that will contain maps
+with the basename "result" that represent the sum of maps from STRDS <b>A</b> and
+equally temporal related maps from STRDS <b>B</b>.
+<br>
+<br>
+The map basename for the result STRDS must always be specified.
+
+<h2>Temporal raster algebra</h2>
+
+The temporal raster algebra provides a wide range of temporal and spatial operators and
+functions that will be presented in the following section. <br>
+<br>
+
+<h3>Temporal relations</h3>
+
+Several temporal topology relations between space
+time datasets are supported: <br>
+<div class="code"><pre>
+equals            A ------
+                  B ------
+
+during            A  ----
+                  B ------
+
+contains          A ------
+                  B  ----
+
+starts            A ----
+                  B ------
+
+started           A ------
+                  B ----
+
+finishs           A   ----
+                  B ------
+
+finished          A ------
+                  B   ----
+
+precedes          A ----
+                  B     ----
+
+follows           A     ----
+                  B ----
+
+overlapped        A   ------
+                  B ------
+
+overlaps          A ------
+                  B   ------
+
+over              booth overlaps and overlapped
+
+</pre></div>
+The relations must be read as: A is related to B, like - A equals B - A is
+during B - A contains B <br>
+<br>
+Topological relations must be specified in {} parentheses. <br>
+
+<h3>Temporal Selection</h3>
+
+The temporal selection simply selects parts of a space time dataset without
+processing raster or vector data.
+
+The algebra provides a selection operator <b>:</b> that selects parts
+of a space time dataset that are temporally equal to parts of a second one
+by default. The following expression
+<div class="code"><pre>
+C = A : B
+</pre></div>
+means: Select all parts of space time dataset A that are equal to B and store
+it in space time dataset C. The parts are time stamped maps. <br>
+<br>
+In addition the inverse selection operator <b>!:</b> is defined as the complement of
+the selection operator, hence the following expression
+<div class="code"><pre>
+C = A !: B
+</pre></div>
+means: select all parts of space time time dataset A that are not equal to B
+and store it in space time dataset (STDS) C. <br>
+<br>
+To select parts of a STDS by different topological relations to other STDS,
+the temporal topology selection operator can be used. The operator consists of
+topological relations, that must be separated by the logical OR operator
+<b>|</b> and the temporal selection operator. Both parts are separated by
+comma and surrounded by curly braces:
+{"topological relations", "temporal selection operator"}  <br>
+<br>
+Examples:
+<div class="code"><pre>
+C = A {equals,:} B
+C = A {equals,!:} B
+</pre></div>
+We can now define arbitrary topological relations using logical OR operator
+to connect them:
+<div class="code"><pre>
+C = A {equals|during|overlaps,:} B
+</pre></div>
+Select all parts of A that are equal to B, during B or overlaps B. <br>
+<br>
+The selection operator is implicitly contained in the temporal topology
+selection operator, so that the following statements are exactly the same:
+<div class="code"><pre>
+C = A : B
+C = A {:} B
+C = A {equal,:} B
+</pre></div>
+
+Same for the complementary selection:
+<div class="code"><pre>
+C = A !: B
+C = A {!:} B
+C = A {equal,!:} B
+</pre></div>
+
+<h3>Conditional statements</h3>
+
+Selection operations can be evaluated within conditional statements.
+<br>
+<div class="code"><pre>
+Note A and B can either be space time datasets or expressions.
+
+if statement                         decision option                        temporal relations
+  if(if, then, else)
+  if(conditions, A)                    A if conditions are True;              temporal topological relation between if and then is equal.
+  if(conditions, A, B)                 A if conditions are True, B otherwise; temporal topological relation between if, then and else is equal.
+  if(topologies, conditions, A)        A if conditions are True;              temporal topological relation between if and then is explicit specified by topologies.
+  if(topologies, conditions, A, B)     A if conditions are True, B otherwise; temporal topological relation between if, then and else is explicit specified by topologies.
+</pre></div>
+The conditions are comparison expressions that are used to evaluate
+space time datasets. Specific values of temporal variables are
+compared by logical operators and evaluated for each map of the STDS.
+<br>
+<br>
+The supported logical operators:
+<div class="code"><pre>
+Symbol  description
+
+  ==    equal
+  !=    not equal
+  >     greater than
+  >=    greater than or equal
+  <     less than
+  <=    less than or equal
+  &&    and
+  ||    or
+</pre></div>
+
+Temporal functions: <br>
+<div class="code"><pre>
+
+td(A)                   Returns a list of time intervals of STDS A
+
+start_time()            Start time as HH::MM:SS
+start_date()            Start date as yyyy-mm-DD
+start_datetime()        Start datetime as yyyy-mm-DD HH:MM:SS
+end_time()              End time as HH:MM:SS
+end_date()              End date as yyyy-mm-DD
+end_datetime()          End datetime as  yyyy-mm-DD HH:MM
+
+start_doy()             Day of year (doy) from the start time [1 - 366]
+start_dow()             Day of week (dow) from the start time [1 - 7], the start of the week is Monday == 1
+start_year()            The year of the start time [0 - 9999]
+start_month()           The month of the start time [1 - 12]
+start_week()            Week of year of the start time [1 - 54]
+start_day()             Day of month from the start time [1 - 31]
+start_hour()            The hour of the start time [0 - 23]
+start_minute()          The minute of the start time [0 - 59]
+start_second()          The second of the start time [0 - 59]
+end_doy()               Day of year (doy) from the end time [1 - 366]
+end_dow()               Day of week (dow) from the end time [1 - 7], the start of the week is Monday == 1
+end_year()              The year of the end time [0 - 9999]
+end_month()             The month of the end time [1 - 12]
+end_week()              Week of year of the end time [1 - 54]
+end_day()               Day of month from the start time [1 - 31]
+end_hour()              The hour of the end time [0 - 23]
+end_minute()            The minute of the end time [0 - 59]
+end_second()            The second of the end time [0 - 59]
+</pre></div>
+
+Additionally the number of maps in intervals can be computed and
+used in conditional statements. <br>
+The operator to count the number of maps
+is the hash <b>#</b>.
+<div class="code"><pre>
+A{contains,#}B
+</pre></div>
+This expression computes the number of maps from space
+time dataset B which are during the time intervals of maps from
+space time dataset A.<br>
+A list of integers (scalars) corresponding to the maps of A
+that contain maps from B will be returned. <br>
+<br>
+
+Furthermore the temporal algebra allows temporal buffering, shifting
+and snapping with the functions buff_t(), tshift() and tsnap()
+respectively.
+<div class="code"><pre>
+buff_t(A, size)         Buffer STDS A with granule ("1 month" or 5)
+tshift(A, size)         Shift STDS A with granule ("1 month" or 5)
+tsnap(A)                Snap time instances and intervals of STDS A
+</pre></div>
+
+<h3>Temporal Operators</h3>
+<p>
+The temporal algebra defines temporal operators that can be combined
+later with spatial operators to perform spatio-temporal operations.
+The temporal operators process the time instances and intervals of temporal related maps.
+</p>
+<div class="code"><pre>
+AND             &       Intersection
+OR              |       Union
+DISJOINT OR     +       Disjoint union
+LEFT REFERENCE  =       Use the time stamp of the left space time dataset
+</pre></div><p>
+For example we can compute the intersection, union or disjoint union from time stamps of maps
+that temporally overlap, or we can just keep the time stamp of the left STDS.
+</p>
+
+<h3>Spatial raster operators</h3>
+
+The module supports the following raster operations: <br>
+<div class="code"><pre>
+Symbol  description     precedence
+
+  %     modulus         1
+  /     division        1
+  *     multiplication  1
+  +     addition        2
+  -     subtraction     2
+</pre></div>
+
+And raster functions:
+<div class="code"><pre>
+abs(x)                  return absolute value of x
+foat(x)                 convert x to foating point
+if decision options:
+  if(x)                 1 if x not zero, 0 otherwise
+  if(x,a)               a if x not zero, 0 otherwise
+  if(x,a,b)             a if x not zero, b otherwise
+int(x)                  convert x to integer [ truncates ]
+log(x)                  natural log of x
+sqrt(x)                 square root of x
+tan(x)                  tangent of x (x is in degrees)
+round(x)		round x to nearest integer
+sin(x)			sine of x (x is in degrees)
+sqrt(x)			square root of x
+tan(x)			tangent of x (x is in degrees)
+isnull(x)              check if x = NULL
+</pre></div>
+<br>
+
+<p>
+<h3>Combinations of temporal, raster and select operators</h3>
+
+We combine the temporal topology relations, the temporal operators and the spatial/select operators to create spatio-temporal operators:
+
+<div class="code"><pre>
+{"list of temporal relations", "temporal operator" "spatial or select operator"}
+</pre></div>
+<p>
+The spatial and the select operators can be used stand-alone.
+In this case the temporal topology relation "equal" and the temporal operator
+"left reference =" is assumed and used as default. This allows the convenient use of the spatial and select
+operators in case of space time raster datasets with equal time stamps.
+</p>
+<div class="code"> <pre>
+ ----------------------------
+|   |  % |  / |  * |  - |  + |
+|---|----|----|----|----|----|
+| & | &% | &/ | &* | &- | &+ |
+| | | |% | |/ | |* | |- | |+ |
+| + | +% | +/ | +* | +- | ++ |
+| = | =% | =/ | =* | =- | =+ |
+ ----------------------------
+</pre></div>
+
+<h3>Examples: </h3>
+Sum maps from space time dataset A with maps from space time dataset
+B which have equal time stamps and are temporary before Jan. 1. 2005 and
+store them in space time dataset D.
+<div class="code"><pre>
+D = if(start_date() < "2005-01-01", A + B)
+</pre></div>
+
+<h2>REFERENCES</h2>
+
+<tt><a href="http://www.dabeaz.com/ply/">PLY(Python-Lex-Yacc)</a></tt>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="t.rast.mapcalc.html">t.rast.mapcalc2</a>
+<a href="r.mapcalc.html">r.mapcalc</a>
+<a href="t.vect.mapcalc.html">t.vect.mapcalc</a>
+<a href="t.select.html">t.select</a>
+<a href="t.rast3d.mapcalc.html">t.rast3d.mapcalc</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Thomas Leppelt, Soeren Gebbert, Thuenen Institut, Germany <br>
+
+<p><i>Last changed: $Date: 2013-07-24 17:35:20 +0100 (Thu, 24 Jul 2013) $</i>
+

Added: grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.py
===================================================================
--- grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast.mapcalc2/t.rast.mapcalc2.py	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       t.rast.mapcal2c
+# AUTHOR(S):    Thomas Leppelt, Soeren Gebbert
+#
+# PURPOSE:      Provide temporal raster algebra to perform spatial an temporal operations
+#               for space time datasets by topological relationships to other space time
+#               datasets.
+# COPYRIGHT:    (C) 2014 by the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (version 2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%module
+#% description: Apply temporal and spatial oeprations on space time raster datasets using temporal raster algebra.
+#% keywords: temporal
+#% keywords: mapalgebra
+#%end
+
+#%option
+#% key: expression
+#% type: string
+#% description: The mapcalc expression for temporal and spatial analysis of space time raster datasets.
+#% key_desc: expression
+#% required : yes
+#%end
+
+#%option
+#% key: basename
+#% type: string
+#% description: The basename of raster maps that are stored within the result space time raster dataset.
+#% key_desc: basename
+#% required : yes
+#%end
+
+#%option
+#% key: nprocs
+#% type: integer
+#% description: Number of r.mapcalc processes to run in parallel
+#% required: no
+#% multiple: no
+#% answer: 1
+#%end
+
+#%flag
+#% key: s
+#% description: Activate spatial topology.
+#%end
+
+import grass.script
+import grass.temporal as tgis
+import sys
+
+def main():
+    expression = options['expression']
+    basename = options['basename']
+    nprocs = options["nprocs"]
+    spatial = flags["s"]
+
+    # Check for PLY istallation
+    try:
+        import ply.lex as lex
+        import ply.yacc as yacc
+    except:
+        grass.script.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules. "
+                             "You can use t.rast.mapcalc that provides a limited but useful alternative to "
+                             "t.rast.mapcalc2 without PLY requirement."))
+
+    tgis.init(True)
+    p = tgis.TemporalRasterAlgebraParser(run = True, debug=False, spatial = spatial, nprocs = nprocs)
+    p.parse(expression, basename, grass.script.overwrite())
+
+if __name__ == "__main__":
+    options, flags = grass.script.parser()
+    sys.exit(main())
+

Added: grass/trunk/temporal/t.rast.mapcalc2/test.t.rast.mapcalc2.sh
===================================================================
--- grass/trunk/temporal/t.rast.mapcalc2/test.t.rast.mapcalc2.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.mapcalc2/test.t.rast.mapcalc2.sh	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Test for t.rast.mapcalc2
+
+export GRASS_OVERWRITE=1
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r.mapcalc and create several space time raster datasets
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc expr="a1 = rand(0, 550)"
+r.mapcalc expr="a2 = rand(0, 450)"
+r.mapcalc expr="a3 = rand(0, 320)"
+r.mapcalc expr="a4 = rand(0, 510)"
+r.mapcalc expr="a5 = rand(0, 300)"
+r.mapcalc expr="a6 = rand(0, 650)"
+
+t.create type=strds temporaltype=absolute output=A1 title="A test" descr="A test"
+t.create type=strds temporaltype=absolute output=A2 title="A test" descr="A test"
+t.register -i type=rast input=A1 maps=a1,a2,a3,a4,a5,a6 start="2001-01-01" increment="3 months"
+t.register type=rast input=A2 maps=a1,a2,a3,a4,a5,a6
+
+t.info A1
+t.info A2
+
+# The first @test
+t.rast.mapcalc2 --v expression="B = A1 + A2" base=b nprocs=5
+t.info type=strds input=B
+
+t.rast.mapcalc2 --v expression="B = if(start_year()>=0&&start_month()>=0&&start_day()>=0&&start_hour()>=0&&start_minute()>=0&&start_second()>=0, A1 + A2) " base=b nprocs=5
+t.info type=strds input=B
+
+t.rast.mapcalc2 --v expression="B = if(end_year()>=0&&end_month()>=0&&end_day()>=0&&end_hour()>=0&&end_minute()>=0&&end_second()>=0, A1 + A2) " base=b nprocs=5
+t.info type=strds input=B
+
+t.rast.mapcalc2 --v expression="B = if(start_doy() >= 0 && start_dow() >= 0, A1 + A2) " base=b nprocs=5
+t.info type=strds input=B
+
+t.rast.mapcalc2 --v expression="B = if(end_doy() >= 0 && end_dow() >= 0, A1 + A2) " base=b nprocs=5
+t.info type=strds input=B
+
+t.rast.mapcalc2 --v expression="B = A1[-1] + A2[1] " base=b nprocs=5
+t.info type=strds input=B
+
+# @postprocess
+t.remove -rf type=strds input=A1,A2,B


Property changes on: grass/trunk/temporal/t.rast.mapcalc2/test.t.rast.mapcalc2.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: grass/trunk/temporal/t.rast3d.mapcalc2/Makefile
===================================================================
--- grass/trunk/temporal/t.rast3d.mapcalc2/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.rast3d.mapcalc2/Makefile	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.rast3d.mapcalc2
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.html
===================================================================
--- grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.html	                        (rev 0)
+++ grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.html	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,35 @@
+<h2>DESCRIPTION</h2>
+
+t.rast3d.mapcalc2 performs temporal and spatial map algebra operations on space time 3D raster datasets (STR3DS)
+by using the temporal raster algebra.
+
+<h3>PROGRAM USE</h3>
+The module expects an <b>expression</b> as input parameter in the following form: <br>
+<br>
+<b> "result = expression" </b>
+<br>
+<br>
+
+The statement structure is exact the same as of t.rast.mapcalc2, please study <a href="t.rast.mapcalc2.html">t.rast.mapcalc2</a>.
+
+<h2>REFERENCES</h2>
+
+<tt><a href="http://www.dabeaz.com/ply/">PLY(Python-Lex-Yacc)</a></tt>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="t.rast.mapcalc2.html">t.rast.mapcalc2</a>
+<a href="t.rast3d.mapcalc.html">t.rast3d.mapcalc</a>
+<a href="r.mapcalc.html">r.mapcalc</a>
+<a href="t.vect.mapcalc.html">t.vect.mapcalc</a>
+<a href="t.select.html">t.select</a>
+</em>
+
+
+<h2>AUTHOR</h2>
+
+Thomas Leppelt, Soeren Gebbert, Thuenen Institut, Germany <br>
+
+<p><i>Last changed: $Date: 2013-07-24 17:35:20 +0100 (Thu, 24 Jul 2013) $</i>
+

Added: grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.py
===================================================================
--- grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast3d.mapcalc2/t.rast3d.mapcalc2.py	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       t.rast3d.mapcalc2
+# AUTHOR(S):    Thomas Leppelt, Soeren Gebbert
+#
+# PURPOSE:      Provide temporal 3D raster algebra to perform spatial an temporal operations
+#               for space time datasets by topological relationships to other space time
+#               datasets.
+# COPYRIGHT:    (C) 2014 by the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (version 2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%module
+#% description: Apply temporal and spatial oeprations on space time 3D raster datasets using temporal raster algebra.
+#% keywords: temporal
+#% keywords: mapalgebra
+#%end
+
+#%option
+#% key: expression
+#% type: string
+#% description: The mapcalc expression for temporal and spatial analysis of space time 3D raster datasets.
+#% key_desc: expression
+#% required : yes
+#%end
+
+#%option
+#% key: basename
+#% type: string
+#% description: The basename of raster maps that are stored within the result space time 3D raster dataset.
+#% key_desc: basename
+#% required : yes
+#%end
+
+#%option
+#% key: nprocs
+#% type: integer
+#% description: Number of r3.mapcalc processes to run in parallel
+#% required: no
+#% multiple: no
+#% answer: 1
+#%end
+
+#%flag
+#% key: s
+#% description: Activate spatial topology.
+#%end
+
+import grass.script
+import grass.temporal as tgis
+import sys
+
+def main():
+    expression = options['expression']
+    basename = options['basename']
+    nprocs = options["nprocs"]
+    spatial = flags["s"]
+
+    # Check for PLY istallation
+    try:
+        import ply.lex as lex
+        import ply.yacc as yacc
+    except:
+        grass.script.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules. "
+                             "You can use t.rast3d.mapcalc that provides a limited but useful alternative to "
+                             "t.rast3d.mapcalc2 without PLY requirement."))
+
+    tgis.init(True)
+    p = tgis.TemporalRaster3DAlgebraParser(run = True, debug=False, spatial = spatial, nprocs = nprocs)
+    p.parse(expression, basename, grass.script.overwrite())
+
+if __name__ == "__main__":
+    options, flags = grass.script.parser()
+    sys.exit(main())
+

Added: grass/trunk/temporal/t.rast3d.mapcalc2/test.t.rast3d.mapcalc2.sh
===================================================================
--- grass/trunk/temporal/t.rast3d.mapcalc2/test.t.rast3d.mapcalc2.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast3d.mapcalc2/test.t.rast3d.mapcalc2.sh	2014-02-12 21:25:39 UTC (rev 59013)
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Test for t.rast3d.mapcalc2
+
+export GRASS_OVERWRITE=1
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r3.mapcalc and create several space time raster datasets
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r3.mapcalc expr="a1 = rand(0, 550)"
+r3.mapcalc expr="a2 = rand(0, 450)"
+r3.mapcalc expr="a3 = rand(0, 320)"
+r3.mapcalc expr="a4 = rand(0, 510)"
+r3.mapcalc expr="a5 = rand(0, 300)"
+r3.mapcalc expr="a6 = rand(0, 650)"
+
+t.create type=str3ds temporaltype=absolute output=A1 title="A test" descr="A test"
+t.create type=str3ds temporaltype=absolute output=A2 title="A test" descr="A test"
+t.register -i type=rast3d input=A1 maps=a1,a2,a3,a4,a5,a6 start="2001-01-01" increment="3 months"
+t.register type=rast3d input=A2 maps=a1,a2,a3,a4,a5,a6
+
+t.info type=str3ds input=A1
+t.info type=str3ds input=A2
+
+# The first @test
+t.rast3d.mapcalc2 --v expression="B = A1 + A2" base=b nprocs=5
+t.info type=str3ds input=B
+
+t.rast3d.mapcalc2 --v expression="B = if(start_year()>=0&&start_month()>=0&&start_day()>=0&&start_hour()>=0&&start_minute()>=0&&start_second()>=0, A1 + A2) " base=b nprocs=5
+t.info type=str3ds input=B
+
+t.rast3d.mapcalc2 --v expression="B = if(end_year()>=0&&end_month()>=0&&end_day()>=0&&end_hour()>=0&&end_minute()>=0&&end_second()>=0, A1 + A2) " base=b nprocs=5
+t.info type=str3ds input=B
+
+t.rast3d.mapcalc2 --v expression="B = if(start_doy() >= 0 && start_dow() >= 0, A1 + A2) " base=b nprocs=5
+t.info type=str3ds input=B
+
+t.rast3d.mapcalc2 --v expression="B = if(end_doy() >= 0 && end_dow() >= 0, A1 + A2) " base=b nprocs=5
+t.info type=str3ds input=B
+
+t.rast3d.mapcalc2 --v expression="B = A1[-1] + A2[1] " base=b nprocs=5
+t.info type=str3ds input=B
+
+# @postprocess
+t.remove -rf type=str3ds input=A1,A2,B


Property changes on: grass/trunk/temporal/t.rast3d.mapcalc2/test.t.rast3d.mapcalc2.sh
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list