skdh.preprocessing.CalibrateAccelerometer#
- class skdh.preprocessing.CalibrateAccelerometer(sphere_crit=0.3, min_hours=72, sd_criteria=0.013, max_iter=1000, tol=1e-10)#
Calibrate pre-recording acceleration readings based on the deviation from 1G when motionless. Acceleration values can be modified in place. Calibration typically requires a minimum amount of data, which can be adjusted to more than the lower limit of 12 hours. If the minimum time specified is not enough, calibration will incrementally use more data until either the criteria are met, or all the data is used.
- Parameters:
- sphere_critfloat, optional
Minimum acceleration value (in g) on both sides of 0g for each axis. Determines if the sphere is sufficiently populated to obtain a meaningful calibration result. Default is 0.3g.
- min_hoursint, optional
Ideal minimum hours of data to use for the calibration. Any values not factors of 12 are rounded up to the nearest factor. Default is 72. If less than this amout of data is avialable (but still more than 12 hours), calibration will still be performed on all the data. If the calibration error is not under 0.01g after these hours, more data will be used in 12 hour increments.
- sd_criteriafloat, optional
The criteria for the rolling standard deviation to determine stillness, in g. This value will likely change between devices. Default is 0.013g, which was found for GeneActiv devices. If measuring the noise in a bench-top test, this threshold should be about 1.2 * noise.
- max_iterint, optional
Maximum number of iterations to perform during calibration. Default is 1000. Generally should be left at this value.
- tolfloat, optional
Tolerance for stopping iteration. Default is 1e-10. Generally this should be left at this value.
Methods
convert_timestamps(t)Convert a timestamp/array of timestamps to a datetime object
predict(*, time, accel[, fs, apply, temperature])Run the calibration on the accelerometer data.
save_results(results, file_name)Save the results of the processing pipeline to a csv file
Notes
This calibration relies on the assumption that a perfectly calibrated accelerometer’s acceleration readings will lie on the unit sphere when motionless. Therefore, this calibration enforces that constraint on motionless data present in the recording to its best ability.
References
[1]V. T. van Hees et al., “Autocalibration of accelerometer data for free-living physical activity assessment using local gravity and temperature: an evaluation on four continents,” Journal of Applied Physiology, vol. 117, no. 7, pp. 738–744, Aug. 2014, doi: 10.1152/japplphysiol.00421.2014.
- predict(*, time, accel, fs=None, apply=True, temperature=None)#
Run the calibration on the accelerometer data.
- Parameters:
- timenumpy.ndarray
(N, ) array of unix timestamps, in seconds.
- accelnumpy.ndarray
(N, 3) array of accelerations measured by centrally mounted lumbar device, in units of ‘g’.
- fsfloat, optional
Sampling frequency in Hz. If not provided, it is calculated from the timestamps.
- applybool, optional
Apply the calibration to the acceleration. Default is True. Both cases return the scale, offset, and temperature scale in the return dictionary.
- temperaturenumpy.ndarray
(N, ) array of temperature measured by the sensor.
- Returns:
- resultsdictionary
Returns input data, as well as the acceleration scale, acceleration offset, and temperature scale.
Notes
The scaling factors are applied as follows:
\[a_i(t) = (y_i(t) + d_i)s_i + (T(t) - \bar{T}_c)m_i\]where \(a_i\) is the corrected acceleration in the ith axis, \(t\) is a time point, \(y_i\) is the measured accleration in the ith axis, \(d_i\) is the offset for the ith axis, \(s_i\) is the scale for the ith axis. If available, \(T\) is the sensor measured temperature, \(\bar{T}_c\) is the mean temperature from the calibration, and \(m_i\) is the temperature scale for the ith axis.