[GRASS-dev] Re: r.series: threshold/count method?

Glynn Clements glynn at gclements.plus.com
Mon Sep 7 17:49:14 EDT 2009


Markus Neteler wrote:

> I have an extra issue: For the particular growing degree day calculation
> I am facing the problem that the values I am comparing with a FP values
> and that GRASS_EPSILON is useless in this particular case. It works
> only with
> 
>  /* EPSILON = GRASS_EPSILON; */
>   EPSILON = 10.
>   if (fabs(tval - values[i]) < EPSILON ) {
> 
> because the pixel values are growing so quickly from one map to the
> next. Since we need a generic solution, another "precision" or whatever
> parameter needs to be passed otherwise the thresholding fails completely.
> EPSILON however depends on the input maps and needs to be user
> controllable.
> 
> How to deal with that?

What exactly are you trying to measure?

>From your original post, it sounds like you have a monotonically
increasing input, and you want the time (index) at which the value
first exceeds the threshold, e.g.:

	for (i = 0; i < n; i++) {
	    if (values[i] >= threshold) {
	        *result = (DCELL) i;
	        return;
	    }
	}
	Rast_set_d_null_value(result, 1);

If you need an approximate equality comparison, the usual solution is
to use the ratio of the difference to one of the values, e.g.:

	double EPSILON = 1e-6; /* 1 ppm */
	if (fabs(values[i] - threshold) < EPSILON * threshold)
		...

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list