[GRASS-SVN] r58431 - grass-addons/grass7/raster/r.gdd

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 10 00:07:00 PST 2013


Author: mmetz
Date: 2013-12-10 00:06:59 -0800 (Tue, 10 Dec 2013)
New Revision: 58431

Modified:
   grass-addons/grass7/raster/r.gdd/main.c
   grass-addons/grass7/raster/r.gdd/r.gdd.html
Log:
r.gdd: more user-friendly index selection

Modified: grass-addons/grass7/raster/r.gdd/main.c
===================================================================
--- grass-addons/grass7/raster/r.gdd/main.c	2013-12-09 20:57:25 UTC (rev 58430)
+++ grass-addons/grass7/raster/r.gdd/main.c	2013-12-10 08:06:59 UTC (rev 58431)
@@ -22,6 +22,11 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
+#define IDX_GDD 1
+#define IDX_WINKLER 2
+#define IDX_BEDD 3
+#define IDX_HUGLIN 4
+
 struct input
 {
     const char *name;
@@ -41,14 +46,15 @@
     struct GModule *module;
     struct
     {
-	struct Option *input, *add, *file, *output, *range,
+	struct Option *input, *add, *file, *output, *index, *range,
 	              *scale, *shift, *baseline, *cutoff;
     } parm;
     struct
     {
-	struct Flag *nulls, *lazy, *avg, *huglin;
+	struct Flag *nulls, *lazy, *avg;
     } flag;
-    int i;
+    char *desc = NULL;
+    int idx, i;
     int num_inputs, max_inputs, add_in;
     struct input *inputs = NULL;
     struct output *out = NULL;
@@ -85,6 +91,22 @@
     parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
     parm.output->multiple = NO;
 
+    parm.index = G_define_option();
+    parm.index->key = "index";
+    parm.index->type = TYPE_STRING;
+    parm.index->multiple = NO;
+    parm.index->required = NO;
+    parm.index->options = "gdd,winkler,bedd,huglin";
+    parm.index->answer = "gdd";
+    parm.index->label = "Index to calculate";
+    G_asprintf(&desc,
+	       "gdd;%s;winkler;%s;bedd;%s;huglin;%s",
+	       _("Growing Degree Days"),
+	       _("Winkler index"),
+	       _("Biologically Effective Degree Days"),
+	       _("Huglin Heliothermal index"));
+    parm.index->descriptions = desc;
+
     parm.scale = G_define_option();
     parm.scale->key = "scale";
     parm.scale->type = TYPE_DOUBLE;
@@ -121,12 +143,8 @@
 
     flag.avg = G_define_flag();
     flag.avg->key = 'a';
-    flag.avg->description = _("Use average instead of min, max");
+    flag.avg->description = _("Use average instead of (min + max) / 2");
 
-    flag.huglin = G_define_flag();
-    flag.huglin->key = 'h';
-    flag.huglin->description = _("Calculate Huglin index");
-
     flag.nulls = G_define_flag();
     flag.nulls->key = 'n';
     flag.nulls->description = _("Propagate NULLs");
@@ -158,6 +176,19 @@
     baseline = atof(parm.baseline->answer);
     cutoff = atof(parm.cutoff->answer);
     
+    idx = 0;
+    if (strcmp(parm.index->answer, "gdd") == 0)
+	idx = IDX_GDD;
+    else if (strcmp(parm.index->answer, "winkler") == 0)
+	idx = IDX_WINKLER;
+    else if (strcmp(parm.index->answer, "bedd") == 0)
+	idx = IDX_BEDD;
+    else if (strcmp(parm.index->answer, "huglin") == 0)
+	idx = IDX_HUGLIN;
+    else
+        G_fatal_error(_("Unknown index '%s' for option %s"),
+	              parm.index->answer, parm.index->key);
+    
     if (cutoff <= baseline)
         G_fatal_error(_("'%s' must be > '%s'"), parm.cutoff->key,
 	                                        parm.baseline->key);
@@ -303,6 +334,8 @@
 			null = 1;
 		    }
 		    else {
+			if (idx != IDX_BEDD && v > cutoff)
+			    v = cutoff;
 			avg += v;
 			if (Rast_is_f_null_value(&min) || min > v)
 			    min = v;
@@ -328,12 +361,12 @@
 		    avg = (min + max) / 2.;
 		}
 
-		if (flag.huglin->answer)
+		if (idx == IDX_HUGLIN)
 		    avg = (avg + max) / 2.;
 
 		if (avg < baseline)
 		    avg = baseline;
