[GRASS-SVN] r43540 - in grass/branches/releasebranch_6_4: include
lib/stats raster/r.neighbors raster/r.resamp.stats raster/r.series
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 20 13:04:26 EDT 2010
Author: neteler
Date: 2010-09-20 17:04:26 +0000 (Mon, 20 Sep 2010)
New Revision: 43540
Added:
grass/branches/releasebranch_6_4/lib/stats/c_thresh.c
Modified:
grass/branches/releasebranch_6_4/include/stats.h
grass/branches/releasebranch_6_4/lib/stats/c_ave.c
grass/branches/releasebranch_6_4/lib/stats/c_count.c
grass/branches/releasebranch_6_4/lib/stats/c_divr.c
grass/branches/releasebranch_6_4/lib/stats/c_intr.c
grass/branches/releasebranch_6_4/lib/stats/c_kurt.c
grass/branches/releasebranch_6_4/lib/stats/c_max.c
grass/branches/releasebranch_6_4/lib/stats/c_maxx.c
grass/branches/releasebranch_6_4/lib/stats/c_median.c
grass/branches/releasebranch_6_4/lib/stats/c_min.c
grass/branches/releasebranch_6_4/lib/stats/c_minx.c
grass/branches/releasebranch_6_4/lib/stats/c_mode.c
grass/branches/releasebranch_6_4/lib/stats/c_percentile.c
grass/branches/releasebranch_6_4/lib/stats/c_range.c
grass/branches/releasebranch_6_4/lib/stats/c_reg.c
grass/branches/releasebranch_6_4/lib/stats/c_skew.c
grass/branches/releasebranch_6_4/lib/stats/c_stddev.c
grass/branches/releasebranch_6_4/lib/stats/c_sum.c
grass/branches/releasebranch_6_4/lib/stats/c_var.c
grass/branches/releasebranch_6_4/raster/r.neighbors/main.c
grass/branches/releasebranch_6_4/raster/r.resamp.stats/main.c
grass/branches/releasebranch_6_4/raster/r.series/main.c
Log:
backport: threshold and quantiles for r.series
Modified: grass/branches/releasebranch_6_4/include/stats.h
===================================================================
--- grass/branches/releasebranch_6_4/include/stats.h 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/include/stats.h 2010-09-20 17:04:26 UTC (rev 43540)
@@ -4,8 +4,8 @@
#include <grass/gis.h>
-typedef void stat_func(DCELL *, DCELL *, int);
-typedef void stat_func_w(DCELL *, DCELL(*)[2], int);
+typedef void stat_func(DCELL *, DCELL *, int, const void *);
+typedef void stat_func_w(DCELL *, DCELL(*)[2], int, const void *);
extern stat_func c_ave;
extern stat_func c_count;
@@ -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;
@@ -27,6 +28,7 @@
extern stat_func c_quart1;
extern stat_func c_quart3;
extern stat_func c_perc90;
+extern stat_func c_quant;
extern stat_func c_skew;
extern stat_func c_kurt;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_ave.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_ave.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_ave.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_ave(DCELL * result, DCELL * values, int n)
+void c_ave(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL sum;
int count;
@@ -23,7 +23,7 @@
*result = sum / count;
}
-void w_ave(DCELL * result, DCELL(*values)[2], int n)
+void w_ave(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL sum;
DCELL count;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_count.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_count.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_count.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_count(DCELL * result, DCELL * values, int n)
+void c_count(DCELL * result, DCELL * values, int n, const void *closure)
{
int count;
int i;
@@ -14,7 +14,7 @@
*result = count;
}
-void w_count(DCELL * result, DCELL(*values)[2], int n)
+void w_count(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL count;
int i;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_divr.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_divr.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_divr.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
#include <grass/stats.h>
-void c_divr(DCELL * result, DCELL * values, int n)
+void c_divr(DCELL * result, DCELL * values, int n, const void *closure)
{
int count;
DCELL prev;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_intr.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_intr.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_intr.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
#include <grass/stats.h>
-void c_intr(DCELL * result, DCELL * values, int n)
+void c_intr(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL center;
int count;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_kurt.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_kurt.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_kurt.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_kurt(DCELL * result, DCELL * values, int n)
+void c_kurt(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL sum, ave, sumsq, sumqt, var;
int count;
@@ -42,7 +42,7 @@
*result = sumqt / (count * var * var) - 3;
}
-void w_kurt(DCELL * result, DCELL(*values)[2], int n)
+void w_kurt(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL sum, ave, sumsq, sumqt, var;
int count;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_max.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_max.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_max.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_max(DCELL * result, DCELL * values, int n)
+void c_max(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL max;
int i;
@@ -20,3 +20,24 @@
else
*result = max;
}
+
+void w_max(DCELL * result, DCELL(*values)[2], int n, const void *closure)
+{
+ DCELL max;
+ int i;
+
+ G_set_d_null_value(&max, 1);
+
+ for (i = 0; i < n; i++) {
+ if (G_is_d_null_value(&values[i][0]))
+ continue;
+
+ if (G_is_d_null_value(&max) || max < values[i][0])
+ max = values[i][0];
+ }
+
+ if (G_is_d_null_value(&max))
+ G_set_d_null_value(result, 1);
+ else
+ *result = max;
+}
Modified: grass/branches/releasebranch_6_4/lib/stats/c_maxx.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_maxx.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_maxx.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_maxx(DCELL * result, DCELL * values, int n)
+void c_maxx(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL max, maxx;
int i;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_median.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_median.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_median.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
#include <grass/stats.h>
-void c_median(DCELL * result, DCELL * values, int n)
+void c_median(DCELL * result, DCELL * values, int n, const void *closure)
{
n = sort_cell(values, n);
@@ -11,7 +11,7 @@
*result = (values[(n - 1) / 2] + values[n / 2]) / 2;
}
-void w_median(DCELL * result, DCELL(*values)[2], int n)
+void w_median(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL total;
int i;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_min.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_min.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_min.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_min(DCELL * result, DCELL * values, int n)
+void c_min(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL min;
int i;
@@ -20,3 +20,24 @@
else
*result = min;
}
+
+void w_min(DCELL * result, DCELL(*values)[2], int n, const void *closure)
+{
+ DCELL min;
+ int i;
+
+ G_set_d_null_value(&min, 1);
+
+ for (i = 0; i < n; i++) {
+ if (G_is_d_null_value(&values[i][0]))
+ continue;
+
+ if (G_is_d_null_value(&min) || min > values[i][0])
+ min = values[i][0];
+ }
+
+ if (G_is_d_null_value(&min))
+ G_set_d_null_value(result, 1);
+ else
+ *result = min;
+}
Modified: grass/branches/releasebranch_6_4/lib/stats/c_minx.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_minx.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_minx.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
-void c_minx(DCELL * result, DCELL * values, int n)
+void c_minx(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL min, minx;
int i;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_mode.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_mode.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_mode.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
#include <grass/stats.h>
-void c_mode(DCELL * result, DCELL * values, int n)
+void c_mode(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL mode;
int max;
@@ -34,7 +34,7 @@
*result = mode;
}
-void w_mode(DCELL * result, DCELL(*values)[2], int n)
+void w_mode(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL mode;
DCELL max;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_percentile.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_percentile.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_percentile.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,9 +1,11 @@
#include <math.h>
+
#include <grass/gis.h>
#include <grass/stats.h>
-static void percentile(DCELL * result, DCELL * values, int n, double percent)
+void c_quant(DCELL * result, DCELL * values, int n, const void *closure)
{
+ double quant = *(const double *)closure;
double k;
int i0, i1;
@@ -14,7 +16,7 @@
return;
}
- k = n * percent / 100;
+ k = n * quant;
i0 = (int)floor(k);
i1 = (int)ceil(k);
@@ -23,24 +25,27 @@
: values[i0] * (i1 - k) + values[i1] * (k - i0);
}
-void c_quart1(DCELL * result, DCELL * values, int n)
+void c_quart1(DCELL * result, DCELL * values, int n, const void *closure)
{
- percentile(result, values, n, 25.0);
+ static const double q = 0.25;
+ c_quant(result, values, n, &q);
}
-void c_quart3(DCELL * result, DCELL * values, int n)
+void c_quart3(DCELL * result, DCELL * values, int n, const void *closure)
{
- percentile(result, values, n, 75.0);
+ static const double q = 0.75;
+ c_quant(result, values, n, &q);
}
-void c_perc90(DCELL * result, DCELL * values, int n)
+void c_perc90(DCELL * result, DCELL * values, int n, const void *closure)
{
- percentile(result, values, n, 90.0);
+ static const double q = 0.90;
+ c_quant(result, values, n, &q);
}
-static void percentile_w(DCELL * result, DCELL(*values)[2], int n,
- double percent)
+void w_quant(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
+ double quant = *(const double *)closure;
DCELL total;
int i;
DCELL k;
@@ -59,24 +64,27 @@
k = 0.0;
for (i = 0; i < n; i++) {
k += values[i][1];
- if (k >= total * percent / 100)
+ if (k >= total * quant)
break;
}
*result = values[i][0];
}
-void w_quart1(DCELL * result, DCELL(*values)[2], int n)
+void w_quart1(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
- percentile_w(result, values, n, 25.0);
+ static const double q = 0.25;
+ w_quant(result, values, n, &q);
}
-void w_quart3(DCELL * result, DCELL(*values)[2], int n)
+void w_quart3(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
- percentile_w(result, values, n, 75.0);
+ static const double q = 0.75;
+ w_quant(result, values, n, &q);
}
-void w_perc90(DCELL * result, DCELL(*values)[2], int n)
+void w_perc90(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
- percentile_w(result, values, n, 90.0);
+ static const double q = 0.90;
+ w_quant(result, values, n, &q);
}
Modified: grass/branches/releasebranch_6_4/lib/stats/c_range.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_range.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_range.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_range(DCELL * result, DCELL * values, int n)
+void c_range(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL min, max;
int i;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_reg.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_reg.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_reg.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -73,17 +73,17 @@
G_set_d_null_value(result, 1);
}
-void c_reg_m(DCELL * result, DCELL * values, int n)
+void c_reg_m(DCELL * result, DCELL * values, int n, const void *closure)
{
regression(result, values, n, REGRESSION_SLOPE);
}
-void c_reg_c(DCELL * result, DCELL * values, int n)
+void c_reg_c(DCELL * result, DCELL * values, int n, const void *closure)
{
regression(result, values, n, REGRESSION_OFFSET);
}
-void c_reg_r2(DCELL * result, DCELL * values, int n)
+void c_reg_r2(DCELL * result, DCELL * values, int n, const void *closure)
{
regression(result, values, n, REGRESSION_COEFF_DET);
}
@@ -157,17 +157,17 @@
G_set_d_null_value(result, 1);
}
-void w_reg_m(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_m(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
regression_w(result, values, n, REGRESSION_SLOPE);
}
-void w_reg_c(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_c(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
regression_w(result, values, n, REGRESSION_OFFSET);
}
-void w_reg_r2(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_r2(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
regression_w(result, values, n, REGRESSION_COEFF_DET);
}
Modified: grass/branches/releasebranch_6_4/lib/stats/c_skew.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_skew.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_skew.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,7 +1,7 @@
#include <math.h>
#include <grass/gis.h>
-void c_skew(DCELL * result, DCELL * values, int n)
+void c_skew(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL sum, ave, sumsq, sumcb, sdev;
int count;
@@ -43,7 +43,7 @@
*result = sumcb / (count * sdev * sdev * sdev);
}
-void w_skew(DCELL * result, DCELL(*values)[2], int n)
+void w_skew(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL sum, ave, sumsq, sumcb, sdev;
int count;
Modified: grass/branches/releasebranch_6_4/lib/stats/c_stddev.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_stddev.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_stddev.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -2,11 +2,11 @@
#include <grass/gis.h>
#include <grass/stats.h>
-void c_stddev(DCELL * result, DCELL * values, int n)
+void c_stddev(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL var;
- c_var(&var, values, n);
+ c_var(&var, values, n, closure);
if (G_is_d_null_value(&var))
G_set_d_null_value(result, 1);
@@ -14,11 +14,11 @@
*result = sqrt(var);
}
-void w_stddev(DCELL * result, DCELL(*values)[2], int n)
+void w_stddev(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL var;
- w_var(&var, values, n);
+ w_var(&var, values, n, closure);
if (G_is_d_null_value(&var))
G_set_d_null_value(result, 1);
Modified: grass/branches/releasebranch_6_4/lib/stats/c_sum.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_sum.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_sum.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_sum(DCELL * result, DCELL * values, int n)
+void c_sum(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL sum;
int count;
@@ -23,7 +23,7 @@
*result = sum;
}
-void w_sum(DCELL * result, DCELL(*values)[2], int n)
+void w_sum(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL sum;
DCELL count;
Added: grass/branches/releasebranch_6_4/lib/stats/c_thresh.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_thresh.c (rev 0)
+++ grass/branches/releasebranch_6_4/lib/stats/c_thresh.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -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/releasebranch_6_4/lib/stats/c_thresh.c
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: grass/branches/releasebranch_6_4/lib/stats/c_var.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/stats/c_var.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/lib/stats/c_var.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -1,6 +1,6 @@
#include <grass/gis.h>
-void c_var(DCELL * result, DCELL * values, int n)
+void c_var(DCELL * result, DCELL * values, int n, const void *closure)
{
DCELL sum, ave, sumsq;
int count;
@@ -39,7 +39,7 @@
*result = sumsq / count;
}
-void w_var(DCELL * result, DCELL(*values)[2], int n)
+void w_var(DCELL * result, DCELL(*values)[2], int n, const void *closure)
{
DCELL sum, ave, sumsq;
int count;
Modified: grass/branches/releasebranch_6_4/raster/r.neighbors/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.neighbors/main.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/raster/r.neighbors/main.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -302,9 +302,9 @@
G_set_d_null_value(rp, 1);
else {
if (newvalue_w)
- newvalue_w(rp, values_w, n);
+ newvalue_w(rp, values_w, n, NULL);
else
- newvalue(rp, values, n);
+ newvalue(rp, values, n, NULL);
if (half && !G_is_d_null_value(rp))
*rp += 0.5;
Modified: grass/branches/releasebranch_6_4/raster/r.resamp.stats/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.resamp.stats/main.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/raster/r.resamp.stats/main.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -38,7 +38,7 @@
{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, NULL, NULL, NULL}
};
static char *build_method_list(void)
@@ -141,7 +141,7 @@
if (null && nulls)
G_set_d_null_value(&outbuf[col], 1);
else
- (*method_fn) (&outbuf[col], values, n);
+ (*method_fn) (&outbuf[col], values, n, NULL);
}
G_set_window(&dst_w);
@@ -227,7 +227,7 @@
if (null && nulls)
G_set_d_null_value(&outbuf[col], 1);
else
- (*method_fn) (&outbuf[col], values, n);
+ (*method_fn) (&outbuf[col], values, n, NULL);
}
G_set_window(&dst_w);
Modified: grass/branches/releasebranch_6_4/raster/r.series/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.series/main.c 2010-09-20 17:03:02 UTC (rev 43539)
+++ grass/branches/releasebranch_6_4/raster/r.series/main.c 2010-09-20 17:04:26 UTC (rev 43540)
@@ -3,7 +3,7 @@
*
* MODULE: r.series
* AUTHOR(S): Glynn Clements <glynn gclements.plus.com> (original contributor)
- * Hamish Bowman <hamish_nospam yahoo.com>, Jachym Cepicky <jachym les-ejk.cz>,
+ * Hamish Bowman <hamish_b yahoo.com>, Jachym Cepicky <jachym les-ejk.cz>,
* Martin Wegmann <wegmann biozentrum.uni-wuerzburg.de>
* PURPOSE:
* COPYRIGHT: (C) 2002-2008 by the GRASS Development Team
@@ -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"},
@@ -47,6 +48,7 @@
{c_quart1, 0, "quart1", "first quartile"},
{c_quart3, 0, "quart3", "third quartile"},
{c_perc90, 0, "perc90", "ninetieth percentile"},
+ {c_quant, 0, "quantile", "arbitrary quantile"},
{c_skew, 0, "skewness", "skewness"},
{c_kurt, 0, "kurtosis", "kurtosis"},
{NULL, 0, NULL, NULL}
@@ -65,6 +67,8 @@
int fd;
DCELL *buf;
stat_func *method_fn;
+ double quantile;
+ double threshold;
};
static char *build_method_list(void)
@@ -104,7 +108,7 @@
struct GModule *module;
struct
{
- struct Option *input, *output, *method, *range;
+ struct Option *input, *output, *method, *quantile, *threshold, *range;
} parm;
struct
{
@@ -145,6 +149,21 @@
parm.method->description = _("Aggregate operation");
parm.method->multiple = YES;
+ 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->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';
@@ -218,6 +237,12 @@
out->name = output_name;
out->method_fn = menu[method].method;
+ 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);
@@ -264,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->method_fn)(&out->buf[col], values_tmp, num_inputs, &out->threshold);
}
}
}
More information about the grass-commit
mailing list