Skip to content

Commit

Permalink
version 1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Calenge authored and gaborcsardi committed Dec 14, 2007
1 parent 34b6e5d commit 97d0de3
Show file tree
Hide file tree
Showing 14 changed files with 564 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CONTENTS
Expand Up @@ -353,6 +353,12 @@ Keywords: spatial
Description: Estimation of kernel home-range
URL: ../../../library/adehabitat/html/kernelUD.html

Entry: kerneloverlap
Aliases: kerneloverlap
Keywords: spatial
Description: Spatial Interaction between Animals Monitored Using Radio-Tracking
URL: ../../../library/adehabitat/html/kerneloverlap.html

Entry: kselect
Aliases: kselect, kplot.kselect, hist.kselect, print.kselect
Keywords: multivariate
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: adehabitat
Version: 1.7
Date: 2007/08/29
Version: 1.7.1
Date: 2007/12/14
Title: Analysis of habitat selection by animals
Author: Clement Calenge, contributions from Mathieu Basille, Stephane Dray and Scott Fortmann-Roe
Maintainer: Clement Calenge <calenge@biomserv.univ-lyon1.fr>
Expand All @@ -9,4 +9,4 @@ Suggests: gpclib, sp, spatstat, MASS, tkrplot, shapefiles, CircStats
Description: A collection of tools for the analysis of habitat selection by animals
Encoding: latin1
License: GPL version 2 or newer
Packaged: Wed Aug 29 12:35:56 2007; calenge
Packaged: Fri Dec 14 17:31:10 2007; calenge
5 changes: 5 additions & 0 deletions INDEX
Expand Up @@ -3,6 +3,7 @@ adehabitat-package adehabitat: a Package for the Analysis of the
albatross Argos Monitoring of Adult Albatross Movement
altr Attach or Detach Bursts in Objects of Class
'ltraj' to Search Path
angles Compute Turning Angles - Deprecated
area2asc Converts a Polygon to Raster
area2dxf Exportation of Areas
as.area Objects of Class "area"
Expand Down Expand Up @@ -86,6 +87,8 @@ join.asc Finds the Value of Mapped Variables at some
kasc2df Conversion of Objects of Class kasc
kasc2spixdf Conversion of maps from/to the package "sp"
kernelbb Estimation of Kernel Brownian Bridge Home-Range
kerneloverlap Spatial Interaction between Animals Monitored
Using Radio-Tracking
kernelUD Estimation of Kernel Home-Range
kselect K-Select Analysis: a Method to Analyse the
Habitat Selection by Animals
Expand Down Expand Up @@ -161,6 +164,8 @@ simm.mou Simulation of a Bivariate Ornstein-Uhlenbeck
Process
sliwinltr Apply a Function on an Object of Class "ltraj",
Using a Sliding Window
speed Computes the Speed Between Successive
Relocations of an Animal - Deprecated
squirrel Radio-Tracking Data of Squirrels
squirreloc Radio-tracking of squirrels
storemapattr Store Attributes of Maps of Class asc and kasc
Expand Down
100 changes: 100 additions & 0 deletions R/angles.r
@@ -0,0 +1,100 @@
"angles" <- function (x, id = levels(x$id), burst = levels(x$burst),
date = NULL, slsp = c("remove", "missing"))
{
## The function is deprecated
.Deprecated("as.ltraj")

## Verifications
if (!inherits(x, "traj"))
stop("x should be of class \"traj\"")
slsp <- match.arg(slsp)


## prepangles is used to remove successive relocations
## located at the same place
prepangles <- function(x)
{
## Verifications
if (!inherits(x, "traj"))
stop("x should be of class \"traj\"")

## split per burst
li <- split(x, x$burst)

## keeps only the successive relocations at different places
foo <- function(y) {
oo <- unlist(lapply(2:nrow(y),
function(i)
(!all(y[i,c("x","y")]==y[i-1,c("x","y")]))))
oo <- c(TRUE,oo)
y <- y[oo,]
}

## output
res <- do.call("rbind", lapply(li, foo))
return(res)
}

## gets the selected bursts
x <- getburst(x, burst = burst, id = id, date = date)

## if the angles are to be removed when successive relocations are
## on the same place
if (slsp=="remove")
x <- prepangles(x)

## split per burst
li <- split(x, x$burst)

## To compute the angles
foo <- function(x) {

## gets the coordinates
xy<-as.matrix(x[,c("x","y")])
ang<-1:(nrow(xy)-2)


for (i in 2:(nrow(xy)-1)) {

## current relocation, with the previous one
na <- 0
ref1<-xy[i-1,]

## the origin of the space is placed on the previous reloc
xyb1<-t(t(xy)-ref1)
ang1<--atan2(xyb1[i,2],xyb1[i,1])

## Position of rotated x2 and x3
x2<-c(sqrt(sum(xyb1[i,]^2)), 0)
if (sum(abs(x2)) < 1e-7)
na<-1
x3b<-x3<-xyb1[i+1,]
x3b[1]= cos(ang1)*x3[1] - sin(ang1)*x3[2]
x3b[2]= sin(ang1)*x3[1] + cos(ang1)*x3[2]
x3<-x3b

## Computation of the angles
x3<-x3-x2
if (sum(abs(x3)) < 1e-7)
na<-1
ang[i-1]<-atan2(x3[2],x3[1])
if (na > 0.5)
if (slsp == "missing")
ang[i - 1] <- NA
}

## output
so<-data.frame(id=x$id[-c(1,nrow(xy))],
x=xy[-c(1,nrow(xy)),1],
y=xy[-c(1,nrow(xy)),2],
date=x$date[-c(1,nrow(xy))],
burst=x$burst[-c(1,nrow(xy))],
angles=ang)
}

## output
lo <- do.call("rbind", lapply(li, foo))
row.names(lo) <- 1:nrow(lo)
return(lo)
}

