Computes a logical is_static flag for each row in tag$magnetic using the
acceleration magnitude.
The classification is done in these steps:
Compute the acceleration norm
gn = sqrt(x^2 + y^2 + z^2)for each sample.Apply the hard threshold
abs(gn - 1) < static_thr_hardto build the initial static candidates.If
use_activity = TRUEandtag$accelerationis available, cluster the positive activityvaluesamples into low- and high-activity groups and set samples matching the high-activity group (by date) toFALSE.Remove outliers among the remaining candidate static samples using a MAD rule on
gnwith thresholdstatic_thr_outlier.
Samples with missing acceleration are returned as NA.
Arguments
- tag
A
GeoPressureRtag object containing a$magneticdata frame withacceleration_x,acceleration_y, andacceleration_z. Withuse_activity = TRUE, thevaluecolumn oftag$accelerationis used as an activity signal.- static_thr_hard
Numeric or
NULL. Hard threshold around 1 g used to build the initial candidate static set. IfNULL, the default0.1is used.- static_thr_outlier
Numeric or
NULL. MAD threshold used to remove outliers among the candidate static samples. IfNULL, the default3is used.- use_activity
Logical. If
TRUEandtag$accelerationis available, use activity clustering to flag high-activity samples as moving before MAD outlier filtering.
Value
The input tag object with tag$magnetic$is_static added or updated.
tag$magnetic$is_static is a logical vector where TRUE denotes samples
considered static and FALSE denotes samples considered moving.
Examples
library(GeoPressureR)
withr::with_dir(system.file("extdata", package = "GeoMagR"), {
tag <- tag_create("14DM", quiet = TRUE)
tag_static_obj <- tag_static(tag)
table(tag_static_obj$magnetic$is_static)
# A stricter hard threshold keeps fewer samples as static
tag_static_strict <- tag_static(tag, static_thr_hard = 0.05, static_thr_outlier = 2)
table(tag_static_strict$magnetic$is_static)
})
#>
#> FALSE TRUE
#> 952 998
