Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable g.calibrate to handle temperature data from ad-hoc csv file #992

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 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
14 changes: 4 additions & 10 deletions R/g.calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@
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"]])]

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
Copy link
Collaborator

@l-k- l-k- Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might actually be incorrect?

We get P$data from read.myacc.csv, and there it gets populated with columns c("timestamp","accx","accy","accz","temperature"), in that exact order. You can see it here:
https://github.com/wadpac/GGIR/blob/master/R/read.myacc.csv.R#L172-L179

So it doesn't matter where the acceleration and temperature columns were located in the original csv file. P$data$temperature is always 4th or 5th column (depending on whether there is a timestamp column), no matter what params_rawdata[["rmc.col.temp"]] value was. And acceleration columns are always either 1:3 or 2:4, no matter what params_rawdata[["rmc.col.acc"]] values were.

It was just a coincidence that our test file had rmc.col.acc = 2:4, rmc.col.temp = 5, like what read.myacc.csv produces.

I'll send an alternative PR in a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting that Lena, I will now close this PR.

} else if (dformat == FORMAT$GT3X) {
data = as.matrix(P[,2:4])
}
Expand Down Expand Up @@ -195,7 +190,6 @@
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])
Expand All @@ -205,11 +199,10 @@
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
Expand All @@ -221,7 +214,8 @@
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

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

View check run for this annotation

Codecov / codecov/patch

R/g.calibrate.R#L217-L218

Added lines #L217 - L218 were not covered by tests
temperature = as.numeric(data[,temperaturecolumn])
} else if (mon == MONITOR$ACTIGRAPH) {
use.temp = FALSE
Expand Down
Loading