TREMOR12 automated data processing


In [1]:
# Required modules - do not modify
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

# User preferences - can be changed
pref_grid_visible = True
pref_plot_gravity = True
pref_save_figures = False
pref_filename     = 'tremor_samples.csv'

Raw data


In [2]:
# Create dataframe from CSV file
df = pd.read_csv(pref_filename)

# Create time column starting at zero and use as index
# Note that the 'timestamp2001_ms' column contains absolute date and time (in ms from Jan 1, 2001)
# Time is in seconds
df['time'] = 0.001 * (df['timestamp2001_ms'] - df['timestamp2001_ms'][0])
cols = df.columns.tolist()
cols = cols[-1:] + cols[1:-1]
params = df[cols].set_index('time')

# Show first 5 rows for exploratory purposes
params.head()


Out[2]:
roll pitch yaw rotX rotY rotZ accX accY accZ gravX gravY gravZ
time
0.000000 -0.268758 0.016428 0.123095 0.020964 -0.064637 -0.045642 -0.030481 -0.055561 0.006962 -0.263525 -0.122784 -0.956806
0.010000 -0.269731 0.016056 0.123714 0.061535 -0.110241 -0.054151 -0.030487 -0.048095 0.001352 -0.264435 -0.123398 -0.956476
0.020033 -0.271110 0.015760 0.124805 0.108518 -0.155816 -0.057343 -0.024382 -0.040939 0.001512 -0.265718 -0.124482 -0.955980
0.030041 -0.273008 0.015626 0.126265 0.144900 -0.200314 -0.049840 -0.023518 -0.043169 -0.007425 -0.267483 -0.125929 -0.955298
0.040041 -0.278764 0.016071 0.133000 0.154542 -0.208792 -0.046644 -0.026946 -0.039420 -0.000295 -0.272737 -0.132608 -0.952906

Descriptive parameter statistics


In [3]:
# Provide basic descriptive statistics for tremor parameters
params.describe()


Out[3]:
roll pitch yaw rotX rotY rotZ accX accY accZ gravX gravY gravZ
count 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000 808.000000
mean -0.992005 1.837763 0.360829 -0.087991 -0.094372 0.039380 -0.000066 0.034955 0.020339 -0.612401 -0.347423 -0.463532
std 0.616394 1.990519 0.179723 2.246431 4.000816 2.223562 0.503292 0.294676 0.380595 0.216771 0.166498 0.463732
min -2.713387 -3.137010 0.009150 -7.341962 -12.319378 -6.990265 -1.283882 -0.708737 -1.270164 -0.949870 -0.707237 -0.977277
25% -1.317743 2.484498 0.233794 -1.349800 -2.349001 -1.505577 -0.206585 -0.117221 -0.160816 -0.797238 -0.475772 -0.870620
50% -0.894487 2.699471 0.365033 0.047393 0.108100 -0.015090 -0.016317 -0.005987 0.009378 -0.660303 -0.356980 -0.572989
75% -0.460041 2.845255 0.495841 1.276256 2.507316 1.196256 0.269633 0.192568 0.229690 -0.426545 -0.231670 -0.230436
max -0.187178 3.139689 0.785583 5.963924 10.784140 7.624787 1.653141 0.834309 1.193677 -0.183936 -0.009150 0.768944

Create graphs


In [4]:
def create_plot(param_values, title_value, entity_value):
    '''Creates separate plots from manually entered values'''
    param_plot = params[param_values].plot(figsize=(20,5), title=title_value, grid = pref_grid_visible)
    param_plot.set_xlabel('Time (seconds)')
    param_plot.set_ylabel(title_value + ' (' + entity_value + ')')
    plt.legend(['X', 'Y', 'Z'], loc=1)
    
    if pref_save_figures:
        plt.savefig('fig_' + title_value.lower().replace(' ', '_') + '.png', dpi=300)
    
    return param_plot

In [5]:
# Create individual plots
create_plot(['accX', 'accY', 'accZ'], 'Acceleration', 'G')
create_plot(['roll', 'pitch', 'yaw'], 'Rotation', 'radians')
create_plot(['rotX', 'rotY', 'rotZ'], 'Rotation speed', 'radians / second')
if pref_plot_gravity:
    create_plot(['gravX', 'gravY', 'gravZ'], 'Gravity', 'G')



In [5]: