[GRASS-user] r.mapcalc and the neighborhood modifier

Hi

I would like to create a new raster layer, based on the neighborhood
modifier, but where the offset is not constant, but the cell value in a
different map.

Reasoning: I am modeling seed dispersal into neighboring cells and the
direction is based on the aspect. I created the aspect in agnps format
("flowdir") and I created two layers (flowdir_dx and flowdir_dy) indicating the x and y offset
based on flowdir.

Now when simulating the flow, I want to use:

,----
| r.mapcalc expression="test = seeds[flowdir_dy, flowdir_dx]" --overwrite
`----

but I get the following error:
,----
| syntax error, unexpected NAME, expecting INTEGER or '-'
| Parse error
| ERROR: parse error
`----

I assume from that error message, that I can not supply a map go get the
values for the neighborhood modifier, but have to use constant values.

I could put these into if statements, but I wanted to avoid these if
possible.

Is there a way that I can use the offset from a map?

Cheers,

Rainer

--
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

Rainer M Krug wrote:

I assume from that error message, that I can not supply a map go get the
values for the neighborhood modifier, but have to use constant values.

Correct.

The main reason is that, like most GRASS raster modules, r.mapcalc
works row-by-row. For each input map, it records the minimum and
maximum row offset used in neighbourhood modifiers; it does this
before any maps are opened.

In theory, there's no reason why the column offset can't be an
arbitrary expression (or an index instead of an offset), but that
isn't currently supported.

Given how r.mapcalc works, it should be fairly simple to add a
function to allow unrestricted column indexing, e.g.
column(data, index) where both data and index are arbitrary
expressions.

Allowing the row offset to be an arbitrary expression would be
somewhat harder to implement (or to implement efficiently, at least),
as r.mapcalc would need to be able to fetch rows on-demand based upon
the results of calculations, and to know when each row was no longer
needed.

A more restricted form, where the row offset is simply the value taken
from a map would be more straightforward, as the code which determines
the range of offsets could examine the range of the map used for the
row offset. However, this would run the risk of feature creep, i.e. a
demand for extending the offset map to map+offset up to arbitrary
expressions involving maps and constants.

An alternative option would be to allow arbitrary expressions but with
explicit constant bounds.

However, while these options are viable, neither is exactly trivial.

I could put these into if statements, but I wanted to avoid these if
possible.

Is there a way that I can use the offset from a map?

If the range of possible offsets is small (e.g. {-1,0,+1}), I'd go
with "if" statements.

Otherwise, you might want to look into using one of the Python APIs (I
think we have four now: grass.script, grass.script.array, grass.lib
and grass.pygrass).

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

Hi Rainer,

I came across this email and was wondering if you found a solution for this problem?

Cheers,

Paulo

···

On Tue, Jul 16, 2013 at 12:50 PM, Rainer M Krug <Rainer@krugs.de> wrote:

Hi

I would like to create a new raster layer, based on the neighborhood
modifier, but where the offset is not constant, but the cell value in a
different map.

Reasoning: I am modeling seed dispersal into neighboring cells and the
direction is based on the aspect. I created the aspect in agnps format
(“flowdir”) and I created two layers (flowdir_dx and flowdir_dy) indicating the x and y offset
based on flowdir.

Now when simulating the flow, I want to use:

,----
| r.mapcalc expression=“test = seeds[flowdir_dy, flowdir_dx]” --overwrite
`----

but I get the following error:
,----
| syntax error, unexpected NAME, expecting INTEGER or ‘-’
| Parse error
| ERROR: parse error
`----

I assume from that error message, that I can not supply a map go get the
values for the neighborhood modifier, but have to use constant values.

I could put these into if statements, but I wanted to avoid these if
possible.

Is there a way that I can use the offset from a map?

Cheers,

Rainer


Rainer M. Krug

email: RMKruggmailcom


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user