trip and tripEstimation

R packages to summarize animal track data


Both of these packages are now on CRAN: please let me know
if you are using them. Mike Sumner, April 2007 

Tutorial on using trip

trip-demo.pdf

Demonstration of light geo-location using tripEstimation

tripEstimation-demo.pdf


An example of using data from a flat (csv) file

readArgos is for reading the Argos Service PRV format.
I've been meaning to write more examples for just flat text files,
but not gotten around to it.  The beauty of readArgos is that it does
(almost all of) the following automagically:

You have a csv file, let's say it looks like this (I've disguised the names to protect innocents):

prognum,ptt,nlines,nsensor,satname,class,date,time,latitude,longitude,altitude,transfreq
39484,7838,6,4,M,1,2001-03-23,00:49:09,-42.867,67.373,0,401638430
39484,7838,9,4,K,0,2001-03-28,20:24:25,-39.991,63.608,0,401638460
39484,7838,5,4,J,0,2001-03-28,21:04:46,-39.908,64.454,0,401638424
...

Then you can read this using basic R:

d <- read.csv("file.csv")

## You'll need to extract  the date-times (in principle, trip will handle
## _any_ numeric date-time  format, but I've not tested it - chron at least
## is something I should ensure is supported):

d$gmt  <- as.POSIXct(strptime(paste(d$date, d$time), "%Y-%m-%d %H:%M:%S"), tz = "GMT")
range(d$gmt)

##Now, let's start with the basic sp stuff:

library(trip)  ## loads sp etc. as required

coordinates(d) <- ~longitude+latitude
## c("longitude", "latitude") would work too (as would c("x", "y") if that's what the file had)

summary(d)  ## it's a SpatialPointsDataFrame

## now for trip

## here we're just telling it the names of the date-time and ID columns (other names would work)
tr <- trip(d, c("gmt", "ptt"))
plot(tr, pch = ".")
lines(tr)

## filter for speed
tr$ok <- speedfilter(tr, max.speed = 90)  ## black-broweds in my case, 90kmh

## time spent gridding

grd <- tripGrid(tr[tr$ok, ], dur = 10*60)  ## interpolate between points down to 10 minutes
image(grd, col = bpy.colors(20))
summary(grd)  ## it's a SpatialGridDataFrame

If you have problems:

d <- as.data.frame(d) ## go back to a standard data.frame first, just in case ## You might need to remove duplicate rows: d <- d[!duplicated(d), ] ## And/or you might need to order the records by date-time within ID: d <- d[order(d$ptt, d$gmt), ] ## And finally, you might have duplicated date-times (but the coordinates etc are different): d$gmt <- adjust.duplicateTimes(d$gmt, d$ptt)