From 8ee7673ce6d57a27c32670c012e88cf71a485033 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Tue, 12 Dec 2023 17:47:06 +0100 Subject: [PATCH] fixes #991 --- NEWS.md | 2 ++ R/g.calibrate.R | 14 ++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0c0097049..fc18d4dc6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ - Part 5: Fix bug in recently added fucntionality for studying overlap between sibs and self-reported beahviours #989. +- Part 1: Fix bug in adhoc-csv format calibration process as it could not extract temperature column #991 + # CHANGES IN GGIR VERSION 3.0-1 - Part 2: Added option to provide a csv file with start and end dates when accelerometer is expected to be worn #943 diff --git a/R/g.calibrate.R b/R/g.calibrate.R index 96353164a..01463e774 100644 --- a/R/g.calibrate.R +++ b/R/g.calibrate.R @@ -141,12 +141,7 @@ g.calibrate = function(datafile, params_rawdata = c(), data = P$data } } else if (dformat == FORMAT$AD_HOC_CSV) { - if (length(params_rawdata[["rmc.col.time"]]) > 0 && mon == MONITOR$AD_HOC) { - columns_to_use = 2:4 - } else { - columns_to_use = 1:3 - } - data = P$data[, columns_to_use] + data = P$data[, c(params_rawdata[["rmc.col.acc"]], params_rawdata[["rmc.col.temp"]])] } else if (dformat == FORMAT$GT3X) { data = as.matrix(P[,2:4]) } @@ -195,7 +190,6 @@ g.calibrate = function(datafile, params_rawdata = c(), use.temp = TRUE } else if (mon == MONITOR$AD_HOC && dformat == FORMAT$AD_HOC_CSV && length(params_rawdata[["rmc.col.temp"]]) > 0) { # ad-hoc format csv with temperature Gx = as.numeric(data[,1]); Gy = as.numeric(data[,2]); Gz = as.numeric(data[,3]) - temperature = as.numeric(data[, params_rawdata[["rmc.col.temp"]]]) use.temp = TRUE } else if (mon == MONITOR$AD_HOC && dformat == FORMAT$AD_HOC_CSV && length(params_rawdata[["rmc.col.temp"]]) == 0) { # ad-hoc format csv without temperature Gx = as.numeric(data[,1]); Gy = as.numeric(data[,2]); Gz = as.numeric(data[,3]) @@ -205,11 +199,10 @@ g.calibrate = function(datafile, params_rawdata = c(), if (ncol(data) == 3) extra = 0 if (ncol(data) >= 4) extra = 1 for (jij in 1:3) { - data2[,jij] = data[,(jij+extra)] + data2[, jij] = data[, (jij + extra)] } Gx = data[,1]; Gy = data[,2]; Gz = data[,3] } - if (mon == MONITOR$GENEACTIV) { if ("temperature" %in% colnames(data)) { temperaturecolumn = which(colnames(data) == "temperature") #GGIRread @@ -221,7 +214,8 @@ g.calibrate = function(datafile, params_rawdata = c(), temperaturecolumn = 5 temperature = as.numeric(data[,temperaturecolumn]) } else if (mon == MONITOR$AD_HOC && use.temp == TRUE) { - temperaturecolumn = params_rawdata[["rmc.col.temp"]] + temperaturecolumn = which(names(data) == "temperature") + if (length(temperaturecolumn) == 0) temperaturecolumn = 4 temperature = as.numeric(data[,temperaturecolumn]) } else if (mon == MONITOR$ACTIGRAPH) { use.temp = FALSE