[GRASS-SVN] r66886 - in grass/branches/releasebranch_7_0: lib/python/temporal temporal/t.rast.univar temporal/t.rast.univar/testsuite temporal/t.rast3d.univar temporal/t.rast3d.univar/testsuite temporal/t.vect.univar

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 21 10:37:52 PST 2015


Author: martinl
Date: 2015-11-21 10:37:52 -0800 (Sat, 21 Nov 2015)
New Revision: 66886

Added:
   grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test_univar.py
   grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test_univar.py
Removed:
   grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test.t.rast.univar.sh
   grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh
Modified:
   grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py
   grass/branches/releasebranch_7_0/temporal/t.rast.univar/t.rast.univar.py
   grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/t.rast3d.univar.py
   grass/branches/releasebranch_7_0/temporal/t.vect.univar/t.vect.univar.py
Log:
temporal framework: Added output and region flag to t.rast.univar
temporal modules: Added output option to t.rast3d.univar and new python tests
temporal modules: Added file based output to t.vect.univar
[news]
(merge r66572:r66574 from trunk)


Modified: grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -7,8 +7,9 @@
 
     import grass.temporal as tgis
 
-    tgis.print_gridded_dataset_univar_statistics(type, input, where, extended, no_header, fs)
+    tgis.print_gridded_dataset_univar_statistics(type, input, output, where, extended, no_header, fs, rast_region)
 
+..
 
 (C) 2012-2013 by the GRASS Development Team
 This program is free software under the GNU General Public
@@ -24,16 +25,21 @@
 ###############################################################################
 
 
-def print_gridded_dataset_univar_statistics(type, input, where, extended,
-                                            no_header=False, fs="|"):
+def print_gridded_dataset_univar_statistics(type, input, output, where, extended,
+                                            no_header=False, fs="|",
+                                            rast_region=False):
     """Print univariate statistics for a space time raster or raster3d dataset
 
        :param type: Must be "strds" or "str3ds"
        :param input: The name of the space time dataset
+       :param output: Name of the optional output file, if None stdout is used
        :param where: A temporal database where statement
        :param extended: If True compute extended statistics
        :param no_header: Supress the printing of column names
        :param fs: Field separator
+       :param rast_region: If set True ignore the current region settings
+              and use the raster map regions for univar statistical calculation.
+              Only available for strds.
     """
 
     # We need a database interface
@@ -42,6 +48,9 @@
 
     sp = open_old_stds(input, type, dbif)
 
+    if output is not None:
+        out_file = open(output, "w")
+
     rows = sp.get_registered_maps(
         "id,start_time,end_time", where, "start_time", dbif)
 
@@ -61,7 +70,10 @@
             string += fs + "first_quartile" + fs + "median" + fs
             string += "third_quartile" + fs + "percentile_90"
 
-        print string
+        if output is None:
+            print string
+        else:
+            out_file.write(string + "\n")
 
     for row in rows:
         string = ""
@@ -73,6 +85,8 @@
 
         if extended is True:
             flag += "e"
+        if type == "strds" and rast_region is True:
+            flag += "r"
 
         if type == "strds":
             stats = gscript.parse_command("r.univar", map=id, flags=flag)
@@ -97,10 +111,18 @@
         if extended is True:
             string += fs + str(stats["first_quartile"]) + fs + str(stats["median"])
             string += fs + str(stats["third_quartile"]) + fs + str(stats["percentile_90"])
-        print string
 
+        if output is None:
+            print string
+        else:
+            out_file.write(string + "\n")
+
     dbif.close()
 
+    if output is not None:
+        out_file.close()
+
+
 ###############################################################################
 
 
@@ -110,6 +132,7 @@
     """Print univariate statistics for a space time vector dataset
 
        :param input: The name of the space time dataset
+       :param output: Name of the optional output file, if None stdout is used
        :param twhere: A temporal database where statement
        :param layer: The layer number used in case no layer is present
               in the temporal dataset

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.univar/t.rast.univar.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.univar/t.rast.univar.py	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.univar/t.rast.univar.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -25,6 +25,10 @@
 #%option G_OPT_STRDS_INPUT
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%option G_OPT_T_WHERE
 #% guisection: Selection
 #%end
@@ -40,6 +44,11 @@
 #%end
 
 #%flag
+#% key: r
+#% description: Ignore the current region settings and use the raster map regions for univar statistical calculation
+#%end
+
+#%flag
 #% key: s
 #% description: Suppress printing of column names
 #% guisection: Formatting
@@ -55,16 +64,23 @@
 
     # Get the options
     input = options["input"]
+    output = options["output"]
     where = options["where"]
     extended = flags["e"]
     no_header = flags["s"]
+    rast_region = bool(flags["r"])
     separator = grass.separator(options["separator"])
 
     # Make sure the temporal database exists
     tgis.init()
 
+    if not output:
+        output = None
+    if output == "-":
+        output = None
+
     tgis.print_gridded_dataset_univar_statistics(
-        "strds", input, where, extended, no_header, separator)
+        "strds", input, output, where, extended, no_header, separator, rast_region)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Deleted: grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test.t.rast.univar.sh
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test.t.rast.univar.sh	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test.t.rast.univar.sh	2015-11-21 18:37:52 UTC (rev 66886)
@@ -1,27 +0,0 @@
-#!/bin/sh
-# Test univariate statistics for space time raster 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
-
-# Data generation
-r.mapcalc expr="prec_1 = rand(0, 550)" -s
-r.mapcalc expr="prec_2 = rand(0, 450)" -s
-r.mapcalc expr="prec_3 = rand(0, 320)" -s
-r.mapcalc expr="prec_4 = rand(0, 510)" -s
-r.mapcalc expr="prec_5 = rand(0, 300)" -s
-r.mapcalc expr="prec_6 = rand(0, 650)" -s
-
-t.create type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register type=raster --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"
-
-# The first @test
-t.rast.univar -e input=precip_abs1 
-
-t.rast.univar -s input=precip_abs1 
-
-t.remove  -rf type=strds input=precip_abs1

Copied: grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test_univar.py (from rev 66572, grass/trunk/temporal/t.rast.univar/testsuite/test_univar.py)
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test_univar.py	                        (rev 0)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.univar/testsuite/test_univar.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -0,0 +1,135 @@
+"""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("r.mapcalc", expression="a_1 = 100",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_2 = 200",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_3 = 300",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_4 = 400",  overwrite=True)
+
+        cls.runModule("t.create",  type="strds",  temporaltype="absolute",  
+                                 output="A",  title="A test",  description="A test",  
+                                 overwrite=True)
+        cls.runModule("t.register",  flags="i",  type="raster",  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="strds",  
+                                   inputs="A")
+        cls.del_temp_region()
+
+    def test_1(self):
+        
+        t_rast_univar = SimpleModule("t.rast.univar", input="A",
+                                                      where="start_time >= '2001-01-01'",
+                                                      overwrite=True, verbose=True)
+        self.runModule("g.region", res=1)
+        self.assertModule(t_rast_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|960000|0|9600
+a_2 at testing|2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600
+"""
+        self.assertLooksLike(univar_text,  t_rast_univar.outputs.stdout)
+
+    def test_2(self):
+
+        t_rast_univar = SimpleModule("t.rast.univar", input="A",
+                                                      where="start_time >= '2001-03-01'",
+                                                      overwrite=True, verbose=True)
+        self.runModule("g.region", res=1)
+        self.assertModule(t_rast_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|1920000|0|9600
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600
+"""
+        self.assertLooksLike(univar_text,  t_rast_univar.outputs.stdout)
+
+    def test_3(self):
+
+        t_rast_univar = SimpleModule("t.rast.univar", input="A",
+                                                      where="start_time >= '2001-03-01'",
+                                                      overwrite=True, verbose=True)
+        self.runModule("g.region", res=10)
+        self.assertModule(t_rast_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|19200|0|96
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|28800|0|96
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|38400|0|96
+"""
+        self.assertLooksLike(univar_text,  t_rast_univar.outputs.stdout)
+
+    def test_4(self):
+
+        self.runModule("g.region", res=10)
+        self.assertModule("t.rast.univar", input="A", flags="r",
+                                           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|1920000|0|9600
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600
+"""
+        univar_output = open("univar_output.txt", "r").read()
+
+        self.assertLooksLike(univar_text, univar_output)
+
+    def test_5(self):
+
+        self.runModule("g.region", res=10)
+        self.assertModule("t.rast.univar", input="A", flags="rs",
+                                           output="univar_output.txt",
+                                           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|1920000|0|9600
+a_3 at testing|2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600
+a_4 at testing|2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600
+"""
+        univar_output = open("univar_output.txt", "r").read()
+
+        self.assertLooksLike(univar_text, univar_output)
+
+    def test_6_error_handling_empty_strds(self):
+        # Empty strds
+        self.assertModuleFail("t.rast.univar", input="A",
+                                           output="univar_output.txt",
+                                           where="start_time >= '2015-03-01'",
+                                           overwrite=True, verbose=True)
+
+    def test_7_error_handling_no_input(self):
+        # No input
+        self.assertModuleFail("t.rast.univar",  output="out.txt")
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()

Modified: grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/t.rast3d.univar.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/t.rast3d.univar.py	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/t.rast3d.univar.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -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/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test.t.rast3d.univar.sh	2015-11-21 18:37:52 UTC (rev 66886)
@@ -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
-

Copied: grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test_univar.py (from rev 66573, grass/trunk/temporal/t.rast3d.univar/testsuite/test_univar.py)
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test_univar.py	                        (rev 0)
+++ grass/branches/releasebranch_7_0/temporal/t.rast3d.univar/testsuite/test_univar.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -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()

Modified: grass/branches/releasebranch_7_0/temporal/t.vect.univar/t.vect.univar.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.vect.univar/t.vect.univar.py	2015-11-21 18:30:56 UTC (rev 66885)
+++ grass/branches/releasebranch_7_0/temporal/t.vect.univar/t.vect.univar.py	2015-11-21 18:37:52 UTC (rev 66886)
@@ -25,6 +25,10 @@
 #%option G_OPT_STVDS_INPUT
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%option G_OPT_V_FIELD
 #%end
 
@@ -72,6 +76,7 @@
 
     # Get the options
     input = options["input"]
+    output = options["output"]
     twhere = options["twhere"]
     layer = options["layer"]
     type = options["type"]
@@ -84,8 +89,13 @@
     # Make sure the temporal database exists
     tgis.init()
 
+    if not output:
+        output = None
+    if output == "-":
+        output = None
+
     tgis.print_vector_dataset_univar_statistics(
-        input, twhere, layer, type, column, where, extended, header, separator)
+        input, output, twhere, layer, type, column, where, extended, header, separator)
 
 if __name__ == "__main__":
     options, flags = grass.parser()



More information about the grass-commit mailing list