complex coastline and adehabitatHR: trouble with kerneloverlaphr function after coastline has been clipped out

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

complex coastline and adehabitatHR: trouble with kerneloverlaphr function after coastline has been clipped out

Elizabeth Hartel
Hi all,

I am using R version 2.14.2 on a Windows 7 machine and adehabitatHR version 0.4.2.  

I have an extensive database of dolphin locations and would like to look at home range overlap between animals.  My study area has a complex coastline and does not work with the "boundary" slot in the kernelUD function.  I was able to clip out the land using the method devised by Tony Fischback and Clement Calenge in the following post http://r-sig-geo.2731867.n2.nabble.com/Walruses-and-adehabitatHR-class-estUDm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals-td6497315.html.

The above method requires coversion of the kernelUD output (of class-estUDm) into a SpatialPixelsDataFrame.  Once the land is clipped out, I successfully converted the object back into class-estUDm.  However, when I try to run the kerneloverlaphr function with the converted file, I get 0 for every overlap (which should not be the case).  Kerneloverlaphr works fine if I run it using the kernelUDs before the land is clipped out, but not after.  I have no idea why it's not working properly, but it must have something to do with the process of clipping out the land.

Any advice on the matter would be greatly appreciated.  I have included an example of my code using the data(puechabonsp) that comes with the adehabitatHR package.


# Load data
 data(puechabonsp)

# Store relocations
 loc <- puechabonsp$relocs

# Store map
 elev <- puechabonsp$map

# Build "fake" habitat map (1= habitat, 0 = non habitat)
 fullgrid(elev) <- TRUE
 hab <- elev
 hab[[1]] <- as.numeric(!is.na(hab[[1]]))

# Convert hab back into SpatialPixelsDataFrame (as needed for kernelUD function)
 hab <- as(hab, "SpatialPixelsDataFrame")

# Estimate UD
 ud <- kernelUD(loc[,1], grid=hab)

# Convert to SpatialPixelsDataFrame
 udspdf <- estUDm2spixdf(ud)

# Convert resulting file to fullgrid
 fullgrid(udspdf) <- TRUE

# Convert habitat map to fullgrid
 fullgrid(hab)<-TRUE

# Multiply each column of udspdf by the habitat variable
 resu <- lapply(1:ncol(udspdf), function(i) {udspdf[[i]] * hab[[1]] / sum(udspdf[[i]] * hab[[1]])})
 resu <- as.data.frame(resu)
 names(resu) <- names(udspdf@data)

# Define it as a data slot for udspdf
 udspdf@data <- resu

# Convert to SpatialPixelsDataFrame
 fullgrid(udspdf) <- FALSE

# Convert result back into class estUDm
 re <- lapply(1:ncol(udspdf), function(i) {
      so <- new("estUD", udspdf[,i])
      so@h <- list(h=0, meth="specified") # fake value
      so@vol <- FALSE
      return(so)
      })

 names(re) <- names(udspdf)
 class(re) <- "estUDm"

# Find kernel overlap
 kov_clipped <- kerneloverlaphr(re, method = "PHR", percent = 95, conditional = FALSE)

# Result is all zeros (copied directly from R window)
> kov_clipped
      Brock Calou Chou Jean
Brock     0     0    0    0
Calou     0     0    0    0
Chou      0     0    0    0
Jean      0     0    0    0

# Run kernel overlap for non-clipped UDs (to test accuracy of the above)
 kov_nonclipped <- kerneloverlaphr(ud, method = "PHR", percent = 95, conditional = FALSE)

# Result is not all zeros (copied directly from R window)
> kov_nonclipped
           Brock     Calou      Chou       Jean
Brock 0.94933028 0.7198043 0.0000000 0.02139490
Calou 0.30917730 0.9495502 0.0000000 0.02949861
Chou  0.00000000 0.0000000 0.9496367 0.89242679
Jean  0.04359732 0.3086748 0.9122472 0.94957049



Thanks so much for your time and assistance!

Liz



-----------
Liz Hartel
Biological Scientist
Population Biology and Behavioral Ecology
Harbor Branch Oceanographic Institute - FAU
5600 US 1 North, Fort Pierce, FL 34946
work: (772) 242-2238
cell: (772) 216-4363
www.hboi.fau.edu
Reply | Threaded
Open this post in threaded view
|