131 changes: 131 additions & 0 deletions R/kerneloverlap.R
@@ -0,0 +1,131 @@
kerneloverlap <- function(xy, id = NULL,
method = c("HR", "PHR", "VI", "BA", "UDOI", "HD"),
lev=95, conditional=FALSE, ...)
{
## Verifications
method <- match.arg(method)

## UD estimation
x <- kernelUD(xy, id, same4all=TRUE, ...)
vol <- getvolumeUD(x)

## Matrix of results
res <- matrix(0, ncol=length(x), nrow=length(x))

## loop for each animal
for (i in 1:length(x)) {
for (j in 1:i) {

if (method=="HR") {
vi <- vol[[i]]$UD
vj <- vol[[j]]$UD
vi[vi<=lev] <- 1
vi[vi>lev] <- 0
vj[vj<=lev] <- 1
vj[vj>lev] <- 0
vk <- vi*vj
res[i,j] <- sum(vk)/sum(vi)
res[j,i] <- sum(vk)/sum(vj)
}

if (method=="PHR") {
vi <- x[[i]]$UD
vj <- x[[j]]$UD
ai <- vol[[i]]$UD
aj <- vol[[j]]$UD
ai[ai<=lev] <- 1
ai[ai>lev] <- 0
aj[aj<=lev] <- 1
aj[aj>lev] <- 0
if (conditional) {
vi <- vi*ai
vj <- vj*aj
res[j,i] <- sum(vi*aj)*(attr(vi,"cellsize")^2)
res[i,j] <- sum(vj*ai)*(attr(vi,"cellsize")^2)
} else {
res[j,i] <- sum(vi*aj)*(attr(vi,"cellsize")^2)
res[i,j] <- sum(vj*ai)*(attr(vi,"cellsize")^2)
}
}



if (method=="VI") {
vi <- c(x[[i]]$UD)
vj <- c(x[[j]]$UD)
ai <- vol[[i]]$UD
aj <- vol[[j]]$UD
ai[ai<=lev] <- 1
ai[ai>lev] <- 0
aj[aj<=lev] <- 1
aj[aj>lev] <- 0
if (conditional) {
vi <- vi*ai
vj <- vj*aj
res[i,j] <- res[j,i] <- sum(pmin(vi, vj))*(attr(x[[i]]$UD,"cellsize")^2)
} else {
res[i,j] <- res[j,i] <- sum(pmin(vi, vj))*(attr(x[[i]]$UD,"cellsize")^2)
}
}

if (method=="BA") {
vi <- x[[i]]$UD
vj <- x[[j]]$UD
ai <- vol[[i]]$UD
aj <- vol[[j]]$UD
ai[ai<=lev] <- 1
ai[ai>lev] <- 0
aj[aj<=lev] <- 1
aj[aj>lev] <- 0
if (conditional) {
vi <- vi*ai
vj <- vj*aj
res[j,i] <- res[i,j] <- sum(sqrt(vi)*sqrt(vj))*(attr(vi,"cellsize")^2)
} else {
res[j,i] <- res[i,j] <- sum(sqrt(vi)*sqrt(vj))*(attr(vi,"cellsize")^2)
}
}

if (method=="UDOI") {
vi <- x[[i]]$UD
vj <- x[[j]]$UD
ai <- vol[[i]]$UD
aj <- vol[[j]]$UD
ai[ai<=lev] <- 1
ai[ai>lev] <- 0
aj[aj<=lev] <- 1
aj[aj>lev] <- 0
if (conditional) {
vi <- vi*ai
vj <- vj*aj
ak <- sum(ai*aj)*(attr(vi,"cellsize")^2)
res[j,i] <- res[i,j] <- ak * sum(vi*vj)*(attr(vi,"cellsize")^2)
} else {
ak <- sum(ai*aj)*(attr(vi,"cellsize")^2)
res[j,i] <- res[i,j] <- ak * sum(vi*vj)*(attr(vi,"cellsize")^2)
}
}

if (method=="HD") {
vi <- x[[i]]$UD
vj <- x[[j]]$UD
ai <- vol[[i]]$UD
aj <- vol[[j]]$UD
ai[ai<=lev] <- 1
ai[ai>lev] <- 0
aj[aj<=lev] <- 1
aj[aj>lev] <- 0
if (conditional) {
vi <- vi*ai
vj <- vj*aj
res[j,i] <- res[i,j] <- sqrt(sum((sqrt(vi) - sqrt(vj))^2*(attr(vi,"cellsize")^2)))
} else {
res[j,i] <- res[i,j] <- sqrt(sum((sqrt(vi) - sqrt(vj))^2*(attr(vi,"cellsize")^2)))
}
}
}
}
rownames(res) <- names(x)
colnames(res) <- names(x)
return(res)
}
38 changes: 38 additions & 0 deletions R/speed.r
@@ -0,0 +1,38 @@
"speed" <- function(x, id=levels(x$id), burst=levels(x$burst),
date=NULL, units=c("seconds", "hours","days"))
{
## Verifications
.Deprecated("as.ltraj")
if (!inherits(x, "traj"))
stop("should be an object of class traj")
units<-match.arg(units)

## Selection of dates
x<-getburst(x, burst=burst, id=id, date=date)

## distances between successives relocations
li<-split(x, x$burst)
foo<-function(x) {
x1<-x[-1,]
x2<-x[-nrow(x),]
dist<-sqrt( (x1$x-x2$x)^2 + (x1$y-x2$y)^2)
hour<-(unclass(x1$date)-unclass(x2$date))
if (units=="hours")
hour<-(unclass(x1$date)-unclass(x2$date))/3600
if (units=="days")
hour<-(unclass(x1$date)-unclass(x2$date))/(3600*24)
disx<-(x1$x-x2$x)
disy<-(x1$y-x2$y)
so<-cbind.data.frame(id=x2$id,x=x2$x, y=x2$y, date=x2$date,
burst=x2$burst,
sp.x=disx/hour, sp.y=disy/hour,
speed=dist/hour, dt=hour)
return(so)
}

## Output
lo<-do.call("rbind", lapply(li, foo))
row.names(lo)<-1:nrow(lo)
return(lo)
}

10 changes: 5 additions & 5 deletions R/subsetmap.asc.r
Expand Up @@ -21,13 +21,13 @@
cs<-attr(x, "cellsize")

## Gets the indices of the limits of the new map
posli1<-round((xlim[1]-xll)/cs, 0)+1
posco1<-round((ylim[1]-yll)/cs, 0)+1
posli2<-round((xlim[2]-xll)/cs, 0)+1
posco2<-round((ylim[2]-yll)/cs, 0)+1
posli1<-floor((xlim[1]-xll)/cs)+1
posco1<-floor((ylim[1]-yll)/cs)+1
posli2<-floor((xlim[2]-xll)/cs)+1
posco2<-floor((ylim[2]-yll)/cs)+1

## Gets the new map
o<-x[posli1:posli2,posco1:posco2]
o<-x[posli1:posli2,posco1:posco2, drop=FALSE]

## Sets the attributes of the new map
attr(o, "xll")<-xy$x[posli1]
Expand Down
Empty file modified data/puechcirc.rda 100644 → 100755
Empty file.

0 comments on commit 97d0de3

Please sign in to comment.