Skip to content

Commit

Permalink
add option to only use qwindow for filtering and not for other purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Nov 22, 2024
1 parent e8c5474 commit 6310360
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
16 changes: 13 additions & 3 deletions R/g.part2.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
params_output = params$params_output
params_general = params$params_general
#-----------------------------
use_qwindow_as_diary = TRUE # If there is a diary specified via qwindow use it
if (is.numeric(params_247[["qwindow"]])) {
params_247[["qwindow"]] = params_247[["qwindow"]][order(params_247[["qwindow"]])]
} else if (is.character(params_247[["qwindow"]])) {
if (length(grep(pattern = "onlyfilter", x = params_247[["qwindow"]])) > 0) {
use_qwindow_as_diary = FALSE # Do not use it if it has the word onlyfilter
}
params_247[["qwindow"]] = g.conv.actlog(params_247[["qwindow"]],
params_247[["qwindow_dateformat"]],
epochSize = params_general[["windowsizes"]][1])
Expand Down Expand Up @@ -83,7 +87,7 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
myfun=c(), params_cleaning = c(), params_247 = c(),
params_phyact = c(), params_output = c(), params_general = c(),
path, ms2.out, foldername, fullfilenames, folderstructure, referencefnames,
daySUMMARY, pdffilenumb, pdfpagecount, csvfolder, cnt78, verbose) {
daySUMMARY, pdffilenumb, pdfpagecount, csvfolder, cnt78, verbose, use_qwindow_as_diary) {
Nappended = I_list = tail_expansion_log = NULL
if (length(ffdone) > 0) {
if (length(which(ffdone == as.character(unlist(strsplit(fnames[i], "eta_"))[2]))) > 0) {
Expand Down Expand Up @@ -151,6 +155,10 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
}
}
qwindowImp = params_247[["qwindow"]]
if (use_qwindow_as_diary == FALSE) {
# reset qwindow to default
params_247[["qwindow"]] = c(0, 24)
}
if (inherits(qwindowImp, "data.frame")) {
qwindowImp = qwindowImp[which(qwindowImp$ID == ID),]
if (nrow(qwindowImp) == 0) {
Expand Down Expand Up @@ -324,7 +332,8 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
params_phyact, params_output, params_general,
path, ms2.out, foldername, fullfilenames,
folderstructure, referencefnames,
daySUMMARY, pdffilenumb, pdfpagecount, csvfolder, cnt78, verbose)
daySUMMARY, pdffilenumb, pdfpagecount,
csvfolder, cnt78, verbose, use_qwindow_as_diary)

})
return(tryCatchResult)
Expand All @@ -344,7 +353,8 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
params_phyact, params_output, params_general,
path, ms2.out, foldername, fullfilenames,
folderstructure, referencefnames,
daySUMMARY, pdffilenumb, pdfpagecount, csvfolder, cnt78, verbose)
daySUMMARY, pdffilenumb, pdfpagecount,
csvfolder, cnt78, verbose, use_qwindow_as_diary)
}
}
}
12 changes: 8 additions & 4 deletions R/g.part5.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,14 @@ g.part5 = function(datadir = c(), metadatadir = c(), f0=c(), f1=c(),
qqq_backup = c()
add_one_day_to_next_date = FALSE
if (is.character(params_247[["qwindow"]])) {
params_247[["qwindow"]] = g.conv.actlog(params_247[["qwindow"]],
params_247[["qwindow_dateformat"]],
epochSize = ws3new)
# This will be an object with numeric qwindow values for all individuals and days
if (length(grep(pattern = "onlyfilter", x = params_247[["qwindow"]])) > 0) {
params_247[["qwindow"]] = g.conv.actlog(params_247[["qwindow"]],
params_247[["qwindow_dateformat"]],
epochSize = ws3new)
# This will be an object with numeric qwindow values for all individuals and days
} else {
params_247[["qwindow"]] = c(0, 24)
}
}
lastDay = ifelse(Nwindows > 0, yes = FALSE, no = TRUE) # skip while loop if there are no days to analyses
wi = 1
Expand Down
7 changes: 6 additions & 1 deletion man/GGIR.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,12 @@ GGIR(mode = 1:5,
as fall back setting. You may realise that these columns are the same as the
advanced format for the sleelog accepted by GGIR part 4. So, if you already
have an advanced format sleeplog for part 4 then you can provide this as value
for the qwindow parameter. The main purpose of this functionality is to offer
for the qwindow parameter. If you want to
use \code{qwindow} to guide the nonwear filtering as described in here but
do not want GGIR to use it for day segment analysis in part 2 or 5 then
make sure the diary filename includes the word "onlyfilter" to tell GGIR to
only use qwindow for nonwear filtering.
The main purpose of this functionality is to offer
the option to ignore short lasting nonwear episodes during the night
when there is suspicion that these are falsely detect, e.g. in individuals
with extended motionless sleep periods caused by medication.}
Expand Down

0 comments on commit 6310360

Please sign in to comment.