An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101010/37a0ddef/attachment.pl>
Question concerning calc() function in raster
2 messages · Rainer M Krug, Robert J. Hijmans
Hi Rainer, 1) .calcLayers is only used for functions that operate on a matrix; not in other cases. Perhaps calc does not work correctly in some cases (for some functions), and to investigate that it would be useful to know what you are trying to accomplish. 2) yes that was wrong and now fixed. Thanks! Best, Robert
On Sun, Oct 10, 2010 at 11:43 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:
Hi
I have two questions concerning the function calc() (more accurately
.calcLayers()) (I append the code of the function below) :
1) The value given to the function fun() is a matrix, containig the values
for many calls from all layers - this is not clear from the help page, and
probably should be changed as it complicates the development of fun()
functions. It effectively assumes, that the function fun() does vectorize
the input parameter, which is in most cases when more complicated
calculations are done, not the case (at least not for me). I would suggest
to put it up to discussion, if this behaviour should be changed.
2) Is the (!canProcessInMemory(x, 2)) correct? I would actually assume, that
the processing in one piece is only done, when canProcessInMemory() is
TRUE?
Cheers and thanks a lot for this really hice package (I am back and using it
again),
Rainer
.calcLayers <- function(x, fun, filename='', ...) {
filename <- trim(filename)
outraster <- brick(x, values=FALSE)
if (!canProcessInMemory(x, 2)) {
v <- t( fun( t( getValues(x) )) )
if (filename != '') {
outraster <- writeRaster(outraster)
}
return( setValues(outraster, v) )
}
if ( filename == '') {
filename <- rasterTmpFile()
}
outraster <- writeStart(outraster, filename=filename, ...)
tr <- blockSize(outraster)
pb <- pbCreate(tr$n, type=.progress(...))
for (i in 1:tr$n) {
sv <- t( fun( t( getValues(x, row=tr$row[i], nrows=tr$nrows[i]) )) )
outraster <- writeValues(outraster, sv, tr$row[i])
pbStep(pb)
}
outraster <- writeStop(outraster)
pbClose(pb)
return(outraster)
}
--
NEW GERMAN FAX NUMBER!!!
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
Cell:? ? ? ? ?? +27 - (0)83 9479 042
Fax:? ? ? ? ? ? +27 - (0)86 516 2782
Fax:? ? ? ? ? ? +49 - (0)321 2125 2244
email:? ? ? ? ? Rainer at krugs.de
Skype:? ? ? ? ? RMkrug
Google:? ? ? ?? R.M.Krug at gmail.com