ar_read: Read and Preprocess Data for AcceleRest

View source: R/estimate_rest.R

ar_readR Documentation

Read and Preprocess Data for AcceleRest

Description

AcceleRest expects 30Hz, gravity-calibrated data without gaps. Device files (.cwa, .gt3x, .bin, optionally compressed) are read with actiread::acti_read(), and CSV files with readr::read_csv(). Gaps (all-zero rows from ActiGraph idle sleep mode, and missing values) are filled with the last observation carried forward using actibase::acti_fill_zeros(), as ActiLife does. The data are then low-pass filtered, calibrated, and resampled to 30Hz with the actipy Python module, using the same settings as the AcceleRest command-line tool. .h5 files must already be preprocessed, with an ⁠axes x samples⁠ array in data/accelerometry.

Usage

ar_read(
  file,
  sample_rate = NULL,
  fill_zeros = TRUE,
  lowpass_hz = 15,
  calibrate_gravity = TRUE,
  detect_nonwear = FALSE,
  verbose = FALSE,
  ...
)

Arguments

file

a data.frame with a time column and X, Y, Z axes (see actibase::acti_standardize_data()), or a path to a device, CSV, or .h5 file, optionally compressed (.gz, .bz2, .xz). Time stamps must be unique; data with time stamps rounded to the second should have times reconstructed using the sample rate.

sample_rate

sample rate (Hz) of the data. If NULL, it is found with actibase::get_sample_rate() (from the sample_rate attribute, the header, or the time stamps).

fill_zeros

If TRUE, fill gaps with actibase::acti_fill_zeros(). Any gap left in the data makes the predictions for every context window covering it (about 2.1 hours) missing.

lowpass_hz, calibrate_gravity, detect_nonwear

preprocessing options passed to actipy. Non-wear detected by actipy is set to NA.

verbose

print diagnostic messages

...

additional arguments passed to actiread::acti_read() for device files

Value

A list with the Python (numpy) array of ⁠3 x samples⁠ data (accelerometry), the time of the first sample (start_time, NULL for .h5 files), and actipy information about the data (info).

Examples


  # Runs only after ar_setup(), so Python is not set up otherwise
  if (ar_have_repo() && ar_have_weights() &&
      ar_python_modules_installed()) {
    data = ar_example_data(n_hours = 0.1)
    out = ar_read(data)
    out$start_time
  }


rester documentation built on Nov. 13, 2026, 1:06 a.m.