Skip to content

Extracting avg values from smoothed surface in spatstat

2 messages · Graham Smith, Marcelino de la Cruz

#
Hi,

Probably there is a simpler way, but in the 
meantime, you can use this experimental function 
"gridim" (of course you can modify as you want).

You have to especify the required "lag" of the 
grid (i.e. the desired length of the x-side or 
the y-side of each cell in the grid).
It gives you a list of images of the required 
size. Then use mean.im to obtain thte mean values.


Example of use:

library(spatstat)

data(longleaf)
Z <- smooth.ppp(longleaf)

plot(Z)

lapply(gridim(Z, xlag=10), mean.im)



Regards,

Marcelino








##### FUNCTION "gridim"#################################################

gridim <-  function (miim,xlag,ylag=xlag){

    xrange <- miim$xrange
    yrange <- miim$yrange

    x0 <- xrange[1]
    y0 <- yrange[1]

    maxx <- round(diff(xrange)/xlag)
    maxy <- round(diff(yrange)/ylag)

    result <- NULL
    z <- 0
    for (i in 1:maxx){
       for (j in 1:maxy){
         z <- z+1
         result[z] <- 
list(miim[owin(c((x0+xlag)*(i-1), 
(x0+xlag)*i),c((y0+ylag)*(j-1), (y0+ylag)*j))])
       }
    }

    class(result) <- c("gridedim", class(result))
    return(result)
}

###################################################################################3
At 13:26 25/04/2008, Graham Smith wrote:
________________________________

Marcelino de la Cruz Rot

Departamento de  Biolog?a Vegetal
E.U.T.I. Agr?cola
Universidad Polit?cnica de Madrid
28040-Madrid
Tel.: 91 336 54 35
Fax: 91 336 56 56
marcelino.delacruz at upm.es