Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
Hi, This looks to be exactly the solution i am looking for- I am analysing some telemetry data in a reservoir which is too complex to meet the boundary rules. However I am having a little trouble with the example codeits probably something I have done but. library(adehabitatHR) data(puechabonsp) loc - puechabonsp$relocs elev - puechabonsp$map fullgrid(elev) - TRUE hab - elev hab[[1]] - as.numeric(!is.na(hab[[1]])) #everything works good up till here ud - kernelUD(loc[,1], grid=hab) #when i get to this point I get the following error message error in .kernelUDs(SpatialPoints(x, proj4string = CRS(as.character(pfs1))), : grid should be a number or an object inheriting the class SpatialPixels #i notice that when I run class(hab) [1] SpatialGridDataFrame attr(,package) [1] sp #it appears to be a class SpatialGridDataFrame. and the grid function needs to be of the class SpatialPixels #so I tried hab-SpatialPixels(hab) however this doesnt seem to work i get the error hab2-SpatialPixels(hab) Error in SpatialPixels(hab) : points should be of class or extending SpatialPoints I am a bit of a beginner using sp and adehabitathr packages so i expect it is something silly however I just cant seem to recetify this Thanks for your time Phil H -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Walruses-and-adehabitatHR-class-estUDm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals-tp6497315p7582454.html Sent from the R-sig-geo mailing list archive at Nabble.com. ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
Hi Phil, You should be able to use the following to covert it into a SpatialPixelsDataFrame: hab - as(hab, SpatialPixelsDataFrame) Good luck! Liz Phil H wrote Hi, This looks to be exactly the solution i am looking for- I am analysing some telemetry data in a reservoir which is too complex to meet the boundary rules. However I am having a little trouble with the example codeits probably something I have done but. library(adehabitatHR) data(puechabonsp) loc - puechabonsp$relocs elev - puechabonsp$map fullgrid(elev) - TRUE hab - elev hab[[1]] - as.numeric(!is.na(hab[[1]])) #everything works good up till here ud - kernelUD(loc[,1], grid=hab) #when i get to this point I get the following error message error in .kernelUDs(SpatialPoints(x, proj4string = CRS(as.character(pfs1))), : grid should be a number or an object inheriting the class SpatialPixels #i notice that when I run class(hab) [1] SpatialGridDataFrame attr(,package) [1] sp #it appears to be a class SpatialGridDataFrame. and the grid function needs to be of the class SpatialPixels #so I tried hab-SpatialPixels(hab) however this doesnt seem to work i get the error hab2-SpatialPixels(hab) Error in SpatialPixels(hab) : points should be of class or extending SpatialPoints I am a bit of a beginner using sp and adehabitathr packages so i expect it is something silly however I just cant seem to recetify this Thanks for your time Phil H -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Walruses-and-adehabitatHR-class-estUDm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals-tp6497315p7582460.html Sent from the R-sig-geo mailing list archive at Nabble.com. ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
Dear Antony, You are right, there is indeed a problem with the object estUDm returned by the function BRB. As you rightly noted, each estUD object has a full listing of the D values from all animals (which does not impair the use of other functions, but indeed need to be corrected), and the estUD objects are not named (which does impair the use of this object in other functions, e.g. getverticeshr). For the last bug, as you noted, an easy workaround consists in manually defining these names (I will correct this bug ASAP). Many thanks for reporting. Now, concerning your clipping problem. ## Note that Brock and Calou, the UD have sharp limits ###ASF### Yes I see this. This is because the extent of the grid is to small, compared with the size of the UD (or maybe your smoothing parameters are too large). In your example, the map contained in puechabonsp is too small and does not encompass all possible locations where the animals may have moved, given the diffusion and smoothing parameters that you defined. Another map, larger, would therefore be required. Note that if your aim is just to calculate home range contours, you do not need to use this map: you should define another grid with a larger extent, and then (see the parameters grid and extent on the help page of BRB). If your aim is to measure the use intensity in each pixel of the habitat map, then you do not need home ranges limits. ###ASF### [2011 August 05]: Questions for ClementCalenge: ###ASF### How can we extract home-range contours now that the home range estimates are of class SpatialPixelsDataFrame? The class estUDm is simply a list of objects of class estUD. And an object of class estUD is simply a SpatialPixelsDataFrame with additional slots h (a list of two specifying how h is computed) and vol. Therefore, the following should work, using your objects: 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) }) names(re) - names(udspdf) class(re) - estUDm image(re) ## and find the contours ver - getverticeshr(re, standardize=TRUE) plot(ver) HTH, Clément Calenge -- Clément CALENGE Cellule d'appui à l'analyse de données Direction des Etudes et de la Recherche Office national de la chasse et de la faune sauvage Saint Benoist - 78610 Auffargis tel. (33) 01.30.46.54.14 ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
Wonderful! I am so grateful to all that make this forum so rewarding. Here is an example plot with walrus foraging behavior tracking data (each red point is a daily walrus location, the kernel is weighted by daily hours spent foraging, 50th and 95th percentiles contour polygons are plotted as well as the coastline.) http://r-sig-geo.2731867.n2.nabble.com/file/n6777535/BRB06_All.png This method clearly defines the centers of foraging activity as well as diffuse utilization regions. - Tony Fischbach, Wildlife Biologist Walrus Research Program Alaska Science Center U.S. Geological Survey 4210 University Drive Anchorage, AK 99508-4650 afischb...@usgs.gov http://alaska.usgs.gov/science/biology/walrus -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Walruses-and-adehabitatHR-class-estUDm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals-tp6497315p6777535.html Sent from the R-sig-geo mailing list archive at Nabble.com. ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
Anthony, your script fails for me at the following point: ver - getverticeshr(ud, percent=95, standardize = TRUE, whi = id(ltraj)) Error in getverticeshr.default(x[[i]], percent, ida = names(x)[i], unin, : no method provided for this class In general, it is easier for someone on the list to answer your question if you send a minimal script that reproduces the problem -- I'm not sure the 134 lines were all needed. If you want to construct objects of a certain class at the low level, using the slot() function, you should first fully understand how the objects are organized. Documentation is sparse (as source code is there), but class?SpatialPixelsDataFrame will help you as a start. A likely cause may be that you assume y increases when you go along the pixels in the @data slot (as image() assumes the first row is the most South-bound row), but this is not the case for the sp grid classes. On 09/08/2011 09:53 PM, Anthony Fischbach wrote: I have worked from the script that you provided in your previous posting to address the question, Is there a means to convert the SpatialPixelDataFrame back into an estUDm? My modifications to your script are noted by my initials, ***ASF**. I have extended your script to work with an estUDm created by the BRB function. In delving into the estUDm object I noticed two odd things. 1) estUD objects within the estUDm do not have names assigned when they are created by the BRB function. 2) each estUD object within the estUDm has a full listing of the D values from all animals listed in the estUDm. I was able to clip the estUD's using the habitat grid. By use of the slot() function I was able to placed the 'clipped' utilization distribution in the form of a spatial pixel data frame back into the estUDm class object. However, the resultant estUDm raster appears to have the y coordinates reversed. The modified script is listed below. ## Load the data library(adehabitatHR) library(adehabitatLT) data(puechabonsp) ## Store the relocations loc - puechabonsp$relocs ## and the map elev - puechabonsp$map ## have a look at the data head(as.data.frame(loc)) ## the first column of this data frame is the ID ## Look at the map image(elev) ## Now we build a fake habitat map (1 = habitat and 0 = non habitat) from the elevation map fullgrid(elev) - TRUE hab - elev hab[[1]] - as.numeric(!is.na(hab[[1]])) ## show this habitat map (yellow is habitat) image(hab) ## Estimation of UD for the four animals, using ## the map hab as the grid ud - kernelUD(loc[,1], grid=hab) ###ASF### ###ASF### try with BRB ###ASF### first make ltraj object ###ASF### Cast the Dates as POSIXct dates loc$DT -as.POSIXct(strptime(loc$Date, format='%y%m%d' )) ###ASF### Create an ltraj trajectory object. ltraj - as.ltraj(coordinates(loc), loc$DT, id = loc$Name, burst = loc$Name, typeII = TRUE) ###ASF### Assigne parameter values for BRB ###ASF### Parameters for the Biased Random Bridge Kernel approach tmax - 5*(24*60*60) + 1 ## set the maximum time between locations to be just more than 5 day lmin - 0.1 ## locations less than 0.1 meters apart are considered inactive. ## Set very very low to ensure that the acvitivy variable is used. hMin - 100 ## arbitrarily set to be same as hab grid cell resolution vv2- BRB.likD(ltraj, Dr=c(1,5), Tmax = tmax, Lmin = lmin, habitat = NULL) ## ud -BRB(ltraj, D =vv2, Tmax =tmax, Lmin = lmin, hmin = hMin, habitat = NULL, grid = hab, b = TRUE, extent = 0, tau = 24*60*60 ) ## ud is an object of the class estUDm ## get volumetric contours ver - getverticeshr(ud, percent=95, standardize = TRUE, whi = id(ltraj)) ###ASF### !! PROBLEM !! # str(ud) # List of 4 # $ :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 # ... further str(ud) results omitted ###ASF### 2 Problems apparent here: ###ASF### 1) no names have been assigned to the items in the ud list; ###ASF### 2) the list of D values has been inflated such that a full listing of D values is given under each animal, rather than just one for each animal ###ASF### address names in ud by assigning them to be the same as the ids in ltraj names(ud) - id(ltraj) ## Convert it to SpatialPixelsDataFrame: udspdf - estUDm2spixdf(ud) ## udspdf is an object of class SpatialPixelsDataFrame ## have a look mimage(udspdf) ## Convert the original map to fullgrid (i.e. SpatialGridDataFrame) fullgrid(udspdf) - TRUE ## and the same for the original habitat map (here, it is not needed, ## as the map hab is already fullgrid, but it might be required on you data) fullgrid(hab)-TRUE ##
Re: [R-sig-Geo] placing spdf back into adehabiatHR estUDm
The failure with the line in my posted script is due to the lack of names in the estUDm object. It runs if you first run *names* function then the *getverticeshr* function -- highlighting the bug in the BRB function and in my posted script. names(ud) - id(ltraj) ver - getverticeshr(ud, percent=95, standardize = TRUE, whi = id(ltraj)) Edzer Pebesma-2 wrote: Anthony, your script fails for me at the following point: ver - getverticeshr(ud, percent=95, standardize = TRUE, whi = id(ltraj)) Error in getverticeshr.default(x[[i]], percent, ida = names(x)[i], unin, : no method provided for this class - Tony Fischbach, Wildlife Biologist Walrus Research Program Alaska Science Center U.S. Geological Survey 4210 University Drive Anchorage, AK 99508-4650 afischb...@usgs.gov http://alaska.usgs.gov/science/biology/walrus -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Walruses-and-adehabitatHR-class-estUDm-exclusion-of-non-habitat-pixels-and-summary-over-all-animals-tp6497315p6773846.html Sent from the R-sig-geo mailing list archive at Nabble.com. ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo