Skip to content

Commit

Permalink
add trip import for prefiltering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Jonsen committed Feb 13, 2024
1 parent eb34b50 commit cc72b58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: aniMotum
Title: Fit Continuous-Time State-Space and Latent Variable Models for Quality Control of Argos Satellite (and Other) Telemetry Data and for Estimating Changes in Animal Movement
Version: 1.2-03
Date: 2024-02-06
Version: 1.2-03.9100
Date: 2024-02-13
Authors@R:
c(
person(given = "Ian",
Expand Down Expand Up @@ -43,7 +43,8 @@ Imports:
tmvtnorm,
rnaturalearth,
traipse,
terra
terra,
trip (>= 1.10.0)
LinkingTo: TMB, RcppEigen
Suggests:
testthat,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ importFrom(traipse,track_angle)
importFrom(traipse,track_bearing_to)
importFrom(traipse,track_distance)
importFrom(traipse,track_distance_to)
importFrom(trip,sda)
importFrom(trip,speedfilter)
importFrom(trip,trip)
importFrom(utils,data)
importFrom(utils,flush.console)
importFrom(utils,globalVariables)
Expand Down
11 changes: 7 additions & 4 deletions R/pf_sda_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
##' in favour of `speedfilter`. Either `ang = NA` or
##' `distlim = NA` are sufficient.
##' @importFrom sf st_coordinates st_is_longlat st_crs st_transform
##' @importFrom trip trip sda speedfilter
##' @keywords internal
##' @md

Expand Down Expand Up @@ -52,13 +53,15 @@ if (spdf) {
} else {
filt <- "sda"
}

if(any(is.na(ang))) ang <- c(0,0)
if(any(is.na(distlim))) distlim <- c(0,0)

trip.dat <- suppressWarnings(with(x.tr, trip(data.frame(lon, lat, tms = date, id),
correct_all = FALSE)))

if (filt == "sda") {
tmp <-
suppressWarnings(try(sda(x.tr,
suppressWarnings(try(sda(trip.dat,
smax = vmax * 3.6,
# convert m/s to km/h
ang = ang,
Expand All @@ -76,7 +79,7 @@ if (spdf) {
)

tmp <-
suppressWarnings(try(speedfilter(x.tr,
suppressWarnings(try(speedfilter(trip.dat,
max.speed = vmax * 3.6), # convert m/s to km/h
silent = TRUE))

Expand Down
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ wrap_lon <- function(lon, lon_min = -180) {

}

##' @title sda: filter track for speed, distance and angle.
##' @title sda_int: filter track for speed, distance and angle.
##'
##' @description Create a filter index of a track for "bad" points with a
##' combination of speed, distance and angle tests.
Expand All @@ -87,7 +87,7 @@ wrap_lon <- function(lon, lon_min = -180) {
##' @importFrom traipse track_distance track_angle
##' @keywords internal

sda <- function(x, smax, ang = c(15, 25), distlim = c(2.5, 5.0)) {
sda_int <- function(x, smax, ang = c(15, 25), distlim = c(2.5, 5.0)) {

x$speed.ok <- speedfilter(x, max.speed = smax)
if(all("lon" %in% names(x), "lat" %in% names(x))) {
Expand Down Expand Up @@ -154,7 +154,7 @@ sda <- function(x, smax, ang = c(15, 25), distlim = c(2.5, 5.0)) {
x$ok
}

##' @title speedfilter: filter track for speed.
##' @title speedfilter_int: filter track for speed.
##'
##' @description Create a filter index of a track for "bad" points based only on
##' speed. Called from `sda`
Expand All @@ -165,7 +165,7 @@ sda <- function(x, smax, ang = c(15, 25), distlim = c(2.5, 5.0)) {
##' @return logical vector, with \code{FALSE} values where the tests failed
##' @importFrom traipse track_distance_to
##' @keywords internal
speedfilter <- function (x, max.speed = NULL, test = FALSE)
speedfilter_int <- function (x, max.speed = NULL, test = FALSE)
{

if(all("lon" %in% names(x), "lat" %in% names(x))) {
Expand Down
8 changes: 4 additions & 4 deletions man/sda.Rd → man/sda_int.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/speedfilter.Rd → man/speedfilter_int.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc72b58

Please sign in to comment.