Skip to contents

This vignette shows how to add tidal data to WATLAS data.

library(tools4watlas)
library(data.table)
library(ggplot2)

# Path to csv with raw data
data_path <- system.file(
  "extdata", "watlas_data_aggregated.csv",
  package = "tools4watlas"
)

# Load data
data <- fread(data_path, yaml = TRUE)

Add tidal data

# setorder
setorder(data, tag, time)

# path to tide data
tides_path <- system.file(
  "extdata", "example_2023_tide_data_UTC.csv",
  package = "tools4watlas"
)
tide_data_highres_path <- system.file(
  "extdata", "example_2023_tide_data_highres_UTC.csv",
  package = "tools4watlas"
)

# load tide data
tides <- data.table::fread(tides_path)
tide_data_highres <- data.table::fread(tide_data_highres_path)

# add tide data to movement data
data <- atl_add_tidal_data(
  data = data,
  tide_data = tides,
  tide_data_highres = tide_data_highres,
  waterdata_resolution = "10 minute",
  offset = 30
)

# Show first 5 rows (subset of columns to show additional ones)
head(data[, .(posID, tag, datetime, tideID, tidaltime, time2lowtide,
              waterlevel)]) |>
  knitr::kable(digits = 2)
posID tag datetime tideID tidaltime time2lowtide waterlevel
7917.33 3027 2023-09-23 03:13:00 2023513 133 -247 52
8234.75 3027 2023-09-23 03:19:00 2023513 139 -241 45
8274.00 3027 2023-09-23 03:20:00 2023513 140 -240 45
8302.00 3027 2023-09-23 03:21:00 2023513 141 -239 45
8503.17 3027 2023-09-23 03:24:00 2023513 144 -236 45
8548.41 3027 2023-09-23 03:25:00 2023513 145 -235 39

Select specific times within the tide cycle

For specific analyses, the cleaned data can be selected. To select localizations when mudlfats are available for foraging, we can for example select a low tide period from -2.5 hours to +2.5 hours around low tide (Bijleveld et al. 2016):

# check tide ID
data[, tideID] |> unique()
## [1] 2023513 2023514 2023512
# Select the low tide period for a particular tide as specified by tideID
data_subset <- atl_filter_covariates(
  data = data,
  filters = c(
    "tideID %in% c(2023513, 2023514)",
    "between(time2lowtide, -2.5 * 60, 2.5 * 60)"
  )
)
## Note: 51.24% of the dataset was filtered out, corresponding to 3531 positions.

Add species column

# Load meta data
all_tags_path <- system.file(
  "extdata", "tags_watlas_subset.xlsx", package = "tools4watlas"
)
all_tags <- readxl::read_excel(all_tags_path, sheet = "tags_watlas_all") |>
  data.table()

# join with data
all_tags[, tag := as.character(tag)]
data[all_tags, on = "tag", `:=`(species = i.species)]

# make species first column
setcolorder(data, c("species", setdiff(names(data), c("species"))))

Save as example data for tools4watlas.

# reassign so data is data
data_example <- data
save(data_example, file = "../data/watlas_data_example.rda")