Created
January 11, 2021 15:19
-
-
Save papr/a83c1453e83a39c17123d246be93599e to your computer and use it in GitHub Desktop.
Loads Pupil Mobile IMu data into a pandas dataframe
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
import numpy as np | |
import pandas as pd | |
G = 9.78033 | |
IMU_TYPE = np.dtype([ | |
("time_s", "<f8"), | |
*((f"accel_{d}", "<f4") for d in "xyz"), | |
*((f"gyro_{d}", "<f4") for d in "xyz") | |
]) | |
def load_imu(imu_path): | |
return np.fromfile(imu_path, IMU_TYPE) | |
def load_imu_df(imu_path): | |
imu = load_imu(imu_path) | |
imu["time_s"] -= imu["time_s"][0] | |
df = pd.DataFrame(imu, columns=imu.dtype.names) | |
df["time_s"] = pd.to_datetime(df["time_s"], unit="s") | |
acc = df[[f"accel_{d}" for d in "xyz"]] | |
energy = np.linalg.norm(acc, axis=1) - G | |
df.insert(len(df.columns), "energy", energy) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment