skills/timeseries/imu-gravity-removal/SKILL.md
Remove gravity component from raw accelerometer data using quaternion rotation to yield linear acceleration
npx skillsauth add wenmin-wu/ds-skills timeseries-imu-gravity-removalInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Raw accelerometer readings include gravitational acceleration (~9.81 m/s^2). Use the device's quaternion orientation to rotate the world-frame gravity vector into sensor frame, then subtract it. Essential preprocessing for any wearable/IMU activity recognition task.
import numpy as np
from scipy.spatial.transform import Rotation as R
def remove_gravity(acc_xyz, quaternions, g=9.81):
"""Remove gravity from accelerometer using quaternion orientation.
Args:
acc_xyz: (N, 3) raw accelerometer [x, y, z]
quaternions: (N, 4) orientation [x, y, z, w]
Returns:
(N, 3) linear acceleration
"""
gravity_world = np.array([0, 0, g])
linear = np.zeros_like(acc_xyz)
for i in range(len(acc_xyz)):
rot = R.from_quat(quaternions[i])
gravity_sensor = rot.apply(gravity_world, inverse=True)
linear[i] = acc_xyz[i] - gravity_sensor
return linear
[x, y, z, w] — check your sensor's conventionR.from_quat(all_quats).apply(gravity, inverse=True) for speeddata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF