Skip to content

Commit

Permalink
Merge pull request #56 from wadpac/fix_readme
Browse files Browse the repository at this point in the history
The readme file now includes the links to the data and the published article.
In addition, a quick fix for a removed package dependency.
  • Loading branch information
Anne-Linde authored Jun 25, 2024
2 parents a8e377f + 8d1f590 commit 86ddf02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import(foreach)
import(ggplot2)
import(ggpubr)
importFrom(GENEAread,read.bin)
importFrom(GGIR,g.downsample)
importFrom(GGIRread,readAxivity)
importFrom(GGIRread,resample)
importFrom(data.table,fread)
Expand Down
26 changes: 21 additions & 5 deletions R/autocalibration.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#' @param brand Character of sensor brand: "ActiGraph", "activPAL", "Acttrust", "Axivity", "GENEActiv", or "MOX".
#' @return List of objects identical to g.calibrate function R package GGIR
#' @importFrom stats sd lm.wfit
#' @importFrom GGIR g.downsample
#' @export

autocalibration = function(data, sr, printsummary= TRUE, brand) {
# simplified version of auto-calibration from R package GGIR
# without temperature and without loading the data in blocks
# now includes old g.downsampling function removed from GGIR...

spherecrit=0.3
minloadcrit=72
Expand Down Expand Up @@ -73,13 +73,29 @@ autocalibration = function(data, sr, printsummary= TRUE, brand) {
#=============================================
# non-integer sampling rate is a pain for deriving epoch based sd
# however, with an epoch of 10 seconds it is an integer number of samples per epoch
g.downsample = function(sig,fs,ws3,ws2) {
#averaging per second => var1
sig2 =cumsum(c(0,sig))
select = seq(1,length(sig2),by=fs)
var1 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))])))
#averaging per ws3 => var2 (e.g. 5 seconds)
select = seq(1,length(sig2),by=fs*ws3)
var2 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))])))
#averaging per ws2 => var3 (e.g. 15 minutes)
select = seq(1,length(sig2),by=fs*ws2)
var3 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))])))
invisible(list(var1=var1,var2=var2,var3=var3))
}

EN = sqrt(Gx^2 + Gy^2 + Gz^2)
D1 = GGIR::g.downsample(EN,sr,ws4,ws2)
D1 = g.downsample(EN,sr,ws4,ws2)
EN2 = D1$var2
#mean acceleration
D1 = GGIR::g.downsample(Gx,sr,ws4,ws2); GxM2 = D1$var2
D1 = GGIR::g.downsample(Gy,sr,ws4,ws2); GyM2 = D1$var2
D1 = GGIR::g.downsample(Gz,sr,ws4,ws2); GzM2 = D1$var2

D1 = g.downsample(Gx,sr,ws4,ws2); GxM2 = D1$var2
D1 = g.downsample(Gy,sr,ws4,ws2); GyM2 = D1$var2
D1 = g.downsample(Gz,sr,ws4,ws2); GzM2 = D1$var2

#sd acceleration
dim(Gx) = c(sr*ws4,ceiling(length(Gx)/(sr*ws4))); GxSD2 = apply(Gx,2,sd)
dim(Gy) = c(sr*ws4,ceiling(length(Gy)/(sr*ws4))); GySD2 = apply(Gy,2,sd)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![codecov](https://codecov.io/gh/wadpac/mechanicalshakerexperiments/branch/main/graph/badge.svg?token=C2X6Z6AJLL)](https://codecov.io/gh/wadpac/mechanicalshakerexperiments)


The code in this repository corresponds to our research project to facilitate processing and analyzing data from a large pool of acceleration sensors that were attached to a mechanical shaker machine. The data itself is publicly available [here] ([https://pages.github.com/](https://zenodo.org/records/8160791)).
The code in this repository corresponds to our research project to facilitate processing and analyzing data from a large pool of acceleration sensors that were attached to a mechanical shaker machine. The data itself is publicly available [here](https://zenodo.org/records/8160791).

### File reading

Expand Down

0 comments on commit 86ddf02

Please sign in to comment.