Skip to content

Commit

Permalink
Enable g.calibrate to handle temperature data from ad-hoc csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
l-k- committed Dec 13, 2023
1 parent ededec3 commit cc12bf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions R/g.calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Check warning on line 144 in R/g.calibrate.R

View check run for this annotation

Codecov / codecov/patch

R/g.calibrate.R#L144

Added line #L144 was not covered by tests
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

Check warning on line 151 in R/g.calibrate.R

View check run for this annotation

Codecov / codecov/patch

R/g.calibrate.R#L149-L151

Added lines #L149 - L151 were not covered by tests
} else {
use.temp = FALSE

Check warning on line 153 in R/g.calibrate.R

View check run for this annotation

Codecov / codecov/patch

R/g.calibrate.R#L153

Added line #L153 was not covered by tests
}
data = P$data[, columns_to_use]
} else if (dformat == FORMAT$GT3X) {
data = as.matrix(P[,2:4])
Expand Down Expand Up @@ -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
Expand All @@ -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

Check warning on line 225 in R/g.calibrate.R

View check run for this annotation

Codecov / codecov/patch

R/g.calibrate.R#L225

Added line #L225 was not covered by tests
temperature = as.numeric(data[,temperaturecolumn])
} else if (mon == MONITOR$ACTIGRAPH) {
use.temp = FALSE
Expand Down

0 comments on commit cc12bf8

Please sign in to comment.