From cc12bf832949ca5201a6f4249fa5b1ecf8829eb9 Mon Sep 17 00:00:00 2001 From: l-k- Date: Wed, 13 Dec 2023 01:25:16 -0500 Subject: [PATCH] Enable g.calibrate to handle temperature data from ad-hoc csv file --- NEWS.md | 2 ++ R/g.calibrate.R | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0c0097049..9812ab8bc 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..f6888696c 100644 --- a/R/g.calibrate.R +++ b/R/g.calibrate.R @@ -141,11 +141,17 @@ 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) { + if ("timestamp" %in% colnames(P$data)) { columns_to_use = 2:4 } else { columns_to_use = 1:3 } + if ("temperature" %in% colnames(P$data)) { + columns_to_use = c(columns_to_use, which(colnames(P$data) == "temperature")) + use.temp = TRUE + } else { + use.temp = FALSE + } data = P$data[, columns_to_use] } else if (dformat == FORMAT$GT3X) { data = as.matrix(P[,2:4]) @@ -193,13 +199,8 @@ g.calibrate = function(datafile, params_rawdata = c(), } else if (mon == MONITOR$MOVISENS) { Gx = data[,1]; Gy = data[,2]; Gz = data[,3] 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 + } else if (dformat == FORMAT$AD_HOC_CSV) { Gx = as.numeric(data[,1]); Gy = as.numeric(data[,2]); Gz = as.numeric(data[,3]) - use.temp = FALSE } else if (dformat == FORMAT$CSV && mon != MONITOR$AXIVITY) { # csv and not AX (so, GENEAcitv) data2 = matrix(NA,nrow(data),3) if (ncol(data) == 3) extra = 0 @@ -220,8 +221,8 @@ g.calibrate = function(datafile, params_rawdata = c(), } else if (mon == MONITOR$AXIVITY && dformat == FORMAT$CWA) { temperaturecolumn = 5 temperature = as.numeric(data[,temperaturecolumn]) - } else if (mon == MONITOR$AD_HOC && use.temp == TRUE) { - temperaturecolumn = params_rawdata[["rmc.col.temp"]] + } else if (dformat == FORMAT$AD_HOC_CSV && use.temp == TRUE) { + temperaturecolumn = 4 temperature = as.numeric(data[,temperaturecolumn]) } else if (mon == MONITOR$ACTIGRAPH) { use.temp = FALSE