You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been developing such a function for my personal use (Wildlife insight media-based data). But I'm all a bit confused now on which standard I should be developing the code (camtrap-dp 0.1.6 or 1.0.1).
The function uses the assess_temporal_independence() (see #353 ) and group together media/record according to the rules (minDeltaTime_duration and deltaTimeComparedTo). I use sequenceID (or eventID?) of the first media for the sequences. I also modify the sequenceID of media, is that correct? I finally delete the non-independant observation. But because I don't have the observationStart and observationEnd (only timestamp), I'm loosing quite a lot of information here.
Let me know if you'd like to use such a function and I can make a PR. No worries if that's not the approach you were thinking of, just thought I could share this.
#' Convert media based to event-based#'#' @param pkg A datapackage#' @param minDeltaTime_dur: Duration in minutes between records of the same#' species at the same station to be considered independent.#' @param deltaTimeComparedTo: Character, `"lastIndependentRecord"` or#' `"lastRecord"`.#' For two records to be considered independent, must the second one be at#' least `minDeltaTime` minutes after the last independent record of the same#' species (`deltaTimeComparedTo = "lastIndependentRecord"`), or#' `minDeltaTime` minutes after the last record (`deltaTimeComparedTo =#' "lastRecord"`)?#' If `minDeltaTime` is 0, `deltaTimeComparedTo` should be NULL.#' @exportmedia2event<-function(pkg,
minDeltaTime_duration=60,
deltaTimeComparedTo="lastRecord") { # or "lastIndependentRecord"obs<-pkg$data$observations %>%
dplyr::group_by(.data$scientificName, .data$deploymentID) %>%
dplyr::arrange(.data$scientificName, .data$deploymentID, .data$timestamp) %>%
mutate(
independent= assess_temporal_independence(
.data$timestamp,
minDeltaTime_dur=minDeltaTime_duration,
deltaTimeComparedTo=deltaTimeComparedTo
)
) %>%
ungroup()
obs$NewSequenceID<-obs$sequenceID[obs$independent][cumsum(obs$independent)]
# Replace sequenceID in mediapkg$data$media<-pkg$data$media %>%
left_join(
obs %>% select(sequenceID, NewSequenceID),
by="sequenceID"
) %>%
mutate(sequenceID=NewSequenceID) %>%
select(-NewSequenceID)
# Replace sequenceID in obs and remove non-independant obs.pkg$data$observations<-obs %>%
mutate(sequenceID=NewSequenceID) %>%
filter(independent) %>%
select(-c(independent, NewSequenceID))
return(pkg)
}
The need of such a function emerged in #332.
The text was updated successfully, but these errors were encountered: