[GRASS-SVN] r58687 - in grass/branches/develbranch_6: include raster/r.resamp.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 12 13:43:37 PST 2014


Author: neteler
Date: 2014-01-12 13:43:37 -0800 (Sun, 12 Jan 2014)
New Revision: 58687

Modified:
   grass/branches/develbranch_6/include/stats.h
   grass/branches/develbranch_6/raster/r.resamp.stats/main.c
Log:
r.resamp.stats: backport of adding weighted versions of min, max aggregates (trunk, r33888); Add method=quantile to r.resamp.stats (trunk, r36918) (trac #337)

Modified: grass/branches/develbranch_6/include/stats.h
===================================================================
--- grass/branches/develbranch_6/include/stats.h	2014-01-12 21:14:42 UTC (rev 58686)
+++ grass/branches/develbranch_6/include/stats.h	2014-01-12 21:43:37 UTC (rev 58687)
@@ -35,10 +35,13 @@
 extern stat_func_w w_ave;
 extern stat_func_w w_count;
 extern stat_func_w w_median;
+extern stat_func_w w_min;
+extern stat_func_w w_max;
 extern stat_func_w w_mode;
 extern stat_func_w w_quart1;
 extern stat_func_w w_quart3;
 extern stat_func_w w_perc90;
+extern stat_func_w w_quant;
 extern stat_func_w w_reg_m;
 extern stat_func_w w_reg_c;
 extern stat_func_w w_reg_r2;

Modified: grass/branches/develbranch_6/raster/r.resamp.stats/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.resamp.stats/main.c	2014-01-12 21:14:42 UTC (rev 58686)
+++ grass/branches/develbranch_6/raster/r.resamp.stats/main.c	2014-01-12 21:43:37 UTC (rev 58687)
@@ -30,15 +30,16 @@
     {c_ave,    w_ave,    "average",  "average (mean) value"},
     {c_median, w_median, "median",   "median value"},
     {c_mode,   w_mode,   "mode",     "most frequently occuring value"},
-    {c_min,    NULL,     "minimum",  "lowest value"},
-    {c_max,    NULL,     "maximum",  "highest value"},
+    {c_min,    w_min,    "minimum",  "lowest value"},
+    {c_max,    w_max,    "maximum",  "highest value"},
     {c_quart1, w_quart1, "quart1",   "first quartile"},
     {c_quart3, w_quart3, "quart3",   "third quartile"},
     {c_perc90, w_perc90, "perc90",   "ninetieth percentile"},
     {c_sum,    w_sum,    "sum",      "sum of values"},
     {c_var,    w_var,    "variance", "variance value"},
     {c_stddev, w_stddev, "stddev",   "standard deviation"},
-    {NULL, NULL, NULL, NULL}
+    {c_quant,  w_quant,  "quantile", "arbitrary quantile"},
+    {NULL, NULL, NULL}
 };
 
 static char *build_method_list(void)
@@ -77,7 +78,9 @@
 static DCELL *outbuf;
 static DCELL **bufs;
 static int method;
+static const void *closure;
 static int row_scale, col_scale;
+static double quantile;
 
 static void resamp_unweighted(void)
 {
@@ -141,7 +144,7 @@
 	    if (null && nulls)
 		G_set_d_null_value(&outbuf[col], 1);
 	    else
-		(*method_fn) (&outbuf[col], values, n, NULL);
+		(*method_fn) (&outbuf[col], values, n, closure);
 	}
 
 	G_set_window(&dst_w);
@@ -227,7 +230,7 @@
 	    if (null && nulls)
 		G_set_d_null_value(&outbuf[col], 1);
 	    else
-		(*method_fn) (&outbuf[col], values, n, NULL);
+		(*method_fn) (&outbuf[col], values, n, closure);
 	}
 
 	G_set_window(&dst_w);
@@ -240,7 +243,7 @@
     struct GModule *module;
     struct
     {
-	struct Option *rastin, *rastout, *method;
+	struct Option *rastin, *rastout, *method, *quantile;
     } parm;
     struct
     {
@@ -272,6 +275,14 @@
     parm.method->options = build_method_list();
     parm.method->answer = "average";
 
+    parm.quantile = G_define_option();
+    parm.quantile->key = "quantile";
+    parm.quantile->type = TYPE_DOUBLE;
+    parm.quantile->required = NO;
+    parm.quantile->description = _("Quantile to calculate for method=quantile");
+    parm.quantile->options = "0.0-1.0";
+    parm.quantile->answer = "0.5";
+
     flag.nulls = G_define_flag();
     flag.nulls->key = 'n';
     flag.nulls->description = _("Propagate NULLs");
@@ -289,6 +300,11 @@
     if (method < 0)
 	G_fatal_error(_("Unknown method <%s>"), parm.method->answer);
 
+    if (menu[method].method == c_quant) {
+	quantile = atoi(parm.quantile->answer);
+	closure = &quantile;
+    }
+
     G_get_set_window(&dst_w);
 
     inmap = G_find_cell2(parm.rastin->answer, "");



More information about the grass-commit mailing list