childmindresearch / wristpy

https://childmindresearch.github.io/wristpy/
GNU Lesser General Public License v2.1
5 stars 5 forks source link

Task: Integrating temperature information #14

Open Asanto32 opened 7 months ago

Asanto32 commented 7 months ago

Description

We will use the temperature data (curently for GENEActiv watches only) to facilitate non-wear detection. The algorithm described in this paper was shown to out-perform an acceleration only non-wear detection algorithm (as we have currently implemented).

Briefly the algorithm can be defined as:

A summary of the pseudo -code can be found here. This study used a time window of 1-minute resolution, with a 1-s step, which is a much finer resolution than the GGIR implementation. The thresholds for acceleration and temperature are listed as 13mg, and 26C, respectively.

Tasks

Freeform Notes

No response

Asanto32 commented 7 months ago

Why is temperature used in calibration? It appears to be a comparison to the mean temperature, but this is not a ground truth? Debatable on whether this should be used, in my opinion?

Asanto32 commented 1 month ago

Another temperature based non-wear detection can be found here (more simple than DETACH algo): https://bmjopen.bmj.com/content/5/5/e007447

Asanto32 commented 2 weeks ago

Current thoughts, modify the CTA (above Zhou paper) algorithm to include rate-of-change criteria from DETACH algorithm.

Change the criteria:

if mean_temp < low_temp_threshold:
...
  if mean_temp < mean_temp_previous:
    nonwear[i] = 1

where low_temp_threshold is 26C (default).

To something more like:

if (mean_temp < high_temp) and (rate_of_change < temp_dec_rate):
  nonwear[i] = 1

Perhaps also change:

        if mean_temp < temperature_threshold and (accel_value >= 2):
            nonwear_value_array[window_n] = 1

to:

        if (mean_temp < temperature_threshold or rate_of_change < temp_dec_rate) and (accel_value >= 2):
            nonwear_value_array[window_n] = 1
Asanto32 commented 2 weeks ago

FYI this is what the code block would look like to use the scikit DETACH algorithm + convert results to array. Could obviously be re-organized since we already do the actfast read and have all the sensor data, would just need to convert time back to unix from the datetime.

import skdh
import actfast
from scipy.interpolate import interp1d
from wristpy.io.readers import readers

adam_data = actfast.read("/Users/adam.santorelli/Downloads/adam_three_nights.bin")

time = adam_data["timeseries"]["high_frequency"]["datetime"]
acceleration = adam_data["timeseries"]["high_frequency"]["acceleration"]
temperature = adam_data["timeseries"]["low_frequency"]["temperature"]
detach_class = skdh.preprocessing.DETACH(sd_thresh=0.013)

x_arr1 = np.linspace(0, 1, len(temperature))
x_arr2 = np.linspace(0, 1, len(acceleration))
f = interp1d(x_arr1, temperature)
upsample_temp= f(x_arr2)

detach_wear = detach_class.predict(time = time/1e9, accel = acceleration, temperature=upsample_temp)

nonwear_array = np.ones(len(time), dtype=np.float32)

for start, stop in detach_wear["wear"]:
    nonwear_array[start:stop] = 0
time_detach = readers.unix_epoch_time_to_polars_datetime(time)