[GRASS-SVN] r61179 - in grass/trunk/raster/r.gwflow: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 7 15:49:16 PDT 2014
Author: huhabla
Date: 2014-07-07 15:49:16 -0700 (Mon, 07 Jul 2014)
New Revision: 61179
Added:
grass/trunk/raster/r.gwflow/testsuite/
grass/trunk/raster/r.gwflow/testsuite/validation_7x7_grid.py
grass/trunk/raster/r.gwflow/testsuite/validation_excavation.py
Removed:
grass/trunk/raster/r.gwflow/valid_calc_7x7.py
grass/trunk/raster/r.gwflow/valid_calc_excavation.py
Log:
Moved the validation code into the testsuite directory that contains now gunittests
with r.info and r.univar validation of raster results.
Added: grass/trunk/raster/r.gwflow/testsuite/validation_7x7_grid.py
===================================================================
--- grass/trunk/raster/r.gwflow/testsuite/validation_7x7_grid.py (rev 0)
+++ grass/trunk/raster/r.gwflow/testsuite/validation_7x7_grid.py 2014-07-07 22:49:16 UTC (rev 61179)
@@ -0,0 +1,97 @@
+"""Test to verify r.gwflow calculation, this calculation is based on
+the example at page 133 of the following book:
+author = "Kinzelbach, W. and Rausch, R.",
+title = "Grundwassermodellierung",
+publisher = "Gebr{\"u}der Borntraeger (Berlin, Stuttgart)",
+year = "1995"
+
+ at author Soeren Gebbert
+"""
+
+import grass.script as grass
+import grass.pygrass.modules as pymod
+from gunittest.case import TestCase
+
+# Output of r.univar
+UNIVAR_OUTPUT="""n=49
+null_cells=0
+cells=49
+min=45.1219899394172
+max=50
+range=4.8780100605828
+mean=49.081632669812
+mean_of_abs=49.081632669812
+stddev=0.908558909200636
+variance=0.825479291487849
+coeff_var=1.85111794326975
+sum=2405.00000082079
+"""
+
+# Output of r.info, only a subset of the output is needed
+INFO_OUTPUT="""north=700
+south=0
+east=700
+west=0
+nsres=100
+ewres=100
+rows=7
+cols=7
+cells=49
+datatype=DCELL
+ncats=0
+min=45.1219899394172
+max=50
+map=gwresult_conf
+"""
+
+class Validation7x7Grid(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """!Initiate the temporal GIS and set the region
+ """
+ # Use always the current mapset as temporal database
+ grass.use_temp_region()
+ grass.run_command("g.region", res=100, n=700, s=0, w=0, e=700)
+
+ def setUp(self):
+ """Create input data for transient groundwater flow computation
+ """
+ self.assertModule("r.mapcalc", expression="phead=50")
+ self.assertModule("r.mapcalc", expression="status=if(col() == 1 || col() == 7 , 2, 1)")
+ self.assertModule("r.mapcalc", expression="well=if((row() == 4 && col() == 4), -0.1, 0)")
+ self.assertModule("r.mapcalc", expression="hydcond=0.0005")
+ self.assertModule("r.mapcalc", expression="recharge=0")
+ self.assertModule("r.mapcalc", expression="top_conf=20")
+ self.assertModule("r.mapcalc", expression="bottom=0")
+ self.assertModule("r.mapcalc", expression="s=0.0001")
+ self.assertModule("r.mapcalc", expression="null=0.0")
+
+ def test_transient(self):
+ #First compute the groundwater flow
+ grass.run_command("r.gwflow", "f", solver="cholesky", top="top_conf", bottom="bottom", phead="phead",\
+ status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
+ recharge="recharge", output="gwresult_conf", dt=500, type="confined", budget="water_budget", overwrite=True)
+
+ # loop over the timesteps
+ for i in range(20):
+ grass.run_command("r.gwflow", "f", solver="cholesky", top="top_conf", bottom="bottom", phead="gwresult_conf",\
+ status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
+ recharge="recharge", output="gwresult_conf", dt=500, type="confined", budget="water_budget", overwrite=True)
+
+ global UNIVAR_OUTPUT
+ self.assertRasterFitsUnivar(raster="gwresult_conf", reference=UNIVAR_OUTPUT, precision=3)
+ global INFO_OUTPUT
+ self.assertRasterFitsInfo(raster="gwresult_conf", reference=INFO_OUTPUT, precision=3)
+
+ @classmethod
+ def tearDownClass(cls):
+ """!Remove the temporary region
+ """
+ grass.del_temp_region()
+
+if __name__ == '__main__':
+ from gunittest.main import test
+ test()
+
+
Added: grass/trunk/raster/r.gwflow/testsuite/validation_excavation.py
===================================================================
--- grass/trunk/raster/r.gwflow/testsuite/validation_excavation.py (rev 0)
+++ grass/trunk/raster/r.gwflow/testsuite/validation_excavation.py 2014-07-07 22:49:16 UTC (rev 61179)
@@ -0,0 +1,96 @@
+"""Test to verify r.gwflow calculation, this calculation is based on
+the example at page 167 of the following book:
+author = "Kinzelbach, W. and Rausch, R.",
+title = "Grundwassermodellierung",
+publisher = "Gebr{\"u}der Borntraeger (Berlin, Stuttgart)",
+year = "1995"
+
+ at author Soeren Gebbert
+"""
+
+import grass.script as grass
+import grass.pygrass.modules as pymod
+from gunittest.case import TestCase
+
+# Output of r.univar -g
+UNIVAR_OUTPUT="""n=760
+null_cells=0
+cells=760
+min=3
+max=5.39762629189687
+range=2.39762629189687
+mean=5.02846950820457
+mean_of_abs=5.02846950820457
+stddev=0.333565013446849
+variance=0.111265618195797
+coeff_var=6.63352960384062
+sum=3821.63682623547
+"""
+
+# Output of r.info -gre, only a subset of the output is needed
+INFO_OUTPUT="""north=950
+south=0
+east=2000
+west=0
+nsres=50
+ewres=50
+rows=19
+cols=40
+cells=760
+datatype=DCELL
+ncats=0
+min=3
+max=5.3976262918968
+map=gwresult
+"""
+
+class ValidationExcavation(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """!Initiate the temporal GIS and set the region
+ """
+ # Use always the current mapset as temporal database
+ grass.use_temp_region()
+ grass.run_command("g.region", flags="p", res=50, n=950, s=0, w=0, e=2000)
+
+ def setUp(self):
+ """Create input data for steady state groundwater flow computation
+ """
+
+ self.assertModule("r.mapcalc", expression="phead= if(row() == 19, 5, 3)")
+ self.assertModule("r.mapcalc", expression="status=if((col() == 1 && row() == 13) ||\
+ (col() == 1 && row() == 14) ||\
+ (col() == 2 && row() == 13) ||\
+ (col() == 2 && row() == 14) ||\
+ (row() == 19), 2, 1)")
+
+ self.assertModule("r.mapcalc", expression="hydcond=0.001")
+ self.assertModule("r.mapcalc", expression="recharge=0.000000006")
+ self.assertModule("r.mapcalc", expression="top=20")
+ self.assertModule("r.mapcalc", expression="bottom=0")
+ self.assertModule("r.mapcalc", expression="poros=0.1")
+ self.assertModule("r.mapcalc", expression="null=0.0")
+
+ def test_steady_state(self):
+ #compute a steady state groundwater flow
+ grass.run_command("r.gwflow", flags="f", solver="cholesky", top="top", bottom="bottom", phead="phead", \
+ status="status", hc_x="hydcond", hc_y="hydcond", s="poros", \
+ recharge="recharge", output="gwresult", dt=864000000000, type="unconfined", budget="water_budget")
+
+ global UNIVAR_OUTPUT
+ self.assertRasterFitsUnivar(raster="gwresult", reference=UNIVAR_OUTPUT, precision=3)
+ global INFO_OUTPUT
+ self.assertRasterFitsInfo(raster="gwresult", reference=INFO_OUTPUT, precision=3)
+
+ @classmethod
+ def tearDownClass(cls):
+ """!Remove the temporary region
+ """
+ grass.del_temp_region()
+
+if __name__ == '__main__':
+ from gunittest.main import test
+ test()
+
+
Deleted: grass/trunk/raster/r.gwflow/valid_calc_7x7.py
===================================================================
--- grass/trunk/raster/r.gwflow/valid_calc_7x7.py 2014-07-07 22:33:28 UTC (rev 61178)
+++ grass/trunk/raster/r.gwflow/valid_calc_7x7.py 2014-07-07 22:49:16 UTC (rev 61179)
@@ -1,43 +0,0 @@
-#!/usr/bin/env python
-# Python script to verify r.gwflow calculation, this calculation is based on
-# the example at page 133 of the following book:
-# author = "Kinzelbach, W. and Rausch, R.",
-# title = "Grundwassermodellierung",
-# publisher = "Gebr{\"u}der Borntraeger (Berlin, Stuttgart)",
-# year = "1995"
-#
-import sys
-import os
-import grass.script as grass
-
-# Overwrite existing maps
-grass.run_command("g.gisenv", set="OVERWRITE=1")
-
-grass.message(_("Set the region"))
-
-# The area is 2000m x 1000m with a cell size of 25m x 25m
-grass.run_command("g.region", res=100, n=700, s=0, w=0, e=700)
-
-grass.run_command("r.mapcalc", expression="phead=50")
-grass.run_command("r.mapcalc", expression="status=if(col() == 1 || col() == 7 , 2, 1)")
-grass.run_command("r.mapcalc", expression="well=if((row() == 4 && col() == 4), -0.1, 0)")
-grass.run_command("r.mapcalc", expression="hydcond=0.0005")
-grass.run_command("r.mapcalc", expression="recharge=0")
-grass.run_command("r.mapcalc", expression="top_conf=20")
-grass.run_command("r.mapcalc", expression="bottom=0")
-grass.run_command("r.mapcalc", expression="s=0.0001")
-grass.run_command("r.mapcalc", expression="null=0.0")
-
-#First compute the groundwater flow
-grass.run_command("r.gwflow", "f", solver="cholesky", top="top_conf", bottom="bottom", phead="phead",\
- status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
- recharge="recharge", output="gwresult_conf", dt=500, type="confined", budget="water_budget")
-
-count=500
-# loop over the timesteps
-for i in range(20):
- grass.run_command("r.gwflow", "f", solver="cholesky", top="top_conf", bottom="bottom", phead="gwresult_conf",\
- status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
- recharge="recharge", output="gwresult_conf", dt=500, type="confined", budget="water_budget")
- count += 500
-
Deleted: grass/trunk/raster/r.gwflow/valid_calc_excavation.py
===================================================================
--- grass/trunk/raster/r.gwflow/valid_calc_excavation.py 2014-07-07 22:33:28 UTC (rev 61178)
+++ grass/trunk/raster/r.gwflow/valid_calc_excavation.py 2014-07-07 22:49:16 UTC (rev 61179)
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-# Shellscript to verify r.gwflow calculation, this calculation is based on
-# the example at page 167 of the following book:
-# author = "Kinzelbach, W. and Rausch, R.",
-# title = "Grundwassermodellierung",
-# publisher = "Gebr{\"u}der Borntraeger (Berlin, Stuttgart)",
-# year = "1995"
-#
-import sys
-import os
-import grass.script as grass
-
-# Overwrite existing maps
-grass.run_command("g.gisenv", set="OVERWRITE=1")
-
-grass.message(_("Set the region"))
-
-# The area is 2000m x 1000m with a cell size of 25m x 25m
-grass.run_command("g.region", res=50, n=950, s=0, w=0, e=2000)
-
-grass.run_command("r.mapcalc", expression="phead= if(row() == 19, 5, 3)")
-grass.run_command("r.mapcalc", expression="status=if((col() == 1 && row() == 13) ||\
- (col() == 1 && row() == 14) ||\
- (col() == 2 && row() == 13) ||\
- (col() == 2 && row() == 14) ||\
- (row() == 19), 2, 1)")
-
-grass.run_command("r.mapcalc", expression="hydcond=0.001")
-grass.run_command("r.mapcalc", expression="recharge=0.000000006")
-grass.run_command("r.mapcalc", expression="top=20")
-grass.run_command("r.mapcalc", expression="bottom=0")
-grass.run_command("r.mapcalc", expression="poros=0.1")
-grass.run_command("r.mapcalc", expression="null=0.0")
-
-#compute a steady state groundwater flow
-grass.run_command("r.gwflow", "f", solver="cholesky", top="top", bottom="bottom", phead="phead", \
- status="status", hc_x="hydcond", hc_y="hydcond", s="poros", \
- recharge="recharge", output="gwresult", dt=864000000000, type="unconfined", budget="water_budget")
More information about the grass-commit
mailing list