[GRASSLIST:5838] Re: create new map of TS with min value month
Glynn Clements
glynn at gclements.plus.com
Thu Feb 17 20:55:16 EST 2005
Martin Wegmann wrote:
> I have a time series and I want to create a map containing the information
> which decade has the annual minimum value.
>
> e.g.:
>
> values for one pixel
>
> jan 1 = 10
> jan 2 = 11
> jan 3 = 18
> feb 1 = 9
> feb 2 = 3
> feb 3 = 5
> .....
>
> output = 22 or 5 (either 2= feb ; 2=2. decade OR 5th decade)
>
> The ouput map would hold the information for each pixel which decade has the
> annual minimum value.
> however before I start writing a script with a if condition for each decade
> map I would like to know if somebody knows a more straight forward method.
Add it to r.series, i.e.:
1. Copy c_min.c to e.g. c_minx.c.
2. Change the copy to return the x value instead of the y (see below).
3. Search for all occurrences of c_min in the files in the r.series
directory and add equivalents for c_minx.
4. Repeat for c_max while you're at it.
5. Re-compile.
It's likely to be simpler than writing a script.
Sample (untested) c_minx implementation:
void c_minx(DCELL *result, DCELL *values, int n)
{
DCELL min, minx;
int i;
G_set_d_null_value(&min, 1);
G_set_d_null_value(&minx, 1);
for (i = 0; i < n; i++)
{
if (G_is_d_null_value(&values[i]))
continue;
if (G_is_d_null_value(&min) || min > values[i])
{
min = values[i];
minx = i;
}
}
if (G_is_d_null_value(&minx))
G_set_d_null_value(result, 1);
else
*result = minx;
}
Note: you're stuck with DCELL; r.series only generates DCELL maps. Use
r.mapcalc afterwards if you really need CELL.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list