Identify gaps

Find the gaps between recordings

Miriam Lerma true
10-03-2022

Intro

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

GPS01 <- GPS01 %>%
  mutate(Gaps_class = case_when(is.na(Gaps_time) ~ 'U',
                                Gaps_time <= 300 ~ 'Small',
                                TRUE ~ 'Large'))

Check gaps between locations

range(GPS01$Gaps_time,na.rm=TRUE)
[1] 4.033333 4.700000

Create gap

To artificially create a gap, remove all locations between 13 and 14 hrs

GPS01$Hour <- as.numeric(substr(GPS01$dt, 12, 13))
GPS01_wGap<-GPS01 %>%
  filter(Hour != 13 & Hour != 14)

Add row number

GPS01_wGap$seq<-seq(1:nrow(GPS01_wGap))

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

GPS01_wGap <- GPS01_wGap %>%
  mutate(Gaps_class = case_when(is.na(Gaps_time) ~ 'U',
                                Gaps_time <= 15 ~ 'Small',
                                TRUE ~ 'Large'))

When?

When did the gap occurred?

The result show the latest record, therefore the gap occurred between the previous recording and this one

Large_gaps<-GPS01_wGap %>%
  filter(Gaps_class=='Large')
Large_gaps
# 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)
GPS01_wGap %>%
  filter(seq %in% all_rows)
# 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>

How much?

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?

Where did the gap occurred?

Each circle is the locations, the size of the circle is the gap between locations

ggplot()+
  geom_point(data = GPS01_wGap,
            aes(x=Longitude,y = Latitude,size = Gap_hrs),color='red')+
  geom_path(data = GPS01_wGap,
            aes(x=Longitude,y = Latitude),color='blue',size = 0.5)+
  theme_bw()

ggplotly(ggplot()+
  geom_point(data = GPS01_wGap,
            aes(x=Longitude,y = Latitude,size = Gap_hrs, color=Hour))+
  geom_path(data = GPS01_wGap,
            aes(x=Longitude,y = Latitude),color='blue',size = 0.5)+
  theme_bw())

Further considerations

To solve issues with gaps there are several options:

  1. ‘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.

  2. ‘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)

  3. 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).