[GRASS-SVN] r41667 - in grass/trunk: include lib/stats raster/r.series

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 2 07:15:44 EDT 2010


Author: neteler
Date: 2010-04-02 07:15:43 -0400 (Fri, 02 Apr 2010)
New Revision: 41667

Added:
   grass/trunk/lib/stats/c_thresh.c
Modified:
   grass/trunk/include/stats.h
   grass/trunk/raster/r.series/main.c
Log:
threshold parameter added

Modified: grass/trunk/include/stats.h
===================================================================
--- grass/trunk/include/stats.h	2010-04-02 11:05:58 UTC (rev 41666)
+++ grass/trunk/include/stats.h	2010-04-02 11:15:43 UTC (rev 41667)
@@ -20,6 +20,7 @@
 extern stat_func c_mode;
 extern stat_func c_stddev;
 extern stat_func c_sum;
+extern stat_func c_thresh;
 extern stat_func c_var;
 extern stat_func c_range;
 extern stat_func c_reg_m;

Added: grass/trunk/lib/stats/c_thresh.c
===================================================================
--- grass/trunk/lib/stats/c_thresh.c	                        (rev 0)
+++ grass/trunk/lib/stats/c_thresh.c	2010-04-02 11:15:43 UTC (rev 41667)
@@ -0,0 +1,38 @@
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+
+void c_thresh(DCELL * result, DCELL * values, int n, const void *closure)
+{
+    DCELL thresh, threshx;
+    double tval = *(const double *)closure;
+    double epsilon = GRASS_EPSILON;
+    int i;
+
+    Rast_set_d_null_value(&thresh, 1);
+    Rast_set_d_null_value(&threshx, 1);
+
+    for (i = 0; i < n; i++) {
+	/* already found */
+	if (! Rast_is_d_null_value(&threshx))
+	    continue;
+
+	if (Rast_is_d_null_value(&values[i]))
+	    continue;
+
+	G_debug(2, "values[%d] %f, tval %f", i, values[i], tval);
+	/* for GDD */
+	epsilon = 10.;
+	if (fabs(tval - values[i]) < epsilon ) {
+	    thresh = values[i];
+	    threshx = i + 1;
+	    G_debug(2, "values[%d] %f, thresh %f, threshx %f, diff %f", i, values[i], thresh, threshx, tval - values[i]);
+	}
+    }
+
+    if (Rast_is_d_null_value(&threshx))
+	Rast_set_d_null_value(result, 1);
+    else
+	*result = threshx;
+}


Property changes on: grass/trunk/lib/stats/c_thresh.c
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: grass/trunk/raster/r.series/main.c
===================================================================
--- grass/trunk/raster/r.series/main.c	2010-04-02 11:05:58 UTC (rev 41666)
+++ grass/trunk/raster/r.series/main.c	2010-04-02 11:15:43 UTC (rev 41667)
@@ -40,6 +40,7 @@
     {c_stddev, 0, "stddev",     "standard deviation"},
     {c_range,  0, "range",      "range of values"},
     {c_sum,    0, "sum",        "sum of values"},
+    {c_thresh, 1, "threshold",  "threshold value"},
     {c_var,    0, "variance",   "statistical variance"},
     {c_divr,   1, "diversity",  "number of different values"},
     {c_reg_m,  0, "slope",      "linear regression slope"},
@@ -68,6 +69,7 @@
     DCELL *buf;
     stat_func *method_fn;
     double quantile;
+    double threshold;
 };
 
 static char *build_method_list(void)
@@ -107,7 +109,7 @@
     struct GModule *module;
     struct
     {
-	struct Option *input, *output, *method, *quantile, *range;
+	struct Option *input, *output, *method, *quantile, *threshold, *range;
     } parm;
     struct
     {
@@ -155,6 +157,13 @@
     parm.quantile->options = "0.0-1.0";
     parm.quantile->multiple = YES;
 
+    parm.threshold = G_define_option();
+    parm.threshold->key = "threshold";
+    parm.threshold->type = TYPE_DOUBLE;
+    parm.threshold->required = NO;
+    parm.threshold->description = _("Threshold to calculate for method=threshold");
+    parm.threshold->multiple = YES;
+
     parm.range = G_define_option();
     parm.range->key = "range";
     parm.range->type = TYPE_DOUBLE;
@@ -215,6 +224,9 @@
 	out->quantile = (parm.quantile->answer && parm.quantile->answers[i])
 	    ? atof(parm.quantile->answers[i])
 	    : 0;
+	out->threshold = (parm.threshold->answer && parm.threshold->answers[i])
+	    ? atof(parm.threshold->answers[i])
+	    : 0;
 	out->buf = Rast_allocate_d_buf();
 	out->fd = Rast_open_new(output_name,
 				menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
@@ -259,7 +271,7 @@
 		    Rast_set_d_null_value(&out->buf[col], 1);
 		else {
 		    memcpy(values_tmp, values, num_inputs * sizeof(DCELL));
-		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs, &out->quantile);
+		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs, &out->threshold);
 		}
 	    }
 	}



More information about the grass-commit mailing list