-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't resample more temperature than will be used
GGIRread::resample is very expensive, and we were resampling *all* of the temperature every time we needed to read a block of it. This edit makes g.readaccfile for movisens got 2x faster.
- Loading branch information
Showing
3 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
g.readtemp_movisens = function(datafile, from = c(), to = c(), interpolationType=1) { | ||
g.readtemp_movisens = function(datafile, from = c(), to = c(), acc_sf, acc_length, interpolationType=1) { | ||
# Acceleration data and temperature were sampled at different rates, | ||
# so we need to resample temperature to get the same sampling rate | ||
# as what we have for acceleration. | ||
|
||
temperature = unisensR::readUnisensSignalEntry(dirname(datafile), "temp.bin") | ||
temp_sf = 1 # temperature is most likely sampled at 1Hz, but we'll double-check later | ||
|
||
temp_from = ceiling(from / acc_sf * temp_sf) | ||
temp_to = ceiling(to / acc_sf * temp_sf) | ||
|
||
temperature = unisensR::readUnisensSignalEntry(dirname(datafile), "temp.bin", | ||
startIndex = temp_from, endIndex = temp_to) | ||
new_temp_sf = attr(temperature, "sampleRate") | ||
|
||
# We had guessed that temperature was sampled at 1Hz. Let's check, and if we were wrong, then re-do. | ||
if (temp_sf != new_temp_sf) { | ||
temp_from = ceiling(from / acc_sf * new_temp_sf) | ||
temp_to = ceiling(to / acc_sf * new_temp_sf) | ||
|
||
temperature = unisensR::readUnisensSignalEntry(dirname(datafile), "temp.bin", | ||
startIndex = temp_from, endIndex = temp_to) | ||
} | ||
|
||
temperature = temperature$temp | ||
|
||
# we don't care about the exact timestamp values because we'll throw the timestamps away anyway. | ||
rawTime = seq_len(length(temperature)) | ||
|
||
acc_length = unisensR::getUnisensSignalSampleCount(dirname(datafile), "acc.bin") | ||
timeRes = seq(from = 1, to = rawTime[length(rawTime)], length.out = acc_length) | ||
|
||
temperature = GGIRread::resample(as.matrix(temperature), rawTime, timeRes, length(temperature), type=interpolationType) | ||
|
||
if(length(from) > 0 && length(to) > 0) { | ||
temperature = temperature[from:to] | ||
} | ||
|
||
invisible(temperature) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters