[GRASS-SVN] r61192 - in grass/trunk/temporal: t.rast.extract t.rast.extract/testsuite t.remove
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 8 07:39:32 PDT 2014
Author: huhabla
Date: 2014-07-08 07:39:31 -0700 (Tue, 08 Jul 2014)
New Revision: 61192
Added:
grass/trunk/temporal/t.rast.extract/testsuite/
grass/trunk/temporal/t.rast.extract/testsuite/test_extract.py
Removed:
grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh
Modified:
grass/trunk/temporal/t.remove/t.remove.py
Log:
Converted shell test into gunittest. Added testsuite directory.
Deleted: grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh
===================================================================
--- grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh 2014-07-08 14:36:31 UTC (rev 61191)
+++ grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh 2014-07-08 14:39:31 UTC (rev 61192)
@@ -1,37 +0,0 @@
-#!/bin/sh
-# Test the extraction of a subset of a space time raster input
-
-# We need to set a specific region in the
-# @preprocess step of this test. We generate
-# raster with r.mapcalc
-# 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 --o expr="prec_1 = rand(0, 550)"
-r.mapcalc --o expr="prec_2 = rand(0, 450)"
-r.mapcalc --o expr="prec_3 = rand(0, 320)"
-r.mapcalc --o expr="prec_4 = rand(0, 510)"
-r.mapcalc --o expr="prec_5 = rand(0, 300)"
-r.mapcalc --o expr="prec_6 = rand(0, 650)"
-
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i type=rast input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="3 months"
-
-# The @test
-t.rast.extract --o --v input=precip_abs1 output=precip_abs2 where="start_time > '2001-06-01'" \
- expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=2
-t.info type=strds input=precip_abs2
-
-t.rast.extract --o --v -n input=precip_abs1 output=precip_abs3 where="start_time > '2001-06-01'" \
- expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=4
-t.info type=strds input=precip_abs3
-
-# Let the test fail
-g.remove rast=prec_1
-
-t.rast.extract --o --v input=precip_abs1 output=precip_abs4 \
- where="start_time > '2001-01-01'" expr="precip_abs1/1.0"\
- base=new_test
-t.info type=strds input=precip_abs4
-
-t.remove -rf type=strds input=precip_abs1,precip_abs2,precip_abs3
Added: grass/trunk/temporal/t.rast.extract/testsuite/test_extract.py
===================================================================
--- grass/trunk/temporal/t.rast.extract/testsuite/test_extract.py (rev 0)
+++ grass/trunk/temporal/t.rast.extract/testsuite/test_extract.py 2014-07-08 14:39:31 UTC (rev 61192)
@@ -0,0 +1,155 @@
+"""Test t.rast.extract
+
+(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
+"""
+
+import grass.script as grass
+import grass.pygrass.modules as pymod
+import subprocess
+from gunittest.case import TestCase
+
+class TestRasterExtraction(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """!Initiate the temporal GIS and set the region
+ """
+ grass.use_temp_region()
+ cls.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")
+ cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)
+
+ @classmethod
+ def tearDownClass(cls):
+ """!Remove the temporary region
+ """
+ grass.del_temp_region()
+
+ def setUp(self):
+ """Create input data for transient groundwater flow computation
+ """
+ # Use always the current mapset as temporal database
+ self.runModule("r.mapcalc", expression="prec_1 = 100")
+ self.runModule("r.mapcalc", expression="prec_2 = 200")
+ self.runModule("r.mapcalc", expression="prec_3 = 300")
+ self.runModule("r.mapcalc", expression="prec_4 = 400")
+ self.runModule("r.mapcalc", expression="prec_5 = 500")
+ self.runModule("r.mapcalc", expression="prec_6 = 600")
+
+ self.runModule("t.create", type="strds", temporaltype="absolute",
+ output="precip_abs1", title="A test", description="A test")
+ self.runModule("t.register", flags="i", type="rast", input="precip_abs1",
+ maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6",
+ start="2001-01-01", increment="3 months")
+
+ def tearDown(self):
+ """Remove generated data"""
+ self.runModule("t.remove", flags="rf", type="strds",
+ inputs="precip_abs1,precip_abs2")
+
+ def test_selection(self):
+ """Perform a simple selection by datetime"""
+ self.assertModule("t.rast.extract", input="precip_abs1", output="precip_abs2",
+ where="start_time > '2001-06-01'")
+
+ #self.assertModule("t.info", flags="g", input="precip_abs2")
+
+ tinfo_string="""start_time=2001-07-01 00:00:00
+ end_time=2002-07-01 00:00:00
+ granularity=3 months
+ map_time=interval
+ north=80.0
+ south=0.0
+ east=120.0
+ west=0.0
+ top=0.0
+ bottom=0.0
+ aggregation_type=None
+ number_of_maps=4
+ nsres_min=10.0
+ nsres_max=10.0
+ ewres_min=10.0
+ ewres_max=10.0
+ min_min=300.0
+ min_max=600.0
+ max_min=300.0
+ max_max=600.0"""
+
+ self.assertCommandKeyValue(module="t.info",
+ parameters=dict(flags="g", input="precip_abs2"),
+ reference=tinfo_string, precision=2, sep="=")
+
+ def test_selection_and_expression(self):
+ """Perform a selection by datetime and a r.mapcalc expression"""
+ self.assertModule("t.rast.extract", input="precip_abs1", output="precip_abs2",
+ where="start_time > '2001-06-01'",
+ expression=" if(precip_abs1 > 400, precip_abs1, null())",
+ basename="new_prec", nprocs=2)
+
+ #self.assertModule("t.info", flags="g", input="precip_abs2")
+
+ tinfo_string="""start_time=2002-01-01 00:00:00
+ end_time=2002-07-01 00:00:00
+ granularity=3 months
+ map_time=interval
+ north=80.0
+ south=0.0
+ east=120.0
+ west=0.0
+ top=0.0
+ bottom=0.0
+ aggregation_type=None
+ number_of_maps=2
+ nsres_min=10.0
+ nsres_max=10.0
+ ewres_min=10.0
+ ewres_max=10.0
+ min_min=500.0
+ min_max=600.0
+ max_min=500.0
+ max_max=600.0"""
+
+ self.assertCommandKeyValue(module="t.info",
+ parameters=dict(flags="g", input="precip_abs2"),
+ reference=tinfo_string, precision=2, sep="=")
+
+ def test_expression_with_empty_maps(self):
+ """Perform r.mapcalc expression and register empty maps"""
+ self.assertModule("t.rast.extract", flags="n", input="precip_abs1", output="precip_abs2",
+ expression=" if(precip_abs1 > 400, precip_abs1, null())",
+ basename="new_prec", nprocs=2)
+
+ #self.assertModule("t.info", flags="g", input="precip_abs2")
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2002-07-01 00:00:00
+ granularity=3 months
+ map_time=interval
+ north=80.0
+ south=0.0
+ east=120.0
+ west=0.0
+ top=0.0
+ bottom=0.0
+ aggregation_type=None
+ number_of_maps=6
+ nsres_min=10.0
+ nsres_max=10.0
+ ewres_min=10.0
+ ewres_max=10.0
+ min_min=500.0
+ min_max=600.0
+ max_min=500.0
+ max_max=600.0"""
+
+ self.assertCommandKeyValue(module="t.info",
+ parameters=dict(flags="g", input="precip_abs2"),
+ reference=tinfo_string, precision=2, sep="=")
+
+if __name__ == '__main__':
+ from gunittest.main import test
+ test()
Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py 2014-07-08 14:36:31 UTC (rev 61191)
+++ grass/trunk/temporal/t.remove/t.remove.py 2014-07-08 14:39:31 UTC (rev 61192)
@@ -125,7 +125,7 @@
# to avoid multiple deletation of the same map,
# but the database entries are still present and must be removed
if map.get_name() not in name_list:
- name_list.append(map.get_name())
+ name_list.append(str(map.get_name()))
map_statement += map.delete(dbif=dbif, execute=False)
count += 1
@@ -140,11 +140,11 @@
dbif.execute_transaction(map_statement)
if name_list:
if type == "strds":
- remove(rast=name_list, run_=True)
+ remove(rast=",".join(name_list), run_=True)
if type == "stvds":
- remove(vect=name_list, run_=True)
+ remove(vect=",".join(name_list), run_=True)
if type == "str3ds":
- remove(rast3d=name_list, run_=True)
+ remove(rast3d=",".join(name_list), run_=True)
statement += sp.delete(dbif=dbif, execute=False)
More information about the grass-commit
mailing list