Skip to content

Commit 04e19f8

Browse files
authored
Issue58 actigraph idle sleep (#59)
Fixes #58 => there was a bug when reading ActiGraph data with the idle sleep mode activated, now this is resolved. Fixes #60 => now actimetric uses the date of the following noon to the wake-up time as indicator of the night for the day-level summaries. Fixes #61 => numeric columns in features matrix are no longer rounded to 3 decimal places.
2 parents d0a1528 + 731000e commit 04e19f8

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LazyData: true
2020
Suggests:
2121
testthat (>= 3.0.0), randomForest, gsignal, rattle
2222
Config/testthat/edition: 3
23-
RoxygenNote: 7.3.1
23+
RoxygenNote: 7.3.2
2424
Depends:
2525
R (>= 2.10)
2626
Imports:

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# actimetric 0.1.4
22

3-
* Time series: stores classes as factor in time series to ease interpretation #51
3+
* Time series:
4+
- stores classes as factor in time series to ease interpretation #51
5+
- fixed minor bug related to assignation of date to sleep periods #60
46
* Documentation: minor revision of documentation for functions check_classifier and getBout #41
7+
* Reading data: minor revision of ReadAndCalibrate when reading ActiGraph devices with the Idle Sleep Mode activated #58
8+
* Feature extraction: numeric features are no longer rounded to 3 decimal places #61
59

610
# actimetric 0.1.3
711

R/ReadAndCalibrate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ReadAndCalibrate = function(file, sf, blocksize, blocknumber, inspectfileobject,
131131
if (ncol(S) == (ncol(data) - 1)) {
132132
# this block has time gaps while the previous block did not
133133
S = cbind(S, 1)
134-
colnames(S)[4] = "remaining_epochs"
134+
colnames(S)[ncol(S)] = "remaining_epochs"
135135
}
136136
} else if ("remaining_epochs" %in% colnames(S)) {
137137
if ((ncol(S) - 1) == ncol(data)) {

R/aggregate_per_date.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ aggregate_per_date = function(tsDir, epoch, classifier, classes,
104104
return(list(starts = starts, ends = ends))
105105
}
106106
if ("nighttime.awake" %in% classes) {
107+
noons = which(ts$time == "12:00:00")
107108
start_end_nighttime = find_start_end(ts, column = "activity",
108109
class = c("nighttime.awake", "nighttime.sleep"))
109-
start_end_nighttime_dates = ts$date[start_end_nighttime$ends] # dates based on wakeup
110+
start_end_nighttime_dates = NULL
111+
for (ni in 1:length(start_end_nighttime$ends)) {
112+
next_noon = which(noons > start_end_nighttime$ends[ni])[1]
113+
start_end_nighttime_dates[ni] = ts$date[noons[next_noon]]
114+
}
115+
# start_end_nighttime_dates = ts$date[start_end_nighttime$ends] # dates based on wakeup
110116
rows2fill = which(availableDates %in% start_end_nighttime_dates)
111117
ds[rows2fill, ci] = as.character(ts$timestamp[start_end_nighttime$starts])
112118
ds[rows2fill, ci + 1] = as.character(ts$timestamp[start_end_nighttime$ends])

R/classify.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ classify = function(data = NULL, parameters = NULL, sf = NULL,
7373
ts = as.data.frame(cbind(subject, timestamp, ts))
7474
}
7575
# round numeric columns
76-
numeric_columns = sapply(ts, mode) == 'numeric'
77-
ts[numeric_columns] = round(ts[numeric_columns], 3)
7876
ts = do.call(data.frame,lapply(ts, function(x) replace(x, is.infinite(x), NA)))
7977
ts[is.na(ts)] = 0
8078
# -------------------------------------------------------------------------

R/classifySleep.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ classifySleep = function(anglez, starttime, classifier, infoClassifier, ts, do.s
129129
ts$activity[which(ts$sleep_periods == 1)] = sleep_id
130130
}
131131
}
132+
# recode nighttime as nighttime.awake and sleep as nighttime.sleep
133+
classes = gsub("nighttime", "nighttime.awake", classes)
134+
classes = gsub("sleep", "nighttime.sleep", classes)
132135
activity = factor(x = ts$activity, levels = 1:length(classes), labels = classes)
133136
return(activity)
134137
}

R/runActimetric.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
217217
hvars = GGIR::g.extractheadervars(I)
218218
sf = I$sf
219219
# Extract parameters for reading file in chunks as in GGIR R package
220-
readParams = GGIR::get_nw_clip_block_params(chunksize = 1, dynrange = 8,
221-
monc = I$monc, dformat = I$dformc,
222-
sf = sf, rmc.dynamic_range = NULL)
220+
# the if statement makes this flexible to adapt to different GGIR versions
221+
if ("chunksize" %in% names(as.list(args(GGIR::get_nw_clip_block_params)))) {
222+
readParams = GGIR::get_nw_clip_block_params(chunksize = 1, dynrange = 8,
223+
monc = I$monc, dformat = I$dformc,
224+
sf = sf, rmc.dynamic_range = NULL)
225+
} else {
226+
readParams = GGIR::get_nw_clip_block_params(monc = I$monc, dformat = I$dformc,
227+
sf = sf, params_rawdata = GGIR::load_params()$params_rawdata)
228+
}
223229
blocksize = readParams$blocksize
224230
isLastBlock = FALSE
225231
blocknumber = 1; iteration = 1
@@ -281,6 +287,8 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
281287
nw = rep(0, nrow(data) / (epoch*sf))
282288
}
283289
}
290+
} else {
291+
nw = rep(0, nrow(data) / (epoch*sf))
284292
}
285293
nonwear = c(nonwear, nw)
286294
# enmo per epoch

0 commit comments

Comments
 (0)