Title: | Estimate Step Counts from 'Accelerometry' Data |
---|---|
Description: | Interfaces the 'stepcount' Python module <https://github.com/OxWearables/stepcount> to estimate step counts and other activities from 'accelerometry' data. |
Authors: | John Muschelli [aut, cre] |
Maintainer: | John Muschelli <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.2 |
Built: | 2024-11-02 04:58:07 UTC |
Source: | https://github.com/cran/stepcount |
Create Conda Environment for Walking
conda_create_walking_env(envname = "stepcount", ...)
conda_create_walking_env(envname = "stepcount", ...)
envname |
environment name |
... |
additional arguments to pass to |
Output of reticulate::conda_create
stepcount
Python ModuleInstall the stepcount
Python Module
install_stepcount(packages = "stepcount", ...) have_stepcount() stepcount_check() stepcount_version()
install_stepcount(packages = "stepcount", ...) have_stepcount() stepcount_check() stepcount_version()
packages |
packages to install.
If |
... |
Additional arguments to pass to |
Output of reticulate::py_install
if (have_stepcount()) { stepcount_version() }
if (have_stepcount()) { stepcount_version() }
Load Stepcount Model
sc_load_model( model_type = c("ssl", "rf"), model_path = NULL, check_md5 = TRUE, force_download = FALSE, as_python = TRUE ) sc_model_filename(model_type = c("ssl", "rf")) sc_download_model( model_path, model_type = c("ssl", "rf"), check_md5 = TRUE, ... )
sc_load_model( model_type = c("ssl", "rf"), model_path = NULL, check_md5 = TRUE, force_download = FALSE, as_python = TRUE ) sc_model_filename(model_type = c("ssl", "rf")) sc_download_model( model_path, model_type = c("ssl", "rf"), check_md5 = TRUE, ... )
model_type |
type of the model: either random forest (rf) or Self-Supervised Learning model (ssl) |
model_path |
the file path to the model. If on disk, this can be
re-used and not re-downloaded. If |
check_md5 |
Do a MD5 checksum on the file |
force_download |
force a download of the model, even if the file exists |
as_python |
Keep model object as a python object |
... |
for |
A model from Python. sc_download_model
returns a model file path.
Run Stepcount Model on Data
sc_model_params(model_type, pytorch_device) stepcount( file, sample_rate = NULL, model_type = c("ssl", "rf"), model_path = NULL, pytorch_device = c("cpu", "cuda:0"), verbose = TRUE, keep_data = FALSE ) stepcount_with_model( file, model_type = c("ssl", "rf"), model, sample_rate = NULL, pytorch_device = c("cpu", "cuda:0"), verbose = TRUE, keep_data = FALSE )
sc_model_params(model_type, pytorch_device) stepcount( file, sample_rate = NULL, model_type = c("ssl", "rf"), model_path = NULL, pytorch_device = c("cpu", "cuda:0"), verbose = TRUE, keep_data = FALSE ) stepcount_with_model( file, model_type = c("ssl", "rf"), model, sample_rate = NULL, pytorch_device = c("cpu", "cuda:0"), verbose = TRUE, keep_data = FALSE )
model_type |
type of the model: either random forest (rf) or Self-Supervised Learning model (ssl) |
pytorch_device |
device to use for prediction for PyTorch. |
file |
accelerometry file to process, including CSV,
CWA, GT3X, and |
sample_rate |
the sample rate of the data. Set to |
model_path |
the file path to the model. If on disk, this can be
re-used and not re-downloaded. If |
verbose |
print diagnostic messages |
keep_data |
should the data used in the prediction be in the output? |
model |
A model object loaded from |
A list of the results (data.frame
),
summary of the results, adjusted summary of the results, and
information about the data.
file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = stepcount(file = file) st = out$step_times } ## Not run: file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") df = readr::read_csv(file) if (stepcount_check()) { out = stepcount(file = df) st = out$step_times } if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("tidyr", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE)) { dat = df[10000:12000,] %>% dplyr::select(-annotation) %>% tidyr::gather(axis, value, -time) st = st %>% dplyr::mutate(time = lubridate::as_datetime(time)) %>% dplyr::as_tibble() st = st %>% dplyr::filter(time >= min(dat$time) & time <= max(dat$time)) dat %>% ggplot2::ggplot(ggplot2::aes(x = time, y = value, colour = axis)) + ggplot2::geom_line() + ggplot2::geom_vline(data = st, ggplot2::aes(xintercept = time)) } ## End(Not run)
file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = stepcount(file = file) st = out$step_times } ## Not run: file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") df = readr::read_csv(file) if (stepcount_check()) { out = stepcount(file = df) st = out$step_times } if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("tidyr", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE)) { dat = df[10000:12000,] %>% dplyr::select(-annotation) %>% tidyr::gather(axis, value, -time) st = st %>% dplyr::mutate(time = lubridate::as_datetime(time)) %>% dplyr::as_tibble() st = st %>% dplyr::filter(time >= min(dat$time) & time <= max(dat$time)) dat %>% ggplot2::ggplot(ggplot2::aes(x = time, y = value, colour = axis)) + ggplot2::geom_line() + ggplot2::geom_vline(data = st, ggplot2::aes(xintercept = time)) } ## End(Not run)
stepcount
Read a Data Set for stepcount
sc_read( file, sample_rate = NULL, resample_hz = "uniform", verbose = TRUE, keep_pandas = FALSE )
sc_read( file, sample_rate = NULL, resample_hz = "uniform", verbose = TRUE, keep_pandas = FALSE )
file |
path to the file for reading |
sample_rate |
the sample rate of the data. Set to |
resample_hz |
Target frequency (Hz) to resample the signal. If
"uniform", use the implied frequency (use this option to fix any device
sampling errors). Pass |
verbose |
print diagnostic messages |
keep_pandas |
do not convert the data to a |
A list of the data and information about the data
The data P30_wrist100
is from
https://ora.ox.ac.uk/objects/uuid:19d3cb34-e2b3-4177-91b6-1bad0e0163e7,
where we took the first 180,000 rows, the first 30 minutes of data
from that participant as an example.
file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = sc_read(file) } ## Not run: file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = sc_read(file, sample_rate = 100L) } ## End(Not run)
file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = sc_read(file) } ## Not run: file = system.file("extdata/P30_wrist100.csv.gz", package = "stepcount") if (stepcount_check()) { out = sc_read(file, sample_rate = 100L) } ## End(Not run)
Rename data for Stepcount
sc_rename_data(data) sc_write_csv(data, path = tempfile(fileext = ".csv"))
sc_rename_data(data) sc_write_csv(data, path = tempfile(fileext = ".csv"))
data |
a |
path |
path to the CSV output file |
A data.frame
of renamed columns
stepcount
Use Conda Environment for stepcount
use_stepcount_condaenv(envname = "stepcount", ...) conda_create_stepcount(envname = "stepcount", ..., python_version = "3.9") unset_reticulate_python() have_stepcount_condaenv()
use_stepcount_condaenv(envname = "stepcount", ...) conda_create_stepcount(envname = "stepcount", ..., python_version = "3.9") unset_reticulate_python() have_stepcount_condaenv()
envname |
environment name for the conda environment |
... |
additional arguments to pass to |
python_version |
version of Python to use for environment |
Nothing