[GRASS-SVN] r66602 - in grass/trunk/raster/r.univar: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 26 04:51:23 PDT 2015


Author: huhabla
Date: 2015-10-26 04:51:23 -0700 (Mon, 26 Oct 2015)
New Revision: 66602

Modified:
   grass/trunk/raster/r.univar/r.univar_main.c
   grass/trunk/raster/r.univar/stats.c
   grass/trunk/raster/r.univar/testsuite/test_r_univar.py
Log:
Fixed zone map region bug, introduced with the -r 
flag for map specific regions.
Modified the output of the -g flag in case of zones. Now the shell
style is consistent. Instead of "\nzone num cat\n\n" -> "zone=num;cat"
is printed to stdout. 


Modified: grass/trunk/raster/r.univar/r.univar_main.c
===================================================================
--- grass/trunk/raster/r.univar/r.univar_main.c	2015-10-26 04:18:55 UTC (rev 66601)
+++ grass/trunk/raster/r.univar/r.univar_main.c	2015-10-26 11:51:23 UTC (rev 66602)
@@ -178,11 +178,11 @@
 	if(param.use_rast_region->answer) {
     	    mapset = G_find_raster2(*p, "");
 	    Rast_get_cellhd(*p, mapset, &region);
+	    /* Set the computational region */
+	    Rast_set_window(&region);
         } else {
     	    G_get_window(&region);
         }
-	/* Set the computational region */
-	Rast_set_window(&region);
 
 	fd = open_raster(*p);
 

Modified: grass/trunk/raster/r.univar/stats.c
===================================================================
--- grass/trunk/raster/r.univar/stats.c	2015-10-26 04:18:55 UTC (rev 66601)
+++ grass/trunk/raster/r.univar/stats.c	2015-10-26 11:51:23 UTC (rev 66602)
@@ -134,19 +134,22 @@
 	sprintf(sum_str, "%.15g", stats[z].sum);
 	G_trim_decimal(sum_str);
 
-	if (zone_info.n_zones) {
-	    int z_cat = z + zone_info.min;
-	    
-	    fprintf(stdout, "\nzone %d %s\n\n", z_cat, Rast_get_c_cat(&z_cat, &(zone_info.cats)));
-	}
 
 	if (!param.shell_style->answer) {
+	    if (zone_info.n_zones) {
+	    	int z_cat = z + zone_info.min;
+	    	fprintf(stdout, "\nzone %d %s\n\n", z_cat, Rast_get_c_cat(&z_cat, &(zone_info.cats)));
+	    }
 	    fprintf(stdout, "total null and non-null cells: %lu\n", stats[z].size);
 	    fprintf(stdout, "total null cells: %lu\n\n", stats[z].size - stats[z].n);
 	    fprintf(stdout, "Of the non-null cells:\n----------------------\n");
 	}
 
 	if (param.shell_style->answer) {
+	    if (zone_info.n_zones) {
+	    	int z_cat = z + zone_info.min;
+	    	fprintf(stdout, "zone=%d;%s\n", z_cat, Rast_get_c_cat(&z_cat, &(zone_info.cats)));
+	    }
 	    fprintf(stdout, "n=%lu\n", stats[z].n);
 	    fprintf(stdout, "null_cells=%lu\n", stats[z].size - stats[z].n);
 	    fprintf(stdout, "cells=%lu\n", stats->size);

Modified: grass/trunk/raster/r.univar/testsuite/test_r_univar.py
===================================================================
--- grass/trunk/raster/r.univar/testsuite/test_r_univar.py	2015-10-26 04:18:55 UTC (rev 66601)
+++ grass/trunk/raster/r.univar/testsuite/test_r_univar.py	2015-10-26 11:51:23 UTC (rev 66602)
@@ -18,8 +18,10 @@
         cls.del_temp_region()
 
     def tearDown(self):
+    	pass
         self.runModule("g.remove", type="raster", name="map_a")
         self.runModule("g.remove", type="raster", name="map_b")
+        self.runModule("g.remove", type="raster", name="zone_map")
 
     def setUp(self):
         """Create input data
@@ -29,6 +31,8 @@
                        overwrite=True)
         self.runModule("r.mapcalc", expression="map_b = 200 + row() + col()",
                        overwrite=True)
+        self.runModule("r.mapcalc", expression="zone_map = if(row() < 20, 1,2)",
+                       overwrite=True)
 
     def test_1(self):
         # Output of r.univar
@@ -135,6 +139,40 @@
         self.assertModuleKeyValue(module="r.univar", map=["map_a","map_b"], flags="rg",
                                   reference=univar_string, precision=3, sep='=')
 
+
+    def test_1_zone(self):
+        """
+        multiple maps and zone
+        :return:
+        """
+
+        # Output of r.univar
+        univar_string="""zone=1;
+			n=1710
+			null_cells=0
+			cells=1710
+			min=102
+			max=209
+			range=107
+			mean=155.5
+			mean_of_abs=155.5
+			sum=265905
+			zone=2;
+			n=6390
+			null_cells=0
+			cells=1710
+			min=121
+			max=280
+			range=159
+			mean=200.5
+			mean_of_abs=200.5
+			sum=1281195"""
+
+        self.runModule("g.region", res=1)
+        self.assertModuleKeyValue(module="r.univar", map=["map_a"], 
+                                  zones="zone_map",flags="g",
+                                  reference=univar_string, precision=3, sep='=')
+
 class TestAccumulateFails(TestCase):
 
     def test_error_handling(self):



More information about the grass-commit mailing list