Skip to main content
1 reply [Last post]
annescharf
Offline
Joined: 06/07/2012

Hi Anne,

I've never used the KUD from adehabitatHR, but I just went through the example, and it seems that what the function does is that it calculates the average distance moved by the animal within 6h, and sets all pixels within this width on the other side of the barrier to 0.

So, you can do something similar (but without this 6h distance) by using a polygon, or a raster to mask you resulting dbbmm or ud. For example:

###-----####

library(move)
data(leroy)
## calculating dBBMM
leroy_p <- spTransform(leroy, CRSobj="+proj=aeqd +ellps=WGS84", center=TRUE)
dbbmm <- brownian.bridge.dyn(object=leroy_p, location.error=20, raster=100, ext=.45)
plot(dbbmm)
## calculating corresponding UD
ud <- getVolumeUD(dbbmm)
plot(ud, col=(terrain.colors(100)))


## creating polygon that will represent the area where the animal biologically cannot be found
polyg <- SpatialPolygons(list(Polygons(list(Polygon(matrix(c(c(-6749.8498, -3676.0562,  -525.4177,  1703.0827,  3163.1347,  6774.8423,  6736.4198, -6826.6946,-6749.8498), c(6259.439, 1341.369, -1309.778, -3115.632, -3538.279, -4844.641, -6688.917, -7265.253,6259.439)), byrow=F, ncol=2))),ID="water")),proj4string=CRS(projection(dbbmm)))
## creating a raster and  masking the raster with the polygon. The are of the polygon will contain NAs
maskRaster <- raster(dbbmm)
maskRaster[] <- 1
maskRaster <- mask(maskRaster,polyg, inverse=T)
plot(maskRaster)

## masking the dbbmm with a polygon or with a raster
dbbmmMsk <- mask(dbbmm, maskRaster)
plot(dbbmmMsk)

## to calculate the UD the raster of the dBBMM has to sum up to 1, but by setting a series of cells to NA, this is not anymore the case, and we have to normalize it
cellStats(dbbmmMsk, sum)
dbbmmMskN <- dbbmmMsk/(cellStats(dbbmmMsk, sum))
cellStats(dbbmmMskN, sum)
dbbmmMskud <- as(dbbmmMskN,".UD") # converting it to class .UD

udMsk <- getVolumeUD(dbbmmMskud)
plot(udMsk,col=terrain.colors(100))
contour(udMsk, levels=c(.5,.95), add=T)

## probably one could also just mask the UD. In most cases it probably does not make a big difference
udMsk2 <- mask(ud, maskRaster)
plot(udMsk2,col=terrain.colors(100))
contour(udMsk2, levels=c(.5,.95), add=T)

###-----####

Hope this helps.

Best,

Anne