Find the gaps between recordings
This post is to find and calculate gaps between points.
For the exercises, test data is from masked boobies.
To access
the data you have to install the package sula:
devtools::install_github(“MiriamLL/sula”)
#devtools::install_github("MiriamLL/sula")
library(sula)
GPS01<-(GPS01)
Identify column with time date data
GPS01$dt <- as.POSIXct(strptime(GPS01$tStamp, "%Y-%m-%d %H:%M:%S"))
Check gaps in time between recordings
GPS01$Gaps_time<-as.numeric(GPS01$dt - lag(GPS01$dt))
Classify gaps
Check gaps between locations
range(GPS01$Gaps_time,na.rm=TRUE)
[1] 4.033333 4.700000
To artificially create a gap, remove all locations between 13 and 14 hrs
GPS01$Hour <- as.numeric(substr(GPS01$dt, 12, 13))
Add row number
Calculate lag
GPS01_wGap$Gaps_time<-as.numeric(GPS01_wGap$dt - lag(GPS01_wGap$dt))
Classify gaps
Here, small gaps are when they were less than 15
min between locations
When did the gap occurred?
The result show the latest record, therefore the gap occurred between the previous recording and this one
# A tibble: 3 × 11
Latitude Longitude DateGMT TimeGMT IDs tStamp
<dbl> <dbl> <chr> <chr> <chr> <dttm>
1 -27.3 -109. 02/11/2017 20:00:38 GPS01 2017-11-02 15:00:38
2 -27.2 -109. 03/11/2017 20:00:17 GPS01 2017-11-03 15:00:17
3 -26.9 -109. 04/11/2017 20:03:27 GPS01 2017-11-04 15:03:27
# … with 5 more variables: dt <dttm>, Gaps_time <dbl>,
# Gaps_class <chr>, Hour <dbl>, seq <int>
To see the previous line to see when the gap started you can select this and the previous row
all_rows<-c(Large_gaps$seq,Large_gaps$seq-1)
# A tibble: 6 × 11
Latitude Longitude DateGMT TimeGMT IDs tStamp
<dbl> <dbl> <chr> <chr> <chr> <dttm>
1 -27.2 -109. 02/11/2017 17:59:37 GPS01 2017-11-02 12:59:37
2 -27.3 -109. 02/11/2017 20:00:38 GPS01 2017-11-02 15:00:38
3 -27.2 -109. 03/11/2017 17:58:01 GPS01 2017-11-03 12:58:01
4 -27.2 -109. 03/11/2017 20:00:17 GPS01 2017-11-03 15:00:17
5 -27.1 -109. 04/11/2017 17:56:45 GPS01 2017-11-04 12:56:45
6 -26.9 -109. 04/11/2017 20:03:27 GPS01 2017-11-04 15:03:27
# … with 5 more variables: dt <dttm>, Gaps_time <dbl>,
# Gaps_class <chr>, Hour <dbl>, seq <int>
To calculate the duration of the gap in hours
GPS01_wGap$Gap_hrs<-GPS01_wGap$Gaps_time/60
range(GPS01_wGap$Gap_hrs,na.rm=TRUE)
[1] 0.06722222 2.11166667
Where did the gap occurred?
Each circle is the locations, the size of the circle is the gap between locations
To solve issues with gaps there are several options:
Interpolate the tracking data to specific intervals.
For
example: ‘Gaps in the tracking datasets were linearly interpolated using
the adehabitatLT package in R in order to obtain tracks at 2 h time
intervals.’ (Ventura et al. 2020; Raine t al. 2021).
Other options
for interpolate tracking points here.
However, be cautious because large intervals will return a straight line
that might under or overestimate some areas used.
Define a threshold.
‘Incomplete trips (departure or return from/to the nest not
registered)’ (Lerma et al. 2020; Fijn et al. 2022).
Note that
including incomplete trips for calculating trip durations will not
greatly affect the results. However, gaps in the tracking data might
underestimate the true maximum distance used by the animal, and their
total distance covered during the trip. Therefore it is not advisable to
use it for this purpose.
‘A track was considered to be complete whenever the GPS recorded 80% or more of the duration of the foraging trip.’ (Tarroux et al. 2020)
Use portions of the recordings of the incomplete tracks.
For
example ‘… tracks were examined individually; only complete portions of
tracks were used for analyses…’ (Young et al. 2010).