-		if (avg > cutoff)
+		if (idx == IDX_BEDD && avg > cutoff)
 		    avg = cutoff;
 
 		result = avg - baseline;

Modified: grass-addons/grass7/raster/r.gdd/r.gdd.html
===================================================================
--- grass-addons/grass7/raster/r.gdd/r.gdd.html	2013-12-09 20:57:25 UTC (rev 58430)
+++ grass-addons/grass7/raster/r.gdd/r.gdd.html	2013-12-10 08:06:59 UTC (rev 58431)
@@ -5,41 +5,53 @@
 indices from several input maps with temperature data for different 
 times of the day.
 <p>
-The formula for calculating GDDs is
+<b>GDDs</b> are calculated as
 <div class="code"><pre>
-    average = (max + min) / 2
     gdd = average - baseline
 </pre></div>
-The formula for calculating the Winkler index is
+<p>
+The <b>Winkler index</b> is calculated as
 <div class="code"><pre>
-    average = sum(inputs) / num_inputs
     wi = average - baseline
 </pre></div>
-The formula for calculating the Huglin heliothermal index is
+usually accumulated for the period April 1<sup>st</sup> to October 
+31<sup>st</sup> (northern hemisphere) or the period October 
+1<sup>st</sup> to April 30<sup>th</sup> 
+(southern hemisphere).
+<p>
+<b>BEDDs</b> are calculated as
 <div class="code"><pre>
-    average = (max + min) / 2
+    wi = average - baseline
+</pre></div>
+with an optional upper <em>cutoff</em> applied to the average instead of 
+the temperature values.
+<p>
+The <b>Huglin heliothermal index</b> is calculated as
+<div class="code"><pre>
     hi = (average + max) / 2 - baseline
 </pre></div>
-with <em>min</em> being the minimum daily temperature, <em>max</em> 
-the maximum daily temperature and <em>average</em> the average daily 
-temperature. The <em>min</em>, <em>max</em> and <em>average</em> values 
+usually accumulated for the period April 1<sup>st</sup> to September 
+30<sup>th</sup> (northern hemisphere) or the period September 
+1<sup>st</sup> to April 30<sup>th</sup> (southern hemisphere).
+<p>
+With the <em>-a</em> flag, the average is calculated as the average of 
+all available temperature values, otherwiese the average is calculated as
+<i>(min + max) / 2</i>.
+The <em>min</em>, <em>max</em> and <em>average</em> values 
 are automatically calculated from the input temperature maps.
 <p>
-Any <em>average</em> temperature values above the <em>cutoff</em> value 
-are set to <em>cutoff</em>, and any <em>average</em> values below the 
-<em>baseline</em> value are set to <em>baseline</em>. Negative results 
+Any temperature values (for BEDD, any averages) above the <em>cutoff</em> 
+value are set to <em>cutoff</em>, and any <em>average</em> values below 
+the <em>baseline</em> value are set to <em>baseline</em>. Negative results 
 are set to 0 (zero). 
 <p>
-The <em>cutoff</em> value is useful to calculate Biologically Effective 
-Degree Days (BEDD), assuming that development kinetics reach a plateau 
-at the cutfoff value.
-<p>
 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 map is provided with the <em>gdd</em> option, the 
-values of this map are added to the output, thus accumulating GDDs.
+If an existing map is provided with the <em>add</em> option, the 
+values of this map are added to the output, thus accumulating the 
+selected index.
 
 <h2>NOTES</h2>
 
@@ -51,10 +63,10 @@
 <p>
 With the <em>-n</em> flag, any cell for which any of the 
 corresponding input cells are NULL is automatically set to NULL 
-(NULL propagation) and the GDD value is not calculated.
+(NULL propagation) and the index is not calculated.
 <p>
 Without the <em>-n</em> flag, all non-NULL cells are used to 
-calculate the current GDD.
+calculate the selected index.
 <p>
 If the <em>range=</em> option is given, any values which fall outside 
 that range will be treated as if they were NULL. Note that the range is 
@@ -91,8 +103,7 @@
 opened and closed. The amount of RAM will rise linear with the 
 number of specified input maps. The input and file options are 
 mutually exclusive. Input is a text file with a new line separated 
-list of raster map names and optional weights. As separator between 
-the map name and the weight the charachter | must be used.
+list of raster map names.
 
 <h2>EXAMPLES</h2>
 



More information about the grass-commit mailing list