In [1]:
import sys
import itertools
import matplotlib.pyplot as plt
sys.path.append('..')
from antlia.record import load_records
%load_ext autoreload
%autoreload 2
In [2]:
def set_title(ax, title):
try:
mpld3
except NameError:
ax.figure.suptitle(title)
else:
ax.set_title(title)
DEFAULT_FIGSIZE = (14, 7)
In [3]:
records = load_records(sync=False)
In [4]:
import numpy as np
import scipy
import seaborn as sns
# rider, speed, amplitude, freq
data = np.zeros((4*15, 5))
plt.close()
for rid, tid in itertools.product(range(4), range(15)):
record = records[rid]
trial = record.trial[tid]
try:
ax = trial.plot_steer_event_detection(figsize=DEFAULT_FIGSIZE)
ax.set_title('rider {}, trial {:02d}, events: {}'.format(rid, tid, ax.get_title()))
except ValueError:
continue
est, (t, y, est_y), ev = trial.steer_event_parameters()
fit_desc = 'rider {}, trial {:02d}, a: {:0.02f}, t: {:0.02f}, v: {:0.02f}'.format(
rid, tid, est[0], 1/est[1], ev.speed)
data[rid*15 + tid, :] = np.array([rid, tid, ev.speed, -est[0], 1/est[1]])
colors = sns.color_palette('Paired', 10)
fig2, ax2 = plt.subplots(figsize=DEFAULT_FIGSIZE)
ax2.plot(t, y, label='steer angle event', color=colors[1])
ax2.plot(t, est_y, label='fitted sinusoid', color=colors[7])
ax2.legend()
ax2.set_title(fit_desc)
ax2.axhline(0, color='black')
plt.show()
In [5]:
import pandas as pd
# Average speed (v) in this dataframe is over the
# steer avoidance event (infl, min, infl, max, infl, min, infl)
# and not just the sinusoid fit region (infl, min, infl)
df = pd.DataFrame(data=data, columns=['rider', 'trial', 'v', 'a', 't'])
print(df)
In [6]:
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='a', data=df, ax=ax)
ax.set_title('rider vs fitted amplitude')
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='t', data=df, ax=ax)
ax.set_title('rider vs fitted period')
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='v', data=df, ax=ax)
ax.set_title('rider vs average velocity')
plt.show()
In [7]:
from antlia.plotdf import colormap, plotjoint
colors = sns.color_palette()
plt.close()
g = plotjoint('a', 't', df, ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
g = plotjoint('v', 'a', df[df.v > 1], ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
g = plotjoint('v', 't', df[df.v > 1], ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
plt.show()
In [8]:
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='a', data=df[df.a < 2], ax=ax)
ax.set_title('rider vs fitted amplitude (a < 2)')
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='t', data=df[df.t < 6], ax=ax)
ax.set_title('rider vs fitted period (t < 6)')
fig, ax = plt.subplots(figsize=DEFAULT_FIGSIZE)
sns.swarmplot(x='rider', y='v', data=df[df.v > 1], ax=ax)
ax.set_title('rider vs average velocity (v > 1)')
plt.show()
In [9]:
colors = sns.color_palette()
plt.close()
g = plotjoint('a', 't', df[(df.t < 6) & (df.v > 1)], ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
g = plotjoint('v', 'a', df[(df.t < 6) & (df.v > 1)], ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
g = plotjoint('v', 't', df[(df.t < 6) & (df.v > 1)], ('rider', colors))
g.fig.set_size_inches(DEFAULT_FIGSIZE)
plt.show()