[GRASS-SVN] r66573 - in grass/trunk/temporal/t.rast3d.univar: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 22 03:14:38 PDT 2015


Author: huhabla
Date: 2015-10-22 03:14:37 -0700 (Thu, 22 Oct 2015)
New Revision: 66573

Added:
   grass/trunk/temporal/t.rast3d.univar/testsuite/test_univar.py
Removed:
   grass/trunk/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh
Modified:
   grass/trunk/temporal/t.rast3d.univar/t.rast3d.univar.py
Log:
temporal modules: Added output option to t.rast3d.univar and new python tests


Modified: grass/trunk/temporal/t.rast3d.univar/t.rast3d.univar.py
===================================================================
--- grass/trunk/temporal/t.rast3d.univar/t.rast3d.univar.py	2015-10-22 09:48:51 UTC (rev 66572)
+++ grass/trunk/temporal/t.rast3d.univar/t.rast3d.univar.py	2015-10-22 10:14:37 UTC (rev 66573)
@@ -27,6 +27,10 @@
 #%option G_OPT_STR3DS_INPUT
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%option G_OPT_T_WHERE
 #% guisection: Selection
 #%end
@@ -57,6 +61,7 @@
 
     # Get the options
     input = options["input"]
+    output = options["output"]
     where = options["where"]
     extended = flags["e"]
     no_header = flags["s"]
@@ -65,8 +70,13 @@
     # Make sure the temporal database exists
     tgis.init()
 
+    if not output:
+        output = None
+    if output == "-":
+        output = None
+
     tgis.print_gridded_dataset_univar_statistics(
-        "str3ds", input, where, extended, no_header, separator)
+        "str3ds", input, output, where, extended, no_header, separator)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Deleted: grass/trunk/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh
===================================================================
--- grass/trunk/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh	2015-10-22 09:48:51 UTC (rev 66572)
+++ grass/trunk/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh	2015-10-22 10:14:37 UTC (rev 66573)
@@ -1,29 +0,0 @@
-#!/bin/sh
-# Univariate statitsics for space time raster3d datasets
-
-# We need to set a specific region in the
-# @preprocess step of this test. 
-# 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
-
-export GRASS_OVERWRITE=1
-
-# Generate data
-r3.mapcalc expr="prec_1 = rand(0, 550)" -s
-r3.mapcalc expr="prec_2 = rand(0, 450)" -s
-r3.mapcalc expr="prec_3 = rand(0, 320)" -s
-r3.mapcalc expr="prec_4 = rand(0, 510)" -s
-r3.mapcalc expr="prec_5 = rand(0, 300)" -s
-r3.mapcalc expr="prec_6 = rand(0, 650)" -s
-
-t.create type=str3ds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register type=raster_3d --v -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-15 12:05:45" increment="14 days"
-t.info type=str3ds input=precip_abs1
-
-# The first @test
-t.rast3d.univar -e input=precip_abs1 
-
-t.rast3d.univar -s input=precip_abs1 
-
-t.remove -rf type=str3ds input=precip_abs1
-

Added: grass/trunk/temporal/t.rast3d.univar/testsuite/test_univar.py
===================================================================
--- grass/trunk/temporal/t.rast3d.univar/testsuite/test_univar.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast3d.univar/testsuite/test_univar.py	2015-10-22 10:14:37 UTC (rev 66573)
@@ -0,0 +1,116 @@
+"""Test t.rast.univar
+
+(C) 2014 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.
+
+ at author Soeren Gebbert
+"""
+
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestRasterUnivar(TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        """Initiate the temporal GIS and set the region
+        """
+        cls.use_temp_region()
+        cls.runModule("g.region",  s=0,  n=80,  w=0,  e=120,  b=0,  t=50,  res=1,  res3=1)
+
+        cls.runModule("r3.mapcalc", expression="a_1 = 100",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a_2 = 200",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a_3 = 300",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a_4 = 400",  overwrite=True)
+
+        cls.runModule("t.create",  type="str3ds",  temporaltype="absolute",
+                                   output="A",  title="A test",  description="A test",
+                                   overwrite=True)
+        cls.runModule("t.register",  flags="i",  type="raster_3d",  input="A",
+                                     maps="a_1,a_2,a_3,a_4",  start="2001-01-01", 
+                                     increment="3 months",  overwrite=True)
+
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.runModule("t.remove",  flags="rf",  type="str3ds",
+                                   inputs="A")
+        cls.del_temp_region()
+
+    def test_1(self):
+        
+        t_rast3d_univar = SimpleModule("t.rast3d.univar", input="A",
+                                                          where="start_time >= '2001-01-01'",
+                                                          overwrite=True, verbose=True)
+        self.assertModule(t_rast3d_univar)
+
+        univar_text="""id|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells
+a_1 at testing|2001-01-01 00:00:00|2001-04-01 00:00:00|100|100|100|100|0|0|0|48000000|0|480000
+a_2 at testing|2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|96000000|0|480000
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|144000000|0|480000
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|192000000|0|480000
+"""
+        self.assertLooksLike(univar_text,  t_rast3d_univar.outputs.stdout)
+
+    def test_2(self):
+
+        t_rast3d_univar = SimpleModule("t.rast3d.univar", input="A",
+                                                          where="start_time >= '2001-03-01'",
+                                                          overwrite=True, verbose=True)
+        self.assertModule(t_rast3d_univar)
+
+        univar_text="""id|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells
+a_2 at testing|2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|96000000|0|480000
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|144000000|0|480000
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|192000000|0|480000
+"""
+        self.assertLooksLike(univar_text,  t_rast3d_univar.outputs.stdout)
+
+    def test_3(self):
+
+        self.assertModule("t.rast3d.univar", input="A",
+                                             output="univar_output.txt",
+                                             where="start_time >= '2001-03-01'",
+                                             overwrite=True, verbose=True)
+
+        univar_text="""id|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells
+a_2 at testing|2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|96000000|0|480000
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|144000000|0|480000
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|192000000|0|480000
+"""
+        univar_output = open("univar_output.txt", "r").read()
+
+        self.assertLooksLike(univar_text, univar_output)
+
+    def test_4(self):
+
+        self.assertModule("t.rast3d.univar", input="A",
+                                             output="univar_output.txt", flags="s",
+                                             where="start_time >= '2001-03-01'",
+                                             overwrite=True, verbose=True)
+
+        univar_text="""a_2 at testing|2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|96000000|0|480000
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|144000000|0|480000
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|192000000|0|480000
+"""
+        univar_output = open("univar_output.txt", "r").read()
+
+        self.assertLooksLike(univar_text, univar_output)
+
+    def test_5_error_handling_empty_strds(self):
+        # Empty str3ds
+        self.assertModuleFail("t.rast3d.univar", input="A",
+                                                 output="univar_output.txt",
+                                                 where="start_time >= '2015-03-01'",
+                                                 overwrite=True, verbose=True)
+
+    def test_6_error_handling_no_input(self):
+        # No input
+        self.assertModuleFail("t.rast3d.univar",  output="out.txt")
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()



More information about the grass-commit mailing list