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
Package adehabitatLT; lion telemetry data; removing intermittent 1-hr locations to create 2-hr locations
2 messages · Lisanne Petracca, Mathieu Basille
Dear Lisanne, You want to play around with the function 'subsample' (see the help page for that), assuming that you can 'isolate' the different schedules as different bursts (potentially same ID, but different bursts when dt = 1h or 2h). To achieve that, you may be able to use 'cultraj' or 'hab::subset'. 'hab' is a package I developed, and is available on GitHub: https://github.com/basille/hab Note also that there are a couple of functions for SSFs in there... Also, adehabitatLT provides two functions to regularize trajectories: 'setNA' (that adds NAs for missing locations) and 'sett0' (that rounds the timestamps, similarly to what you already did). Look up the vignette for more details: https://cran.r-project.org/web/packages/adehabitatLT/vignettes/adehabitatLT.pdf Hope this helps, Mathieu. Le 14/11/2016 ? 11:37, Lisanne Petracca a ?crit :
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]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Mathieu Basille basille at ufl.edu | http://ase-research.org/basille +1 954-577-6314 | University of Florida FLREC ? Le tout est de tout dire, et je manque de mots Et je manque de temps, et je manque d'audace. ? ? Paul ?luard This message is signed to guarantee its authenticity. For a true private correspondence, use my public key to encrypt your messages: http://mathieu.basille.net/pub.asc Learn more: http://mzl.la/1BsOGiZ