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'
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]:
In [3]:
# Provide basic descriptive statistics for tremor parameters
params.describe()
Out[3]:
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]: