How to create an estUDm object from utilization distributions created with GIS?

220 Views Asked by At

I created kernel densities/utilization distributions for multiple animals in ArcGIS Pro instead of using the adehabitatHR package in R because I needed a different smoothing parameter estimator and I had a difficult boundary to work with.

Now I have several individual raster files of these UDs and I want to calculate overlap using the UDOI method. This would be much more efficient using the adehabitatHR package, but I'm having trouble converting these rasters into a single estUDm object to use with the kerneloverlaphr function. I apologize, I am not sure how to provide the rasters to create reproducible data, but my code is below.

I appreciate any help with this error message that I'm receiving when running kerneloverlaphr: "Error in if (slot(x[[1]], "vol")) stop("x should not be a volume under UD") : argument is of length zero"

library(raster)
library(adehabitatHR)

#Import kernel density rasters created in ArcGIS Pro
UD1 <- raster("UD1.tif")
UD2 <- raster("UD2.tif")

#Convert to spatial pixels data frame
UD1.px <- as(UD1, "SpatialPixelsDataFrame")
UD2.px <- as(UD2, "SpatialPixelsDataFrame")

#Convert to estUD
UD1.estUD <- new("estUD", UD1.px)
UD2.estUD <- new("estUD", UD2.px)

#Combine both estUD's and convert to estUDm for overlap analysis
UD.combined <- list(animal1=UD1.estUD, animal2=UD2.estUD)
class(UD.combined) <- "estUDm"

#Check individual UD's
plot(UD.combined$animal1) #shows correct UD
plot(UD.combined$animal2) #shows correct UD

kerneloverlaphr(UD.combined, method=c("UDOI")) #Received error message: Error in if (slot(x[[1]], "vol")) stop("x should not be a volume under UD") :   argument is of length zero
1

There are 1 best solutions below

0
Ben On

I think you will need to specify values for the slots of an object of class estUD. The creator of the package has provided an example that I found on this mailing list.

https://www.mail-archive.com/[email protected]/msg00455.html

Here's an example for your problem of calculating overlap. We can simulate loading in external rasters by just creating them from a SpatialPointsDataFrame provided from adehabitatHR.

library(raster)
library(adehabitatHR)
library(sp)

#example data
data(puechabonsp)
dat <- puechabonsp$relocs
dat$Name <- as.character(dat$Name)

#calculate a UD and create example raster (e.g., from GIS)
ud <- kernelUD(dat[ ,'Name'], same4all = TRUE)

r <- estUDm2spixdf(ud)
r <- stack(r)

#convert rasters to spdf
UD1.px <- as(r[[1]], "SpatialPixelsDataFrame")
UD2.px <- as(r[[2]], "SpatialPixelsDataFrame")

#define parameters and slots for estUD
fullgrid(UD1.px) <- FALSE
fullgrid(UD2.px) <- FALSE

hli <- list(h = 1, meth="specified")

UD1.estUD <- new("estUD", UD1.px)
slot(UD1.estUD, "h") <- hli
slot(UD1.estUD, "vol") <- FALSE

UD2.estUD <- new("estUD", UD2.px)
slot(UD2.estUD, "h") <- hli
slot(UD2.estUD, "vol") <- FALSE

#Combine estUDs and convert to estUDm
UD.combined <- list(animal1=UD1.estUD, animal2=UD2.estUD)
class(UD.combined) <- "estUDm"

#Check individual UDs
plot(UD.combined$animal1) #shows correct UD
plot(UD.combined$animal2) #shows correct UD

kerneloverlaphr(UD.combined, method="UDOI")