Re: complex coastline and adehabitatHR: trouble with kerneloverlaphr function after coastline has been clipped out

Phil H
Hi,

I am also running into an identical problem- kerneloverlaphr does not seem to work with my clipped UD...I also get all zeros using the PHR method and all NaNs using the HR method.

I am really happy with the way the clipping method has worked for my data- this forum has been super helpful!

did anyone ever find a solution?

Thanks for your time!

Phil H

Reply | Threaded
Open this post in threaded view
|

Re: complex coastline and adehabitatHR: trouble with kerneloverlaphr function after coastline has been clipped out

Phil H
I notice that the kernal.area function does not seem to work with this clipped UD.

I suspect that it could be related to the "fake" h values provided by the code

fullgrid(udspdf) <- FALSE
re <- lapply(1:ncol(udspdf), function(i) {
so <- new("estUD", udspdf[,i])
so@h <- list(h=0, meth="specified") # fake value
so@vol <- FALSE
return(so)
})

as these seem to be the only differences I can find in the between the clipped and non-clipped data str
see below for an example...........


str(re)
List of 4
 $ Brock:Formal class 'estUD' [package "adehabitatHR"] with 9 slots
  .. ..@ h          :List of 2
  .. .. ..$ h   : num 0
  .. .. ..$ meth: chr "specified"

str(ud)
List of 4
 $ Brock:Formal class 'estUD' [package "adehabitatHR"] with 9 slots
  .. ..@ h          :List of 2
  .. .. ..$ h   : num 212
  .. .. ..$ meth: chr "href"


I am attempting to use the BRB approach following the walrus thread script http://grokbase.com/t/r/r-sig-geo/116mj7w0wx/walruses-and-adehabitathr-class-estudm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals

however I get just the same issues. where BRBUDnotclipped<- is UD created in the BRB above (not clipped)
str(BRBUDnotclipped)
$ Brock: :Formal class 'estUD' [package "adehabitatHR"] with 9 slots
  .. ..@ h          :List of 3
  .. .. ..$ values:List of 2
  .. .. .. ..$ hmin: num 100
  .. .. .. ..$ D   :List of 4
  .. .. .. .. ..$ Brock: num 4.26
  .. .. .. .. ..$ Calou: num 1
  .. .. .. .. ..$ Chou : num 1.86
  .. .. .. .. ..$ Jean : num 6.21
  .. .. ..$ interp:'data.frame':        62 obs. of  3 variables:
  .. .. .. ..$ x: num [1:62] 699889 699968 700046 699644 699242 ...
  .. .. .. ..$ y: num [1:62] 3161559 3161550 3161541 3161372 3161202 ...
  .. .. .. ..$ h: num [1:62] 100 612 100 704 704 ...

and where the BRB clipped UD structure again looks like this

str(UDclipped)
List of 4
 $ Brock:Formal class 'estUD' [package "adehabitatHR"] with 9 slots
  .. ..@ h          :List of 2
  .. .. ..$ h   : num 0
  .. .. ..$ meth: chr "specified"


My idea so far has been to try and re-populate the h slot with my BRB.lik values ie vv2
so far I have tried  

fullgrid(udspdf) <- FALSE
re <- lapply(1:ncol(udspdf), function(i) {
so <- new("estUD", udspdf[,i])
so@h <- list(hmin=100,D=vv2, meth="BRB-specified")
so@vol <- FALSE
return(so)
})

however I dont know how to work with the $interp slot and I cannot seem to extract the D value only from the vv2 of class "DBRB". And to be honest I am not really sure I am correctly addressing the root of the problem? Does anyone have any ideas why this approach doesnt work and why clipped UDs do not work with kerneloverlap? Could it be related to the getvolumeUD function which is used in both the kerneloverlaphr function and also in the kernel.area function?
sorry to repost on the same topic with no further enlightenment. I guess I could try exporting the UD to GIS and clipping it and returning it to adehabitatHR however I imagine this approach would also be tricky and I am not a huge fan of arcGIS and would much prefer to crack this in R!

Surely it is not impossible to generate overlap indexes with clipped datasets? Perhaps I am making some very rookie mistake?

Thanks for your time

Phil H