[GRASS-SVN] r71070 - grass-addons/grass7/raster/r.seasons
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue May 9 00:23:27 PDT 2017
Author: mmetz
Date: 2017-05-09 00:23:27 -0700 (Tue, 09 May 2017)
New Revision: 71070
Modified:
grass-addons/grass7/raster/r.seasons/main.c
grass-addons/grass7/raster/r.seasons/r.seasons.html
Log:
r.seasons: add option to use a raster map with per-cell threshold values (#3301)
Modified: grass-addons/grass7/raster/r.seasons/main.c
===================================================================
--- grass-addons/grass7/raster/r.seasons/main.c 2017-05-09 05:41:00 UTC (rev 71069)
+++ grass-addons/grass7/raster/r.seasons/main.c 2017-05-09 07:23:27 UTC (rev 71070)
@@ -177,7 +177,8 @@
*ts, /* time steps*/
*ns, /* number of seasons */
*nsout, /* output map for number of seasons */
- *threshold, /* threshold to start/stop a season */
+ *tval, /* constant threshold to start/stop a season */
+ *tmap, /* map with threshold values to start/stop a season */
*min, /* minimum length in time to recognize a season */
*max; /* maximum length in time to separate two seasons */
} parm;
@@ -188,6 +189,7 @@
int i;
int num_inputs;
struct input *inputs = NULL;
+ struct input tin;
int num_outputs;
struct output *outputs = NULL;
int nsout_fd;
@@ -248,12 +250,17 @@
parm.nsout->required = NO;
parm.nsout->description = _("Name of output map with detected number of seasons");
- parm.threshold = G_define_option();
- parm.threshold->key = "threshold";
- parm.threshold->type = TYPE_DOUBLE;
- parm.threshold->required = YES;
- parm.threshold->description = _("Threshold to start/stop a season");
+ parm.tval = G_define_option();
+ parm.tval->key = "tval";
+ parm.tval->type = TYPE_DOUBLE;
+ parm.tval->required = NO;
+ parm.tval->description = _("Constant threshold to start/stop a season");
+ parm.tmap = G_define_standard_option(G_OPT_R_INPUT);
+ parm.tmap->key = "tmap";
+ parm.tmap->required = NO;
+ parm.tmap->description = _("Constant threshold to start/stop a season");
+
parm.min = G_define_option();
parm.min->key = "min_length";
parm.min->type = TYPE_DOUBLE;
@@ -305,8 +312,22 @@
G_fatal_error(_("Maximum gap length must be positive"));
}
- threshold = atof(parm.threshold->answer);
+ if (parm.tmap->answer) {
+ tin.name = G_store(parm.tmap->answer);
+ tin.fd = Rast_open_old(tin.name, "");
+ tin.buf = Rast_allocate_d_buf();
+ }
+ else {
+ if (!parm.tval->answer)
+ G_fatal_error(_("No threshold, please provide either <%s> or <%s>"),
+ parm.tval->key, parm.tmap->key);
+ threshold = atof(parm.tval->answer);
+ tin.name = NULL;
+ tin.fd = -1;
+ tin.buf = NULL;
+ }
+
if (flag.lo->answer)
cmp_dbl = cmp_dbl_lo;
else
@@ -347,8 +368,9 @@
p->name = G_store(name);
G_verbose_message(_("Reading raster map <%s>..."), p->name);
p->buf = Rast_allocate_d_buf();
- if (!flag.lazy->answer)
- p->fd = Rast_open_old(p->name, "");
+ p->fd = Rast_open_old(p->name, "");
+ if (flag.lazy->answer)
+ Rast_close(p->fd);
}
if (num_inputs < 1)
@@ -372,9 +394,10 @@
p->name = parm.input->answers[i];
G_verbose_message(_("Reading raster map <%s>..."), p->name);
p->buf = Rast_allocate_d_buf();
- if (!flag.lazy->answer)
- p->fd = Rast_open_old(p->name, "");
- }
+ p->fd = Rast_open_old(p->name, "");
+ if (flag.lazy->answer)
+ Rast_close(p->fd);
+ }
}
if (num_inputs < 3)
G_fatal_error(_("At least 3 input maps are required"));
@@ -470,8 +493,14 @@
Rast_get_d_row(inputs[i].fd, inputs[i].buf, row);
}
+ if (tin.buf)
+ Rast_get_d_row(tin.fd, tin.buf, row);
+
for (col = 0; col < ncols; col++) {
+ if (tin.buf)
+ threshold = tin.buf[col];
+
n_nulls = 0;
for (i = 0; i < num_inputs; i++) {
DCELL v = inputs[i].buf[col];
@@ -539,6 +568,8 @@
for (i = 0; i < num_inputs; i++)
Rast_close(inputs[i].fd);
}
+ if (tin.fd >= 0)
+ Rast_close(tin.fd);
/* close output maps */
for (i = 0; i < num_outputs; i++) {
Modified: grass-addons/grass7/raster/r.seasons/r.seasons.html
===================================================================
--- grass-addons/grass7/raster/r.seasons/r.seasons.html 2017-05-09 05:41:00 UTC (rev 71069)
+++ grass-addons/grass7/raster/r.seasons/r.seasons.html 2017-05-09 07:23:27 UTC (rev 71070)
@@ -2,8 +2,10 @@
<em>r.seasons</em> counts the number of seasons in a time series. A
season is defined as a time period of at least <em>min_length</em>
-length where no value is below <em>threshold</em> (with the <em>-l</em>
-flag, no value above <em>threshold</em>).
+length where no value is below threshold (with the <em>-l</em>
+flag, no value above threshold). As threshold, a fixed value can be
+specified with the <em>tval</em> option, or a raster map with per-cell
+threshold values can be supplied with the <em>tmap</em> option.
<p>
The <em>nout</em> output holds the number of detected seasons. Output
@@ -98,7 +100,7 @@
<div class="code"><pre>
r.seasons input=`g.list rast pat=MOD13* sep=,` prefix=ndvi_season n=3 \
- nout=ndvi_season threshold=3000 min_length=6
+ nout=ndvi_season tval=3000 min_length=6
# the outputs are:
g.list type=raster pattern=ndvi_season*
More information about the grass-commit
mailing list