<div dir="ltr">I have attached a patch to the ticket that fixes the problem. Anyone interested is welcome to test it.<div><br></div><div>regards, Etienne</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Dec 6, 2013 at 1:58 PM, Etienne B. Racine <span dir="ltr"><<a href="mailto:etiennebr@gmail.com" target="_blank">etiennebr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Etienne, I've added the relevant files. I think it's sufficient to debug the function, but if you think it might be helpful, I could add a larger raster and the results of the aggregation.<span class="HOEnZb"><font color="#888888"><br>
<br>
</font></span></div><span class="HOEnZb"><font color="#888888">Etienne<br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/6 Etienne Tourigny <span dir="ltr"><<a href="mailto:etourigny.dev@gmail.com" target="_blank">etourigny.dev@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Jan, can you please add your sample dataset and comments in that ticket?<span><font color="#888888"><div>
<br></div><div>Etienne</div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 3, 2013 at 6:37 PM, Etienne B. Racine <span dir="ltr"><<a href="mailto:etiennebr@gmail.com" target="_blank">etiennebr@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I added a ticket <a href="http://trac.osgeo.org/gdal/ticket/5311" target="_blank">http://trac.osgeo.org/gdal/ticket/5311</a><span><font color="#888888"><br>
<br></font></span></div><span><font color="#888888">Etienne<br></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/2 Etienne Tourigny <span dir="ltr"><<a href="mailto:etourigny.dev@gmail.com" target="_blank">etourigny.dev@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The "average" resampling mode of gdalwarp does "<span style="font-size:12px;font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif">average resampling, computes the average of all non-NODATA contributing pixels</span>". <div>
<br></div><div>It was meant to compute the average of all the pixels in the "<span style="font-family:arial,sans-serif;font-size:13px">aggregation window</span>". However, it may have issues in the corners.</div>
<div><br></div><div>I am the author of the average and mode algorithms, and I basically copied the aggregation logic from the other algorithms (i.e. which pixels are selected for the aggregation), so there may be something wrong in the logic.</div>
<div><br></div><div>Certainly, looking at this simple example shows that something is wrong. </div><div><br></div><div>I tested average and mode resampling with a fairly large dataset and did not find these problems.</div>
<div><br></div><div>Can you create a new bug in the tracker and upload the scripts and data used? I don't have much (any) time to work on this but would be happy to apply a working patch.</div><div><br></div><div>Cheers, Etienne</div>
</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 2, 2013 at 12:22 PM, Etienne B. Racine <span dir="ltr"><<a href="mailto:etiennebr@gmail.com" target="_blank">etiennebr@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I've tried to dig this a bit. I couldn't understand the logic behind gdal aggregation (or downsampling). I've simplified your example using a smaller raster and deterministic values. Maybe someone could enlighten us by looking at the aggregation values ? Note that the lower right cells values were identical in all dimensions I've tried (about 4 - 10).<br>
<br>The example is run on GDAL 1.11dev, released 2013/04/13<br></div><div><br></div><div>Thanks,<br></div>Etienne<br><div><br># in R:<div><br>require(raster)<br>filei <- '10by10.tif'<br>fileo <- '5by5.tif'<br>
<br></div>dm = 4<br>r <- raster(matrix(1:(dm^2), dm, dm))<div><br><br>writeRaster(r, filename=filei, overwrite = TRUE)<br><br>## aggregate using R aggregate function using the mean<br>r1 <- aggregate(r, fact=2, fun = mean, na.rm = TRUE)<br>
<br></div>file.remove(fileo)<br>cmd <- paste("gdalwarp -r average -tr", paste(res(r1), collapse = " "), filei, fileo)<br>system(cmd)<br>r2 <- raster(fileo)<br><br>>as.matrix(r)<br> [,1] [,2] [,3] [,4]<br>
[1,] 1 5 9 13<br>[2,] 2 6 10 14<br>[3,] 3 7 11 15<br>[4,] 4 8 12 16<br>> lapply(list(r1, r2, r2-r1), as.matrix)<br>[[1]]<br> [,1] [,2]<br>[1,] 3.5 11.5<br>[2,] 5.5 13.5<br>
<br>[[2]]<br> [,1] [,2]<br>[1,] 6.0 12.0<br>[2,] 7.5 13.5<br><br>[[3]]<br> [,1] [,2]<br>[1,] 2.5 0.5<br>[2,] 2.0 0.0<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/27 Verbesselt, Jan <span dir="ltr"><<a href="mailto:jan.verbesselt@wur.nl" target="_blank">jan.verbesselt@wur.nl</a>></span><div>
<div><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I have been testing gdalwarp to aggregate (using -r average) an image.<br>
In order to better understand what is happening I have created a<br>
reproducible example within an R environment and compared it with the<br>
aggregate function of the R raster package (see below). There are some<br>
differences between the gdalwarp raster (r2) and the aggregated raster<br>
(r1).<br>
<br>
How is the gdalwarp -r average working? Which pixels are selected for<br>
averaging (e.g.the corner pixels, center pixels, or all within the<br>
aggregation window)?<br>
<br>
If there is a gdal aggregate option to average pixels comparable to the<br>
aggregate function in the R raster package, it would be great as that<br>
would potentially faster, and you could also reproject and aggregate at<br>
once.<br>
<br>
Thanks!<br>
Jan<br>
<br>
<a href="http://bfast.r-forge.r-project.org" target="_blank">http://bfast.r-forge.r-project.org</a><br>
<a href="http://goo.gl/1mBC5F" target="_blank">http://goo.gl/1mBC5F</a><br>
<br>
<br>
## R script<br>
require(raster)<br>
filei <- '10by10.tif'<br>
fileo <- '5by5.tif'<br>
<br>
set.seed(123)<br>
r <- raster(ncols=36, nrows=18)<br>
r <- setValues(r, round(runif(ncell(r))*10))<br>
r<br>
plot(r)<br>
writeRaster(r, filename=filei, overwrite = TRUE)<br>
<br>
## aggregate using R aggregate function using the mean<br>
r1 <- aggregate(r, fact=2, fun = mean, na.rm = TRUE)<br>
<br>
cmd <- paste("gdalwarp -r average -tr 20 20 -te -180 -90 180 90 ",<br>
filei, " ", fileo, sep = "")<br>
system(cmd)<br>
r2 <- raster(fileo)<br>
<br>
## compare<br>
plot(r1)<br>
plot(r2)<br>
r1<br>
r2<br>
getValues(r1)<br>
getValues(r2)<br>
<br>
##<br>
plot(r1-r2)<br>
sessionInfo()<br>
<br>
R> sessionInfo()<br>
R version 3.0.1 (2013-05-16)<br>
Platform: x86_64-pc-linux-gnu (64-bit)<br>
<br>
locale:<br>
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C<br>
LC_COLLATE=C LC_MONETARY=C<br>
[6] LC_MESSAGES=C LC_PAPER=C LC_NAME=C<br>
LC_ADDRESS=C LC_TELEPHONE=C<br>
[11] LC_MEASUREMENT=C LC_IDENTIFICATION=C<br>
<br>
attached base packages:<br>
[1] stats graphics grDevices utils datasets methods base<br>
<br>
other attached packages:<br>
[1] rgdal_0.8-10 raster_2.1-49 sp_1.0-11<br>
<br>
loaded via a namespace (and not attached):<br>
[1] grid_3.0.1 lattice_0.20-23 tools_3.0.1<br>
<br>
<br>
rgdal: version: 0.8-10, (SVN revision 478)<br>
Geospatial Data Abstraction Library extensions to R successfully loaded<br>
Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24<br>
Path to GDAL shared files: /usr/share/gdal/1.10<br>
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]<br>
Path to PROJ.4 shared files: (autodetected)<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div></div></div><br></div>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>