[GRASS-SVN] r52061 - grass-addons/grass7/raster/r.gdd
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 13 09:29:54 PDT 2012
Author: mmetz
Date: 2012-06-13 09:29:53 -0700 (Wed, 13 Jun 2012)
New Revision: 52061
Modified:
grass-addons/grass7/raster/r.gdd/main.c
grass-addons/grass7/raster/r.gdd/r.gdd.html
Log:
r.gdd: fix Winkler index
Modified: grass-addons/grass7/raster/r.gdd/main.c
===================================================================
--- grass-addons/grass7/raster/r.gdd/main.c 2012-06-13 14:18:16 UTC (rev 52060)
+++ grass-addons/grass7/raster/r.gdd/main.c 2012-06-13 16:29:53 UTC (rev 52061)
@@ -153,6 +153,10 @@
baseline = atof(parm.baseline->answer);
cutoff = atof(parm.cutoff->answer);
+
+ if (cutoff <= baseline)
+ G_fatal_error(_("'%s' must be > '%s'"), parm.cutoff->key,
+ parm.baseline->key);
if (parm.input->answer && parm.file->answer)
G_fatal_error(_("input= and file= are mutually exclusive"));
@@ -278,11 +282,11 @@
for (col = 0; col < ncols; col++) {
int null = 0, non_null = 0;
- FCELL min, max, sum, gdd;
+ FCELL min, max, avg, gdd;
min = fnull;
max = fnull;
- sum = 0;
+ avg = 0;
for (i = 0; i < num_inputs; i++) {
FCELL v = inputs[i].buf[col];
@@ -295,13 +299,8 @@
null = 1;
}
else {
- if (v < baseline)
- v = baseline;
- if (v > cutoff)
- v = cutoff;
-
if (flag.avg->answer)
- sum += v;
+ avg += v;
else {
if (Rast_is_f_null_value(&min) || min > v)
min = v;
@@ -321,10 +320,28 @@
}
else {
- if (flag.avg->answer)
- gdd = sum / non_null - baseline;
- else
+ if (flag.avg->answer) {
+ avg /= non_null;
+
+ if (avg < baseline)
+ avg = baseline;
+ if (avg > cutoff)
+ avg = cutoff;
+
+ gdd = avg - baseline;
+ }
+ else {
+ if (min < baseline)
+ min = baseline;
+ if (min > cutoff)
+ min = cutoff;
+ if (max < baseline)
+ max = baseline;
+ if (max > cutoff)
+ max = cutoff;
+
gdd = (min + max) / 2. - baseline;
+ }
if (gdd < 0.)
gdd = 0.;
Modified: grass-addons/grass7/raster/r.gdd/r.gdd.html
===================================================================
--- grass-addons/grass7/raster/r.gdd/r.gdd.html 2012-06-13 14:18:16 UTC (rev 52060)
+++ grass-addons/grass7/raster/r.gdd/r.gdd.html 2012-06-13 16:29:53 UTC (rev 52061)
@@ -1,13 +1,14 @@
<h2>DESCRIPTION</h2>
-<em>r.gdd</em> calculates (accumulated) growing degree days (GDDs) from
-several input maps with temperature data for different times of the day.
+<em>r.gdd</em> calculates (accumulated) growing degree days (GDDs) and
+Winkler indices from several input maps with temperature data for
+different times of the day.
<p>
The formula for calculating GDDs is
<div class="code"><pre>
gdd = (max + min) / 2 - baseline
</pre></div>
-or using the average from all input maps
+The formula for calculating the Winkler index is
<div class="code"><pre>
gdd = average - baseline
</pre></div>
@@ -16,13 +17,18 @@
temperature. The <em>min</em>, <em>max</em> and <em>average</em> values
are automatically calculated from the input temperature maps.
<p>
-Negative GDD values are set to 0 (zero). All (scaled and shifted)
-temperature values above the <em>cutoff</em> value are set to
-<em>cutoff</em>, and all (scaled and shifted) temperature values below
-the <em>baseline</em> value are set to <em>baseline</em>.
+The <em>shift</em> and <em>scale</em> values are applied directly to the
+input values. The <em>baseline</em>, <em>cutoff</em>, and <em>range</em>
+options are applied to the shifted and scaled values.
<p>
-If an existing GDD map is provided with the <em>gdd</em> option, the
-values of this GDD map are added to the output, thus accumulating GDDs.
+Any <em>min</em>, <em>max</em> and <em>average</em> temperature values
+above the <em>cutoff</em> value are set to <em>cutoff</em>, and any
+<em>min</em>, <em>max</em> and <em>average</em> values below the
+<em>baseline</em> value are set to <em>baseline</em>. Negative results
+are set to 0 (zero).
+<p>
+If an existing map is provided with the <em>gdd</em> option, the
+values of this map are added to the output, thus accumulating GDDs.
<h2>NOTES</h2>
More information about the grass-commit
mailing list