[GRASS-user] 2 r.neighbors questions

Hermann Peifer peifer at gmx.eu
Thu Oct 29 05:50:44 EDT 2009


Glynn,

Thanks for the confirmation about how to get to rounded weighted sums.

As far as I can see: r.resamp.stats (which, in a way, also generates 
neighborhood statistics) simply produces DCELL output rasters, no matter 
what the input cell type or aggregation method is. At least the sum of 
integer values results into float values. r.neighbors could perhaps do 
the same.

A small enhancement for r.neighbors would be to add "weighted sum", etc. 
to the auto-title, where appropriate.

And before I forget: should someone perhaps remove this phrase ("for 
method=sum, the sum of the weights should be 1") from 
http://grass.itc.it/grass64/manuals/html64_user/r.neighbors.html

Thanks, Hermann




Glynn Clements wrote:
> Hermann Peifer wrote:
> 
>> I started using r.neighbors and came across the following issues:
>>
>> I have a CELL type input raster and calculate weighted sums. The
>> weights are float, so the calculation result should be float, but
>> r.neighbors output raster is again CELL type with truncated integers.
> 
> r.neighbors output is always of the same type as the input. This
> should probably be changed to use DCELL when weight= is used. It
> should also be changed for average, median, stddev, and variance in
> 7.0, but 6.x (without weight=) needs to maintain the existing
> behaviour for compatibility.
> 
>> How do I get to rounded integers? Do I see this right: that I have to
>> change the input raster to float type (multiply with 1.0?). This will
>> trigger float type values in r.neighbors' output raster, which I could
>> eventually round() to integer. Is this the best way to do it, or am I
>> overlooking a convenient switch or something?
> 
> As you suggest, you need to use r.mapcalc float(), r.neighbors,
> r.mapcalc round().
> 
>> Another question is what exactly is the reason behind the
>> recommendation in r.neighbors documentation:
>>
>>> for method=sum, the sum of the weights should be 1
> 
> That's incorrect. If the sum of the weights is 1, the result will be
> identical to method=average. method=sum gives sum(cell[i]*weight[i])
> while method=average gives sum(cell[i]*weight[i])/sum(weight[i]).
> 
> If you are using the weights= option simply to define a custom window
> shape, using a weight of 1 for cells inside the window and zero for
> outside (possibly with intermediate values on the boundary) will give
> results which are consistent with the built-in rectangular and
> circular windows.
> 



More information about the grass-user mailing list