Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
35fc330
remove unused variables
l-k- Dec 13, 2023
6a67747
don't crash if get to end of csv file before encountering a non-0 number
l-k- Dec 13, 2023
40ae3ef
use correct actigraph csv test file for testing g.inspectfile and g.r…
l-k- Dec 13, 2023
8d9f29a
simplify blocksize handling
l-k- Dec 14, 2023
e2c54cd
up-to-date documentation is in g.readaccfile.Rd
l-k- Dec 14, 2023
740310d
simplify readaccfile
l-k- Dec 18, 2023
525e4b7
clean up if() conditions
l-k- Dec 18, 2023
ecb3e9b
data.table::fread returns a data frame if data.table=FALSE
l-k- Dec 19, 2023
4109b83
standardize output names
l-k- Dec 19, 2023
ebf61a2
correcting comment
l-k- Dec 19, 2023
1f59462
remove unused parameter
l-k- Dec 21, 2023
bb18b5d
fixing a weird copy-paste error I made
l-k- Dec 21, 2023
502370b
call to dotorcoma was in a wrong place
l-k- Dec 23, 2023
9212787
don't convert strings to factors
l-k- Dec 24, 2023
a7ffe05
standardize output for Actigraph csv
l-k- Dec 24, 2023
023ca14
simplify function declaration
l-k- Dec 24, 2023
7666748
standardize output names
l-k- Dec 24, 2023
49ee517
params_general[["desiredtz"]] defaults to ""
l-k- Dec 24, 2023
847373f
converting unix timestamp to POSIXlt & back to numeric leaves it unch…
l-k- Dec 24, 2023
954a009
standardize output
l-k- Dec 24, 2023
44a4411
adding axivity csv test files
l-k- Dec 27, 2023
99ec671
put all tests for same format together
l-k- Dec 28, 2023
613d2bd
add readaccfile and inspectfile tests for movisens
l-k- Dec 29, 2023
d22251f
There could be a dot anywhere in the file path,
l-k- Dec 29, 2023
dcce9c8
standardize output for movisens
l-k- Dec 29, 2023
8e0f445
read.gt3x::read.gt3x already returns a data frame because parameter a…
l-k- Dec 29, 2023
9c41ee9
standardize output for gt3x
l-k- Dec 29, 2023
62c33b7
standardize output for ad hoc csv
l-k- Dec 31, 2023
aa3fc63
I think mon = MOVISENS was a typo, need AD_HOC
l-k- Dec 31, 2023
a7d1c6a
fix number of rows skipped as header
l-k- Jan 1, 2024
1e40e8f
minor cleanup
l-k- Jan 1, 2024
b582d2f
startpage++ not always needed for AD_HOC_CSV
l-k- Jan 2, 2024
3a3ffd3
we don't expect factors in this input
l-k- Jan 3, 2024
91c23df
don't re-read header for later blocks of same file
l-k- Jan 3, 2024
e23600b
minor clarification
l-k- Jan 3, 2024
668bf79
as.numeric() returns NA on failure; length(NA)==1
l-k- Jan 3, 2024
5eb9a81
check if sf is in header under "sample_rate", not rmc.headername.sf
l-k- Jan 3, 2024
18a99f6
remove unused variables
l-k- Jan 4, 2024
c3ea42d
these have no point, get overwritten right away
l-k- Jan 5, 2024
97b9aee
temperature is read in readaccfile
l-k- Jan 8, 2024
bd45fb8
update to use.temp made in get_starttime_weekday_meantemp_truncdata w…
l-k- Jan 8, 2024
21b78b1
location of light and temp columns is now standard
l-k- Jan 8, 2024
490489f
XYZ and time columns are now standardized
l-k- Jan 8, 2024
403aa32
if sf is NULL (corrupt file), return right away
l-k- Jan 9, 2024
579f3ac
use same case for "en" column name in metalong?
l-k- Jan 9, 2024
f81ee23
simplify data resampling
l-k- Jan 9, 2024
8033e09
remove remainders of unused resample experiment
l-k- Jan 9, 2024
4c739a0
remove unused variables
l-k- Jan 9, 2024
3ad834f
provide defaults for individual values of filequality
l-k- Jan 9, 2024
6cf6f25
move dynrange manipulation into module using it
l-k- Jan 9, 2024
adbacee
standardize light and temperature
l-k- Jan 10, 2024
5d6de3e
don't convert strings to factors
l-k- Jan 10, 2024
f35c1b2
accessed P$data before file is read by mistake
l-k- Jan 10, 2024
76cb1f5
location of XYZ & temperature columns now standard
l-k- Jan 10, 2024
dc02759
Fix temperature validation
l-k- Jan 11, 2024
7ee045f
dotorcomma doesn't care about timestamps
l-k- Jan 11, 2024
00d9921
GGIRread::readGENEActiv can read fewer pages than requested
l-k- Jan 11, 2024
a52adfb
cleanup
l-k- Jan 11, 2024
adba24f
don't lose data from the last block even if short
l-k- Jan 11, 2024
d35b406
treat short & corrupt files uniformly
l-k- Jan 11, 2024
57eb6cf
rename variable for readability
l-k- Jan 11, 2024
55a2d28
replace cat() with warning()
l-k- Jan 11, 2024
d4a8bbd
cleanup
l-k- Jan 13, 2024
3e53066
deducting NumberOfGaps isn't right
l-k- Jan 13, 2024
cd41e01
fix expected gap durations
l-k- Jan 13, 2024
084b8f9
treat short & corrupt files uniformly for all monitor types
l-k- Jan 15, 2024
bc3e804
always report a short block as last block
l-k- Jan 15, 2024
9336084
don't call rm(P) twice back to back
l-k- Jan 15, 2024
27ba0f3
remove unused parameter
l-k- Jan 16, 2024
4d9e980
adjust windowsizes in a central place
l-k- Jan 16, 2024
5894e52
nonwear windowsize needs to be a multiple of 10
l-k- Jan 16, 2024
d5bc8e2
XYZ, light & temperature inputs should be numeric
l-k- Jan 17, 2024
346f277
Movisens data is read including endpage
l-k- Jan 17, 2024
c897b2d
handle GENEActiv csv deprecation message in central location
l-k- Jan 17, 2024
696c54c
test that Axivity csv can have unix and formatted timestamps
l-k- Jan 17, 2024
2e58e8f
stop for freq==0 in centralized location
l-k- Jan 17, 2024
91ed457
correct timezones of gt3x timestamps
l-k- Jan 18, 2024
839fa39
params_general[["desiredtz"]] default set elsewhere
l-k- Jan 18, 2024
596beac
convert numeric timestamps directly to desiredtz
l-k- Jan 18, 2024
998efc8
desiredtz and configtz are in params_general, not params_rawdata
l-k- Jan 20, 2024
854956c
timezone conversion for Axivity csv
l-k- Jan 21, 2024
9042b26
use standard column locations
l-k- Jan 22, 2024
800d581
fix raw timestamp imputation
l-k- Jan 23, 2024
0d9fbd2
simplify, and ensure exact seq() length
l-k- Jan 23, 2024
c6c59d9
simplify code
l-k- Jan 25, 2024
b612dfd
only match files ending in "acc.bin"
l-k- Jan 25, 2024
4cb78fc
replace dir() with list.dirs() to list directories
l-k- Jan 25, 2024
8e11155
move params_rawdata[["chunksize"]] validation to central location
l-k- Jan 25, 2024
c93d2fc
simplify temperature handling
l-k- Jan 25, 2024
8993b4c
use curly brackets for more than one operation in the if block
l-k- Jan 25, 2024
900a707
move temperature out of timestamp module
l-k- Jan 25, 2024
b9a239e
for most monitor types start timestamp is time[1]
l-k- Jan 26, 2024
caea2b4
force correct timezone on movisens start timestamp
l-k- Jan 26, 2024
c3ee322
use curly brackets for more than one operation in the if block
l-k- Jan 26, 2024
d7ebd3b
cleanup
l-k- Jan 26, 2024
9619be0
no need to worry about factors
l-k- Jan 26, 2024
3214929
names(fc)[NA] is NA, which is of length 1, not 0
l-k- Jan 26, 2024
6bafbc5
timezone conversion for Actigraph csv start time
l-k- Jan 26, 2024
e3621bb
timezone should be correct at this point
l-k- Jan 26, 2024
5ef40c1
starttime is already a POSIXlt object
l-k- Jan 27, 2024
f132e18
starttime now always POSIXlt, so can simplify code
l-k- Jan 27, 2024
fb95632
only call get_starttime_weekday[...]() for i==1
l-k- Jan 27, 2024
bd7d6f0
rename method, to remove meantemp from name
l-k- Jan 27, 2024
2992471
unused variable
l-k- Jan 28, 2024
133e59a
simplify a little
l-k- Jan 28, 2024
0add1e4
no need to convert to matrix
l-k- Jan 29, 2024
19190b5
if endpage is read, endpage=startpage+blocksize-1
l-k- Jan 29, 2024
bf6398a
don't resample more temperature than will be used
l-k- Jan 30, 2024
5c2300b
don't expect factors; meta_temp already data.frame
l-k- Jan 30, 2024
3cd193e
minor cleanup
l-k- Jan 30, 2024
96a0b49
xyz columns aren't always 1:3 now
l-k- Jan 30, 2024
bea96a1
Addressing "as.POSIXlt.numeric 'origin' must be supplied" error on Ub…
l-k- Jan 31, 2024
7a74d2c
Addressing "as.POSIXlt.numeric 'origin' must be supplied" error on Ub…
l-k- Jan 31, 2024
f1ae56c
suppress download status message
l-k- Feb 1, 2024
ff566bc
don't do expensive operation if not needed
l-k- Feb 1, 2024
c482000
don't set colnames on an empty list
l-k- Feb 1, 2024
09bc026
no need to convert to numeric first
l-k- Feb 2, 2024
87d34c8
minor edit
l-k- Feb 2, 2024
42ef147
Allocate metalong light vars even if no temperature
l-k- Feb 3, 2024
88f3905
don't assign colnames if insufficient data read
l-k- Feb 4, 2024
b8b4d37
rbind *super* expensive on data.frames; use matrix
l-k- Feb 5, 2024
42d4aff
convert time and wear to numeric
l-k- Feb 6, 2024
0eeaf6d
fix useNA parameter for table()
l-k- Feb 6, 2024
04f6c53
add test for processing of wear column
l-k- Feb 6, 2024
8695c06
remove unused test file ax3test.wav
l-k- Feb 6, 2024
e8918fa
shorten Axivity csv test files
l-k- Feb 6, 2024
b63d26a
wear column can stay numeric. We convert the result to numeric by mul…
l-k- Feb 6, 2024
3ce6487
don't add 1 to hoc1. We add 1 to it when we use it
l-k- Feb 6, 2024
e6b68d7
reverting unnecessary change
l-k- Feb 6, 2024
53dfbf9
readacctife returns Unix timestamps, so read.myacc should too
l-k- Feb 7, 2024
d2d6b31
clean up resampling
l-k- Feb 7, 2024
d067fca
Addressing "as.POSIXct/lt.numeric 'origin' must be supplied" error on…
l-k- Feb 7, 2024
d397378
hardcoded windowsizes in g.calibrate, factor out g.downsample, and ti…
vincentvanhees Feb 7, 2024
829761d
warn if files were skipped due to small size
l-k- Feb 7, 2024
8f308ad
P gets reused to store g.imputeTimegaps() output
l-k- Feb 7, 2024
f340f3a
Merge pull request #1038 from wadpac/PR1027_revised_gcalibrate
l-k- Feb 7, 2024
6504623
use lubridate::force_tz b/c as.POSIXlt is expensive
l-k- Feb 9, 2024
b195521
move the call to g.dotorcomma() into g.inspectfile
l-k- Feb 9, 2024
d52a43e
call gc() fewer times per loop iteration
l-k- Feb 9, 2024
186e357
minor cleanup
l-k- Feb 9, 2024
c2b7f61
commenting out GENEA settings, as it's deprecated
l-k- Feb 11, 2024
d1ba2b3
clean up comment
l-k- Feb 11, 2024
23f4223
warn regardless of verbose status
l-k- Feb 11, 2024
ceb4b75
Merge branch 'master' into part1-simplification-v2
l-k- Feb 11, 2024
1ff74a7
select[1:(length(select))] is the same as select
l-k- Feb 12, 2024
5f245d2
if S is one row, process it correctly
l-k- Feb 12, 2024
b11c16f
Fix C$use.temp retrieval and get C$meantempcal
l-k- Feb 13, 2024
47fdd94
issue 1042, align ws and ws2
l-k- Feb 14, 2024
23a768d
Update NEWS.md
l-k- Feb 15, 2024
4b4f330
no need to reuse values from past calls b/c this method now only cal…
l-k- Feb 16, 2024
e235b85
deal with badly formatted timestamps in Axivity csv
l-k- Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ URL: https://github.com/wadpac/GGIR/, https://groups.google.com/forum/#!forum/Rp
BugReports: https://github.com/wadpac/GGIR/issues
License: Apache License (== 2.0) | file LICENSE
Suggests: testthat, covr, knitr, rmarkdown, actilifecounts, ActCR, GGIRread, read.gt3x, readxl
Imports: data.table, foreach, doParallel, signal, zoo, unisensR, ineq, methods, psych, irr
Imports: data.table, foreach, doParallel, signal, zoo, unisensR, ineq, methods, psych, irr, lubridate
Depends: stats, utils, R (>= 3.5)
VignetteBuilder: knitr
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export(g.analyse, g.calibrate,
GGIR, g.shell.GGIR, g.getbout,
g.abr.day.names,
g.applymetrics, g.create.sp.mat, g.detecmidnight,
g.dotorcomma, g.downsample, g.extractheadervars,
g.dotorcomma, g.extractheadervars,
g.getM5L5,
g.getstarttime, g.loadlog,
g.plot5, g.readaccfile,
Expand All @@ -24,7 +24,7 @@ export(g.analyse, g.calibrate,
g.part5.addsib, g.part5.definedays,
g.part5.fixmissingnight, g.part5.onsetwaketiming,
g.part5.wakesleepwindows, g.part5.savetimeseries,
get_nw_clip_block_params, get_starttime_weekday_meantemp_truncdata,
get_nw_clip_block_params, get_starttime_weekday_truncdata,
ismovisens, g.readtemp_movisens,
g.conv.actlog, g.fragmentation,
g.intensitygradient, g.part5.handle_lux_extremes,
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# CHANGES IN GGIR VERSION 3.0-6

Part 1:

- Improved readability and maintainability of the code #1027

- Improved processing speed for Axivity .cwa, GENEActiv .bin, and Movisens files

- Made sure that g.readaccfile() reads timestamps in the correct timezone, configtz, for all monitor types

- Note: there will be small differences in both metalong and metashort metrics calculated by this GGIR version, compared to prior versions. This is due to small improvements in the management of timestamps, calibration coefficients, and input data block boundaries.

# CHANGES IN GGIR VERSION 3.0-5

- Part 5: Fix bug in functionality for Sensewear data (externally derived epoch data) #1030
Expand Down
26 changes: 26 additions & 0 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ check_params = function(params_sleep = c(), params_metrics = c(),
check_class("Raw data", params = params_rawdata, parnames = numeric_params, parclass = "numeric")
check_class("Raw data", params = params_rawdata, parnames = boolean_params, parclass = "boolean")
check_class("Raw data", params = params_rawdata, parnames = character_params, parclass = "character")

if (params_rawdata[["chunksize"]] > 1.5) params_rawdata[["chunksize"]] = 1.5
if (params_rawdata[["chunksize"]] < 0.2) params_rawdata[["chunksize"]] = 0.2
}
if (length(params_247) > 0) {
# iglevels and qwindow can be numeric or character, so not tested
Expand Down Expand Up @@ -127,6 +130,29 @@ check_params = function(params_sleep = c(), params_metrics = c(),
check_class("general", params = params_general, parnames = numeric_params, parclass = "numeric")
check_class("general", params = params_general, parnames = boolean_params, parclass = "boolean")
check_class("general", params = params_general, parnames = character_params, parclass = "character")

ws3 = params_general[["windowsizes"]][1]; ws2 = params_general[["windowsizes"]][2]; ws = params_general[["windowsizes"]][3]
if (ws2/60 != round(ws2/60)) {
ws2 = as.numeric(60 * ceiling(ws2/60))
warning(paste0("The long windowsize needs to be a multitude of 1 minute periods.\n",
"Long windowsize has now been automatically adjusted to ",
ws2, " seconds in order to meet this criteria."), call. = FALSE)
}
if (ws2/ws3 != round(ws2/ws3)) {
def = c(1,5,10,15,20,30,60)
def2 = abs(def - ws3)
ws3 = as.numeric(def[which(def2 == min(def2))])
warning(paste0("The long windowsize needs to be a multitude of short windowsize.\n",
"The short windowsize has now been automatically adjusted to ",
ws3, " seconds in order to meet this criteria.\n"), call. = FALSE)
}
if (ws/ws2 != round(ws/ws2)) {
ws = ws2 * ceiling(ws/ws2)
warning(paste0("The third value of parameter windowsizes needs to be a multitude of the second value.\n",
"The third value has been automatically adjusted to ",
ws, " seconds in order to meet this criteria.\n"), call. = FALSE)
}
params_general[["windowsizes"]] = c(ws3, ws2, ws)
}
#-----------------------------------------------------------------------------------
# Check value combinations and apply corrections if not logical
Expand Down
26 changes: 18 additions & 8 deletions R/datadir2fnames.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ datadir2fnames = function(datadir,filelist) {
}
} else {
if (ismovisens(datadir)) {
fnamesfull = dir(datadir, recursive = TRUE, pattern = "acc.bin", full.names = TRUE)
fnames = basename(dirname(fnamesfull))
nfolders = length(dir(datadir))
if (nfolders > length(fnamesfull)) { # meaning there are movisens data folder without acc.bin
# folders without acc.bin
allfolders = dir(datadir, full.names = TRUE)
foldersWithAccBin = dirname(fnamesfull)
noAccBin = allfolders[which(!allfolders %in% foldersWithAccBin)]
fnamesfull = dir(datadir, recursive = TRUE, pattern = "acc.bin$", full.names = TRUE)
foldersWithAccBin = dirname(fnamesfull)
fnames = basename(foldersWithAccBin)

allfolders = list.dirs(datadir, recursive=FALSE, full.names = TRUE)

# are there any folders that don't contain acc.bin (directly, or in any subfolders)?
noAccBin = c()
for (fld in allfolders) {
if (fld %in% foldersWithAccBin) next # folder contains acc.bin

# do any subfolders contain acc.bin?
if (!any(grepl(paste(fld, '/', sep = ''), foldersWithAccBin))) {
noAccBin = c(noAccBin, fld)
}
}

if (length(noAccBin) > 0) {
warning(paste0("The following movisens data folders do not contain the ",
"acc.bin file with the accelerometer recording, and ",
"therefore cannot be processed in GGIR: ",
Expand Down
32 changes: 13 additions & 19 deletions R/detect_nonwear_clipping.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ detect_nonwear_clipping = function(data = c(), windowsizes = c(5, 900, 3600), sf
CWav = NWav = rep(0, nmin)
crit = ((window/window2)/2) + 1

if (is.numeric(data[,1]) == FALSE) {
data[,1] = as.numeric(data[,1])
data[,2] = as.numeric(data[,2])
data[,3] = as.numeric(data[,3])
}
if (nonwear_approach %in% c("2013", "2023")) {
# define windows to check:
for (h in 1:nmin) { #number of windows
Expand Down Expand Up @@ -43,25 +38,24 @@ detect_nonwear_clipping = function(data = c(), windowsizes = c(5, 900, 3600), sf
NWflag = h:(h + window/window2 - 1)
if (NWflag[length(NWflag)] > nmin) NWflag = NWflag[-which(NWflag > nmin)]
# window to check (not aggregated values)
hoc1 = h * window2 - window2 + 1
hoc2 = hoc1 + window - 1
hoc1 = h * window2 - window2
hoc2 = hoc1 + window
if (hoc2 > nrow(data)) {
hoc2 = nrow(data)
}
}
# ---
if (length(params_rawdata[["rmc.col.wear"]]) > 0) {
wearcol = as.character(data[, which(colnames(data) == "wear")])
suppressWarnings(storage.mode(wearcol) <- "logical")
wearTable = table(wearcol[(1 + hoc1):hoc2], useNA = FALSE)
NWav[h] = as.logical(tail(names(sort(wearTable)), 1)) * 3 # times 3 to simulate heuristic approach
if ("wear" %in% colnames(data)) {
wearTable = table(data[(1 + hoc1):hoc2, "wear"], useNA = "no")
NWav[h] = as.numeric(tail(names(sort(wearTable)), 1)) * 3 # times 3 to simulate heuristic approach
}
for (jj in 1:3) {
xyzCol = which(colnames(data) %in% c("x", "y", "z"))
for (jj in seq(3)) {
# Clipping
aboveThreshold = which(abs(data[(1 + cliphoc1):cliphoc2, jj]) > clipthres)
aboveThreshold = which(abs(data[(1 + cliphoc1):cliphoc2, xyzCol[jj]]) > clipthres)
CW[h, jj] = length(aboveThreshold)
if (length(aboveThreshold) > 0) {
if (length(which(abs(data[c((1 + cliphoc1):cliphoc2)[aboveThreshold],jj]) > clipthres * 1.5)) > 0) {
if (length(which(abs(data[c((1 + cliphoc1):cliphoc2)[aboveThreshold], xyzCol[jj]]) > clipthres * 1.5)) > 0) {
CW[h, jj] = window2 # If there is a a value that is more than 150% the dynamic range then ignore entire block.
}
}
Expand All @@ -73,18 +67,18 @@ detect_nonwear_clipping = function(data = c(), windowsizes = c(5, 900, 3600), sf
} else if (nonwear_approach == "2023") {
indices = seq((1 + hoc1), hoc2, by = ceiling(sf / 5))
}
maxwacc = max(data[indices, jj], na.rm = TRUE)
minwacc = min(data[indices, jj], na.rm = TRUE)
maxwacc = max(data[indices, xyzCol[jj]], na.rm = TRUE)
minwacc = min(data[indices, xyzCol[jj]], na.rm = TRUE)
absrange = abs(maxwacc - minwacc)
if (absrange < racriter) {
sdwacc = sd(data[indices,jj], na.rm = TRUE)
sdwacc = sd(data[indices, xyzCol[jj]], na.rm = TRUE)
if (sdwacc < sdcriter) {
NW[NWflag,jj] = 1
}
}
}
CW = CW / (window2)
if (length(params_rawdata[["rmc.col.wear"]]) == 0) {
if (!("wear" %in% colnames(data))) {
NWav[h] = (NW[h,1] + NW[h,2] + NW[h,3]) #indicator of non-wear
}
CWav[h] = max(c(CW[h, 1], CW[h, 2], CW[h, 3])) #indicator of clipping
Expand Down
4 changes: 3 additions & 1 deletion R/g.applymetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ g.applymetrics = function(data, sf, ws3, metrics2do,
zc.lb = 0.25, zc.hb = 3, zc.sb = 0.01,
zc.order = 2,
actilife_LFE = FALSE){
# data should be a 3 column matrix with the x, y, and z acceleration
data = data[, c("x", "y", "z")]

epochsize = ws3 #epochsize in seconds
# data is a 3 column matrix with the x, y, and z acceleration
do.bfen = metrics2do$do.bfen
do.enmo = metrics2do$do.enmo
do.lfenmo = metrics2do$do.lfenmo
Expand Down
Loading