[GRASS-dev] r.mapcalc: using text labels as file names in equations

Hi,

I have to do computations on raster map combinations: one map contains the
month of interest as pixel value, a set of 12 monthly maps the related values.

My task is to find pixelwise the average temperature of the, say,
warmest month of
a year which's number is stored in the first map called "warmest_month"
along with a text label:
1 jan_tmean
2 feb_tmean
...

I would then need to use these text labels (alias map names) in a r.mapcalc
function which is already working for numerical labels (see pH values in
the manual, accessible with @mapname).

Suggestion: new "?" operator, to allow for this:

r.mapcalc "snow_zone = if(?warmest_month < 3.0, 1, null() )"

This would not read "warmest_month" (1...12) but "jan_tmean" etc instead
and use the label as map name to the numerical extract values from there.

Would it be possible to extend r.mapcalc in this direction?

Markus

Markus Neteler wrote:

I have to do computations on raster map combinations: one map contains the
month of interest as pixel value, a set of 12 monthly maps the related values.

My task is to find pixelwise the average temperature of the, say,
warmest month of
a year which's number is stored in the first map called "warmest_month"
along with a text label:
1 jan_tmean
2 feb_tmean
...

I would then need to use these text labels (alias map names) in a r.mapcalc
function which is already working for numerical labels (see pH values in
the manual, accessible with @mapname).

Suggestion: new "?" operator, to allow for this:

r.mapcalc "snow_zone = if(?warmest_month < 3.0, 1, null() )"

This would not read "warmest_month" (1...12) but "jan_tmean" etc instead
and use the label as map name to the numerical extract values from there.

Would it be possible to extend r.mapcalc in this direction?

r.mapcalc can't be expected to cover every possible use case by
itself, and this one is highly specialised (and far from trivial to
implement).

As thing stand, I suggest using:

  graph(warmest_month,1,jan_tmean,2,feb_tmean,3,mar_tmean,...)

This could be turned into a script, e.g. r.index, which selects a
value from a sequence of input maps based upon an index map, i.e.:

  r.index output=tmean index=warmest_month inputs=jan_tmean,feb_tmean,...

Generating the list of maps from category labels could be done by a
separate script, or r.index could have a flag for it.

OTOH, an index() function may be a worthwhile addition to r.mapcalc.
The graph() function is more general than is necessary here, and is
less efficient.

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