View source: R/ct_correct_datetime.R
| ct_correct_datetime | R Documentation |
This function corrects datetime stamps in camera trap data using a reference correction table. It applies time adjustments based on known timing errors for each camera deployment.
ct_correct_datetime(
data,
datetime,
deployment,
corrector,
format = NULL,
time_zone = "UTC"
)
data |
A data.frame or tibble containing camera trap records with datetime information that needs correction. |
datetime |
Column name (unquoted) in |
deployment |
Column name (unquoted) in both |
corrector |
A data.frame containing correction information with columns:
|
format |
Optional datetime format specification. Can be:
|
time_zone |
Time zone used to parse the datetimes in |
Two kinds of clock error are handled. A constant offset (a camera set to the wrong date or time) is corrected from the true datetime of the first record of each deployment. Clock drift (a camera that gains or loses time during the deployment) is corrected when the true datetime of the last record is also supplied: the correction then changes linearly with time, from the offset at the first record to the offset at the last record.
Camera clocks do not change for daylight saving time. Datetimes are therefore
parsed in the time zone given by time_zone, which defaults to "UTC" (no daylight
saving), so that recorded wall-clock times are kept as they are and no record
is shifted or lost at a daylight saving change.
A data.frame with the original data plus additional columns:
corrected_datetime - corrected datetime as POSIXct
correction_applied - sign of correction applied
time_offset_seconds - magnitude of correction in seconds
(varies between records when drift is corrected)
corrector_reference - reference datetime used for correction
# Load camera trap data
library(dplyr)
data(penessoulou)
camtrap_data <- penessoulou %>%
dplyr::filter(project == "Last")
# Create correction table
# CAMERA 1 was running slow (+), CAMERA 2 was running fast (-)
crtor <- data.frame(
camera = c("CAMERA 1", "CAMERA 2"),
sign = c("+", "-"),
datetimes = c("2025-03-14 8:17:00", "2024-11-14 10:02:03")
)
# Apply datetime corrections
ct_correct_datetime(
data = camtrap_data,
datetime = datetimes,
deployment = camera,
corrector = crtor
) %>%
dplyr::select(datetimes,
corrected_datetime,
time_offset_seconds) %>%
dplyr::slice_head(n = 10)
# Clock drift: CAMERA 1 also lost 90 s over the deployment, so the true time
# of its last record is 90 s later than the constant offset gives
crtor_drift <- crtor
crtor_drift$end_datetimes <- c("2025-04-16 01:16:15", NA)
ct_correct_datetime(
data = camtrap_data,
datetime = datetimes,
deployment = camera,
corrector = crtor_drift
) %>%
dplyr::filter(camera == "CAMERA 1") %>%
dplyr::select(datetimes, corrected_datetime, time_offset_seconds) %>%
dplyr::slice_tail(n = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.