[R-sig-eco] Package adehabitatLT; lion telemetry data; removing intermittent 1-hr locations to create 2-hr locations

Lisanne Petracca lisanne.petracca at yahoo.com
Mon Nov 14 17:37:13 CET 2016


Hi all,

This is my first time posting to this mailing list, so I apologize in advance if I fail to describe my problem adequately.

I am working with a lion telemetry database, containing ~125,000 locations of 14 individuals.

The issue is that the database is messy. There are different collaring schedules between and within individuals (as some lions were collared multiple times), and my goal is to extract all points that are two hours apart for a step-selection function.

Using the package adehabitatLT, I was able to round all telemetry points to the nearest hour, and remove lion--time duplicates that may have resulted from this rounding. I first converted to ltraj class, a class suitable for analysis of movement paths. Code below (or you can skip ahead to next part):


alldatastep_pre <- as.data.frame(subset(dt, select=c("Name", "LocalTime", "lat", "long")))

#convert time column to POSIXct object
time <- as.POSIXct(strptime(alldatastep_pre$LocalTime,"%Y-%m-%d %H:%M:%S"), tz="Africa/Harare")
time2 <- round(time, units="hours")
alldatastep_pre$NewTime <- as.POSIXct(strptime(time2,format="%Y-%m-%d %H:%M"), tz="Africa/Harare")

#removing duplicates of Lion ID---Time due to rounding
alldatastep2_pre <- alldatastep_pre[!duplicated(paste(alldatastep_pre$Name, alldatastep_pre$NewTime)), ]
time <- as.POSIXct(strptime(alldatastep2_pre$NewTime,format="%Y-%m-%d %H:%M"), tz="Africa/Harare")

#extract WGS coordinate columns from alldata
WGSCoords <- data.frame(X = alldatastep2_pre$long, Y = alldatastep2_pre$lat)
names(WGSCoords) <- c("X","Y")

#convert it from data frame to sp object
coordinates(WGSCoords) <- ~ X + Y # longitude first

#add a coordinate reference system (in this case WGS84)
proj4string(WGSCoords) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")

#project using spTransform
UTMCoords <- as.data.frame(spTransform(WGSCoords, CRS("+proj=utm +zone=35 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")))
head(UTMCoords)

#conversion to class ltraj
finaldatastep_pre <- as.ltraj(xy = UTMCoords[,c("X","Y")], date= time, id = alldatastep2_pre$Name)

I then cut all trajectories such that each "burst" of points is separated by a maximum of two hours:

#function "foo2" will return TRUE when time lag btw 2 relocs is >2 hours
foo2 <- function(dt) 

{
  return(dt> (1*3600*2))
}

#cuts ltraj object into "bursts" separated by maximum of 2 hours
finaldatastep_pre_2hr <- cutltraj(finaldatastep_pre, "foo2(dt)", nextr = TRUE)

So, this is all great, BUT it leaves me with locations that are separated by one AND two hours, rather than just those locations separated by two hours, which is my goal. I am unable to figure out how to use R to convert a data frame like the one below such that ONLY points separated by two hours (dt=7200) are retained. So, essentially, in the case of two subsequent locations separated by 3600 seconds (one hour), I want to only retain the second one such that all points are separated by 7200 seconds (two hours).

Here is a sample of my data frame:


| x | y | date | dist | dt | id |
| 530042.6 | 7907562 | 9/9/2011 19:00 | 563.124484 | 3600 | Bhubesi |
| 529550.4 | 7907288 | 9/9/2011 20:00 | 391.955558 | 3600 | Bhubesi |
| 529235.2 | 7907055 | 9/9/2011 21:00 | 4.425924 | 3600 | Bhubesi |
| 529235.2 | 7907051 | 9/9/2011 22:00 | 457.910135 | 7200 | Bhubesi |
| 528913.5 | 7906725 | 9/10/2011 0:00 | 2.105879 | 3600 | Bhubesi |
| 528911.4 | 7906725 | 9/10/2011 1:00 | 614.954651 | 7200 | Bhubesi |
| 529519.1 | 7906819 | 9/10/2011 3:00 | 2308.861303 | 3600 | Bhubesi |
| 531726.2 | 7907497 | 9/10/2011 4:00 | 764.682101 | 3600 | Bhubesi |
| 532321.3 | 7907017 | 9/10/2011 5:00 | 282.912376 | 3600 | Bhubesi |
| 532142 | 7906798 | 9/10/2011 6:00 | 705.010909 | 3600 | Bhubesi |


Any guidance would be appreciated.
Best,Lisanne
	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list