abfleishman / trakR

R package for basic data processing for spatial animal tracking data
GNU General Public License v3.0
3 stars 1 forks source link

Error in MakeTrip when no points beyond cut offs and n cut off #1

Closed abfleishman closed 6 years ago

abfleishman commented 6 years ago

Hi Abram! I'm running into this error with MakeTrip: Error in Out[i]:In[i] : NA/NaN argument

I looked for NAs in the arguments and I couldn't find any. Do you have an idea on how to troubleshoot? Happy to send a reproducible example

Thanks!

##### Trip segmentation: WEGU SEFI 2015, for Abram
#####
##### 3 Aug 2018

rm(list=ls())
ls()
dev.off()

library(ggplot2)
library(maps)
library(mapdata)
library(dplyr)
library(trakR)
library(argosfilter)
library(readr)

# Load tracks
field<-read_csv("C:/Users/ConservationMetrics/Downloads/SubsetForAbram.csv")
names(field)

tracks<- field %>%
  distinct(CaptureID,DateTime,.keep_all = T) # removes NAs; none appear here

tracks$InterpointTime<-InterpointTime(tracks = tracks,ID = "CaptureID",DateTime = "DateTime")
tracks$InterpointDist<-InterpointDist(tracks = tracks,ID = "CaptureID",lat = "Latitude",lon = "Longitude")
tracks$Dist2Col<-Dist2Colony(tracks,dataLat = "Latitude", dataLon = "Longitude", ColonyLat = 37.69891,ColonyLong = -123.003361)
table(is.na(tracks$InterpointTime))
table(is.na(tracks$InterpointDist))
table(is.na(tracks$Dist2Col))

ggplot(tracks,aes(Longitude,Latitude)) +geom_path()+geom_point(x=-123.003361,y=37.69891, col="red",size=5)
ggplot(tracks,aes(Longitude,Latitude,col=Dist2Col>1)) +geom_point(size=2)+geom_point(x=-123.003361,y=37.69891, col="red",size=5)

hist(tracks$Dist2Col)
table(tracks$Dist2Col>1)
tracks_w_trips<-MakeTrip(tracks,ID = "CaptureID",DistCutOff = 1,Dist2Colony = "Dist2Col",NumLocCut = 10) # Error in Out[i]:In[i] : NA/NaN argument

newfield <- field[rowSums(is.na(field)) > 0,] #no NAs in original df
newfield <- tracks[rowSums(is.na(tracks)) > 0,] #NAs in 2 rows, InterpointTime & InterpointDist
abfleishman commented 6 years ago

hmm... I think I see the problem. There are only 5 points that are outside the DistCutOff of one km that you set. And then on top of this, you have set a NumLocCut = 10 so it tries to say that this is not really a trip because it is below the threshold. I will add an error message when this is the case. The way to fix this issue, for now, is to lower either the distance DistCutOff so that there are >10 points outside the buffer or lower the number of points needed to make a trip. Or manually remove this bird. I will try and have the function give a warning and move on to the next bird in the loop but I am not sure when I will have time to make that adjustment. Hope this helps!

abfleishman commented 6 years ago

fixed with informative warning