[GRASS-SVN] r41666 - in grass/branches/develbranch_6: include
lib/stats raster/r.series
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 2 07:06:00 EDT 2010
Author: neteler
Date: 2010-04-02 07:05:58 -0400 (Fri, 02 Apr 2010)
New Revision: 41666
Added:
grass/branches/develbranch_6/lib/stats/c_thresh.c
Modified:
grass/branches/develbranch_6/include/stats.h
grass/branches/develbranch_6/raster/r.series/main.c
Log:
threshold parameter added
Modified: grass/branches/develbranch_6/include/stats.h
===================================================================
--- grass/branches/develbranch_6/include/stats.h 2010-04-02 10:59:34 UTC (rev 41665)
+++ grass/branches/develbranch_6/include/stats.h 2010-04-02 11:05:58 UTC (rev 41666)
@@ -19,6 +19,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/branches/develbranch_6/lib/stats/c_thresh.c
===================================================================
--- grass/branches/develbranch_6/lib/stats/c_thresh.c (rev 0)
+++ grass/branches/develbranch_6/lib/stats/c_thresh.c 2010-04-02 11:05:58 UTC (rev 41666)
@@ -0,0 +1,36 @@
+#include <grass/gis.h>
+#include <math.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;
+
+ G_set_d_null_value(&thresh, 1);
+ G_set_d_null_value(&threshx, 1);
+
+ for (i = 0; i < n; i++) {
+ /* already found */
+ if (! G_is_d_null_value(&threshx))
+ continue;
+
+ if (G_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 (G_is_d_null_value(&threshx))
+ G_set_d_null_value(result, 1);
+ else
+ *result = threshx;
+}
Property changes on: grass/branches/develbranch_6/lib/stats/c_thresh.c
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: grass/branches/develbranch_6/raster/r.series/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.series/main.c 2010-04-02 10:59:34 UTC (rev 41665)
+++ grass/branches/develbranch_6/raster/r.series/main.c 2010-04-02 11:05:58 UTC (rev 41666)
@@ -39,6 +39,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"},
@@ -67,6 +68,7 @@
DCELL *buf;
stat_func *method_fn;
double quantile;
+ double threshold;
};
static char *build_method_list(void)
@@ -106,7 +108,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;
+
/* please, remove before GRASS 7 released */
flag.quiet = G_define_flag();
flag.quiet->key = 'q';
@@ -231,6 +240,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 = G_allocate_d_raster_buf();
out->fd = G_open_raster_new(
output_name, menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
@@ -277,7 +289,7 @@
G_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