From cc72b585b2ae28cbfdd476f43a3e03d4cb90f69b Mon Sep 17 00:00:00 2001 From: Ian Jonsen Date: Tue, 13 Feb 2024 14:23:56 -0400 Subject: [PATCH] add trip import for prefiltering --- DESCRIPTION | 7 ++++--- NAMESPACE | 3 +++ R/pf_sda_filter.R | 11 +++++++---- R/utils.R | 8 ++++---- man/{sda.Rd => sda_int.Rd} | 8 ++++---- man/{speedfilter.Rd => speedfilter_int.Rd} | 8 ++++---- 6 files changed, 26 insertions(+), 19 deletions(-) rename man/{sda.Rd => sda_int.Rd} (85%) rename man/{speedfilter.Rd => speedfilter_int.Rd} (78%) diff --git a/DESCRIPTION b/DESCRIPTION index aab7303c..d76ff28f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", @@ -43,7 +43,8 @@ Imports: tmvtnorm, rnaturalearth, traipse, - terra + terra, + trip (>= 1.10.0) LinkingTo: TMB, RcppEigen Suggests: testthat, diff --git a/NAMESPACE b/NAMESPACE index 76074f58..4e1d8e90 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/pf_sda_filter.R b/R/pf_sda_filter.R index 2c5cd21a..ddb5b7f6 100644 --- a/R/pf_sda_filter.R +++ b/R/pf_sda_filter.R @@ -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 @@ -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, @@ -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)) diff --git a/R/utils.R b/R/utils.R index ac92173d..35bda9ce 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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. @@ -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))) { @@ -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` @@ -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))) { diff --git a/man/sda.Rd b/man/sda_int.Rd similarity index 85% rename from man/sda.Rd rename to man/sda_int.Rd index 27d700e1..4dbbc909 100644 --- a/man/sda.Rd +++ b/man/sda_int.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R -\name{sda} -\alias{sda} -\title{sda: filter track for speed, distance and angle.} +\name{sda_int} +\alias{sda_int} +\title{sda_int: filter track for speed, distance and angle.} \usage{ -sda(x, smax, ang = c(15, 25), distlim = c(2.5, 5)) +sda_int(x, smax, ang = c(15, 25), distlim = c(2.5, 5)) } \arguments{ \item{x}{fG_format object passed from pf_obs_type()} diff --git a/man/speedfilter.Rd b/man/speedfilter_int.Rd similarity index 78% rename from man/speedfilter.Rd rename to man/speedfilter_int.Rd index 3113cca4..863c1a90 100644 --- a/man/speedfilter.Rd +++ b/man/speedfilter_int.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R -\name{speedfilter} -\alias{speedfilter} -\title{speedfilter: filter track for speed.} +\name{speedfilter_int} +\alias{speedfilter_int} +\title{speedfilter_int: filter track for speed.} \usage{ -speedfilter(x, max.speed = NULL, test = FALSE) +speedfilter_int(x, max.speed = NULL, test = FALSE) } \arguments{ \item{x}{fG_format object passed from \code{sda}}