[prev in list] [next in list] [prev in thread] [next in thread] 

List:       grass-dev
Subject:    [GRASS-dev] Re: r.series: threshold/count method?
From:       Markus Neteler <neteler () osgeo ! org>
Date:       2009-08-30 19:05:03
Message-ID: 86782b610908301205p3a327840w9d2bd7c80aae972a () mail ! gmail ! com
[Download RAW message or body]

On Fri, Aug 28, 2009 at 10:47 PM, Markus Neteler<neteler@osgeo.org> wrote:
> Hi,
>
> it would be ideal to have a new threshold/count method in r.series.
> Example: I am calculating growing degree days (accumulated temperatures
> over one year, [1]) and want to know at which day of year (count) this
> happens. Input would be 365 growing degree days maps, parameters
> a threshold value (e.g. 440 for insect moulting) and the result a
> count value per pixel which corresponds to the map number which
> I gave as input (which is the day of year DOY in this case).
>
> Would that be hard to implement? A bit of rounding/epsilon will be
> involved to match the requested threshold since the input maps
> are typically FP maps.
>
> I can imagine more use cases: first frost day in autumn (theshold -0.1=B0=
C
> or so), input daily minimum temperature maps and more...
>
> Markus
>
> [1] http://en.wikipedia.org/wiki/Growing_degree_day

Attached an attempt for review.
My problem is how to pass the threshold value into the function
(currently hardcoded sample value).

Markus

["c_thresh.c" (text/x-c)]

#include <grass/gis.h>
#include <math.h>

void c_thresh(DCELL * result, DCELL * values, int n)
{
    DCELL thresh, threshx;
    double tval = 6;
    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);
	if (fabs(tval - values[i]) < GRASS_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;
}


["thresh.diff" (text/x-diff)]

Index: include/stats.h
===================================================================
--- include/stats.h	(revision 38835)
+++ include/stats.h	(working copy)
@@ -28,6 +28,7 @@
 extern stat_func c_quart3;
 extern stat_func c_perc90;
 extern stat_func c_skew;
+extern stat_func c_thresh;
 extern stat_func c_kurt;
 
 extern stat_func_w w_ave;
Index: raster/r.series/main.c
===================================================================
--- raster/r.series/main.c	(revision 38835)
+++ raster/r.series/main.c	(working copy)
@@ -41,6 +41,7 @@
     {c_sum,    0, "sum",        "sum of values"},
     {c_var,    0, "variance",   "statistical variance"},
     {c_divr,   1, "diversity",  "number of different values"},
+    {c_thresh, 1, "threshold",  "threshold value"},
     {c_reg_m,  0, "slope",      "linear regression slope"},
     {c_reg_c,  0, "offset",     "linear regression offset"},
     {c_reg_r2, 0, "detcoeff",   "linear regression coefficient of determination"},


_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic