## Feature #276

### grdblend should operation on complete grids instead of rows

Status: | New | Start date: | 2013-05-15 | |
---|---|---|---|---|

Priority: | Low | Due date: | ||

Assignee: | - | % Done: | 0% | |

Category: | - | |||

Target version: | - | |||

Platform: |

**Description**

This is a low-priority task. Currently grdblend processes grids by row. There was a discussion to change this to processing entire grids with some concerns about memory consumption. However, I believe we don't have to store more than three grids at the same time because a weighted mean can be calculated cumulatively. Here is a short awk example about what I mean:

for ((i=1;i<5;i++)); do echo $i; done | gawk '{sum=sum+$1; mean=(mean*(NR-1)+$1)/NR} END {print sum, NR, sum/NR, mean}'So there are two possibilities:

- For each blend iteration keep a grid of weighted cumulative sums and the sum of weights. Each iteration loads a new grid (including grdsample), and updates the two aforementioned grids. In the last step you divide one by the other.
- As 1. but each time divide the cumulative sums by the sum of all weights so that you permanently update a cumulative weighted mean instead (I believe blockmean does this).

The drawback of 1 is that you need more memory and get possible overflows with the sums. The 2nd has the advantage that it needs to store only the grid of the cumulative mean and the current grid.