Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set daysleep_offset default value #399

Merged
merged 9 commits into from
Feb 26, 2021
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
person("Joan","Capdevila Pujol",role="ctb"),
person("Jairo H","Migueles",role="ctb"),
person("Matthew R","Patterson",role="ctb"),
person("Dan","Jackson",role="ctb"))
person("Dan","Jackson",role="ctb"),
person("Lena","Kushleyeva",role="ctb"))
Maintainer: Vincent T van Hees <v.vanhees@accelting.com>
Description: A tool to process and analyse data collected with wearable raw acceleration sensors as described in Migueles and colleagues (JMPB 2019), and van Hees and colleagues (JApplPhysiol 2014; PLoSONE 2015). The package has been developed and tested for binary data from 'GENEActiv' <https://www.activinsights.com/> and GENEA devices (not for sale), .csv-export data from 'Actigraph' <https://actigraphcorp.com> devices, and .cwa and .wav-format data from 'Axivity' <https://axivity.com>. These devices are currently widely used in research on human daily physical activity. Further, the package can handle accelerometer data file from any other sensor brand providing that the data is stored in csv format and has either no header or a two column header. Also the package allows for external function embedding.
URL: https://github.com/wadpac/GGIR/, https://groups.google.com/forum/#!forum/RpackageGGIR
Expand Down
4 changes: 2 additions & 2 deletions R/g.IVIS.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
g.IVIS = function(Xi, epochsizesecondsXi = 5, IVIS_epochsize_seconds=c(), IVIS_windowsize_minutes = 60, IVIS.activity.metric = 1) {
if (!is.null(IVIS_epochsize_seconds)) {
g.IVIS = function(Xi, epochsizesecondsXi = 5, IVIS_epochsize_seconds=NA, IVIS_windowsize_minutes = 60, IVIS.activity.metric = 1) {
if (!is.na(IVIS_epochsize_seconds)) {
warning("Argument IVIS_epochsize_seconds has been depricated")
}
IVIS_epochsize_seconds = IVIS_windowsize_minutes*60
Expand Down
10 changes: 5 additions & 5 deletions R/g.part1.R
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ g.part1 = function(datadir=c(),outputdir=c(),f0=1,f1=c(),windowsizes = c(5,900,3
}
if (do.parallel == TRUE) {
on.exit(parallel::stopCluster(cl))
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
}
14 changes: 7 additions & 7 deletions R/g.part2.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ g.part2 = function(datadir=c(),metadatadir=c(),f0=c(),f1=c(),strategy = 1, hrs.d
boutcriter = 0.8,ndayswindow=7,idloc=1,do.imp=TRUE,storefolderstructure = FALSE,
overwrite=FALSE,epochvalues2csv=FALSE,mvpadur=c(1,5,10),selectdaysfile=c(),
window.summary.size=10,dayborder=0,bout.metric=2,closedbout=FALSE,desiredtz="",
IVIS_windowsize_minutes = 60, IVIS_epochsize_seconds = c(), iglevels = c(),
IVIS_windowsize_minutes = 60, IVIS_epochsize_seconds = NA, iglevels = c(),
IVIS.activity.metric=2, TimeSegments2ZeroFile=c(), qM5L5 = c(), do.parallel = TRUE,
myfun=c(), MX.ig.min.dur=10) {
snloc= 1
Expand Down Expand Up @@ -77,7 +77,7 @@ g.part2 = function(datadir=c(),metadatadir=c(),f0=c(),f1=c(),strategy = 1, hrs.d
}
t1 = Sys.time() # copied here
if (do.parallel == TRUE) {
cat(paste0('\n Busy processing ... see ',metadatadir,'/ms2', ' for progress\n'))
cat(paste0('\n Busy processing ... see ', metadatadir, ms2.out, ' for progress\n'))
}

# check whether we are indevelopment mode:
Expand Down Expand Up @@ -221,11 +221,11 @@ g.part2 = function(datadir=c(),metadatadir=c(),f0=c(),f1=c(),strategy = 1, hrs.d
}
if (do.parallel == TRUE) {
on.exit(parallel::stopCluster(cl))
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
}
12 changes: 6 additions & 6 deletions R/g.part3.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ g.part3 = function(metadatadir=c(),f0,f1,anglethreshold = 5,timethreshold = 5,
}
t1 = Sys.time() # copied here
if (do.parallel == TRUE) {
cat(paste0('\n Busy processing ... see ', metadatadir,'/ms3', ' for progress\n'))
cat(paste0('\n Busy processing ... see ', metadatadir,'/meta/ms3.out', ' for progress\n'))
}
# check whether we are indevelopment mode:
GGIRinstalled = is.element('GGIR', installed.packages()[,1])
Expand Down Expand Up @@ -126,11 +126,11 @@ g.part3 = function(metadatadir=c(),f0,f1,anglethreshold = 5,timethreshold = 5,
}
if (do.parallel == TRUE) {
on.exit(parallel::stopCluster(cl))
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
}
12 changes: 6 additions & 6 deletions R/g.part5.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ g.part5 = function(datadir=c(),metadatadir=c(),f0=c(),f1=c(),strategy=1,maxdur=7
}
t0 = t1 = Sys.time() # copied here
if (do.parallel == TRUE) {
cat(paste0('\n Busy processing ... see ',metadatadir,'/ms5', ' for progress\n'))
cat(paste0('\n Busy processing ... see ', metadatadir, ms5.out, ' for progress\n'))
}
# check whether we are in development mode:
GGIRinstalled = is.element('GGIR', installed.packages()[,1])
Expand Down Expand Up @@ -774,11 +774,11 @@ g.part5 = function(datadir=c(),metadatadir=c(),f0=c(),f1=c(),strategy=1,maxdur=7
}
if (do.parallel == TRUE) {
on.exit(parallel::stopCluster(cl))
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames.ms3[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
for (oli in 1:length(output_list)) { # logged error and warning messages
if (is.null(unlist(output_list[oli])) == FALSE) {
cat(paste0("\nErrors and warnings for ",fnames.ms3[oli]))
print(unlist(output_list[oli])) # print any error and warnings observed
}
}
}
6 changes: 3 additions & 3 deletions R/g.shell.GGIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ g.shell.GGIR = function(mode=1:5,datadir=c(),outputdir=c(),studyname=c(),f0=1,f1
# if (length(which(mode == 0)) > 0) dopart0 = TRUE
if (length(which(mode == 1)) > 0) dopart1 = TRUE
if (length(which(mode == 2)) > 0) dopart2 = TRUE
if (length(which(mode == 3)) > 0) dopart3 = TRUE; do.anglez = TRUE
if (length(which(mode == 3)) > 0) { dopart3 = TRUE; do.anglez = TRUE }
if (length(which(mode == 4)) > 0) dopart4 = TRUE
if (length(which(mode == 5)) > 0) dopart5 = TRUE
}
Expand Down Expand Up @@ -97,7 +97,7 @@ g.shell.GGIR = function(mode=1:5,datadir=c(),outputdir=c(),studyname=c(),f0=1,f1
} else if (numi == TRUE) {
txt = paste(as.character(config[ci,1]),"=",as.numeric(config[ci,2]),"",sep="")
} else if (numi == FALSE & logi == FALSE) {
if (length(config[ci,2]) > 0) {
if (length(config[ci,2]) > 0 & !is.na(config[ci,2])) {
if (config[ci,2] == 'c()') {
if (config[ci,1] == "def.no.sleep") def.no.sleep = c()
if (config[ci,1] == "backup.cal.coef") backup.cal.coef = c()
Expand Down Expand Up @@ -206,7 +206,7 @@ g.shell.GGIR = function(mode=1:5,datadir=c(),outputdir=c(),studyname=c(),f0=1,f1
if (exists("ndayswindow") == FALSE) ndayswindow = 7
if (exists("do.imp") == FALSE) do.imp = TRUE
if (exists("IVIS_windowsize_minutes") == FALSE) IVIS_windowsize_minutes=60
if (exists("IVIS_epochsize_seconds") == FALSE) IVIS_epochsize_seconds=c()
if (exists("IVIS_epochsize_seconds") == FALSE) IVIS_epochsize_seconds=NA
if (exists("mvpadur") == FALSE) mvpadur = c(1,5,10) # related to part 2 (functionality to anticipate part 5)
if (length(mvpadur) != 3) {
mvpadur = c(1,5,10)
Expand Down
1 change: 1 addition & 0 deletions R/g.sib.det.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ g.sib.det = function(M,IMP,I,twd=c(-12,12),anglethreshold = 5,
# Estimate Sleep Period Time Window, because this will be used by g.part4 if sleeplog is not available
tmpANGLE = angle[qqq1:qqq2]
tmpTIME = time[qqq1:qqq2]
daysleep_offset = 0
inbedout = sptwindow_HDCZA(tmpANGLE,ws3=ws3,constrain2range=constrain2range,
perc = perc, inbedthreshold = inbedthreshold, bedblocksize = bedblocksize,
outofbedsize = outofbedsize)
Expand Down
2 changes: 1 addition & 1 deletion man/g.IVIS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
van Someren.
}
\usage{
g.IVIS(Xi, epochsizesecondsXi = 5, IVIS_epochsize_seconds = c(),
g.IVIS(Xi, epochsizesecondsXi = 5, IVIS_epochsize_seconds = NA,
IVIS_windowsize_minutes = 60, IVIS.activity.metric = 1)
}
\arguments{
Expand Down
2 changes: 1 addition & 1 deletion man/g.part2.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ do.imp=TRUE,storefolderstructure=FALSE,overwrite=FALSE,
epochvalues2csv=FALSE, mvpadur=c(1,5,10),selectdaysfile=c(),
window.summary.size=10,dayborder=0,
bout.metric=2,closedbout=FALSE,desiredtz="",
IVIS_windowsize_minutes = 60, IVIS_epochsize_seconds = c(),
IVIS_windowsize_minutes = 60, IVIS_epochsize_seconds = NA,
iglevels = c(), IVIS.activity.metric=2, TimeSegments2ZeroFile = c(),
qM5L5=c(), do.parallel = TRUE, myfun=c(), MX.ig.min.dur=10)
}
Expand Down
44 changes: 44 additions & 0 deletions tests/testthat/test_part3_1_night.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
library(GGIR)
context("g.part3")
test_that("Part 3 identifies 1-night scenario", {
skip_on_cran()
#=======================
# Create a test file for a bit over a day worth of data.
# Nmin=2000 is currently the default, but hardcoding it here in case the default changes.
create_test_acc_csv(Nmin=2000)
fn = "123A_testaccfile.csv"
dn = "output_test"
if (file.exists(dn)) unlink(dn,recursive=TRUE)

# g.part# modules report errors and warnings only by printing them out to the console,
# so these are not true errors and warnings that would get caught by the testing module.
# Instead, grab the console output and parse out any errors we should know about.
#
# Note: make sure to call g.shell.GGIR() with do.parallel = FALSE,
# otherwise not all console output will be captured.

out = capture.output(g.shell.GGIR(mode=c(1:3), datadir=fn, outputdir=getwd(), studyname="test", f0=1, f1=1,
do.report=c(), visualreport=FALSE, viewingwindow=1,
overwrite=TRUE, do.parallel = FALSE, minimumFileSizeMB=0),
type = c("output"))

# There shouldn't be any errors or warnings reported, so if there are any, throw an error.
err_idx = grepl("Errors and warnings for", out)
for (ii in 1:length(err_idx)) {
if (err_idx[ii]) {
stop(out[ii:length(err_idx)])
}
}

out.file.path = paste(dn, "/meta/ms3.out/", fn, ".RData", sep ="")
expect_true(file.exists(out.file.path))
load(out.file.path)

# check that the data file had only one night. The 'night' column should contain only 1s
for(i in 1:nrow(sib.cla.sum)) {
expect_that(sib.cla.sum$night[i],equals(1))
}

if (file.exists(fn)) file.remove(fn)
if (file.exists(dn)) unlink(dn, recursive=TRUE)
})