In [8]:
import sys
import numpy as np
import scipy
import matplotlib.pyplot as plt
import seaborn as sns
sys.path.append('..')
from antlia.record import load_records, Record
from antlia import util
%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)
In [3]:
DEFAULT_FIGSIZE = (14, 7)
In [4]:
records = load_records()
for r in records:
print(r)
In [5]:
ax1 = [r.plot_timing(figsize=DEFAULT_FIGSIZE) for r in records]
plt.show()
In [6]:
ax2 = []
for r in records:
offset = r.sync()
print('synchronizing by applying time offset of {:0.3f} sec'.format(offset))
ax2.append(r.plot_timing(figsize=DEFAULT_FIGSIZE))
plt.show()
In [9]:
def plot_edge_dt_dist(edge_dt, title=None, ax=None):
press = edge_dt[0::2]
release = edge_dt[1::2]
if ax is None:
fig, ax = plt.subplots(3, 1, sharex=True, figsize=DEFAULT_FIGSIZE)
data = (edge_dt, press, release)
colors = sns.color_palette('Paired', 10)[1::2]
labels = ('both', 'press', 'release')
for d, c, l, a in zip(data, colors, labels, ax):
sns.distplot(d, color=c, label=l, ax=a)
for a in ax:
a.set_ylabel('probability density')
a.legend()
ax[-1].set_xlabel('time error [s]')
if title is not None:
set_title(ax[0], title)
return ax
diff = []
for i, r in enumerate(records, 1):
def edge_time(k):
subrecord = getattr(r, k)
_, index = util.reduce_runs(subrecord.sync)
# Remove first and last elements correspond to
# logging start and stop, not to sync edges.
return subrecord.time[index[1:-2]]
e = [edge_time(k) for k in Record.kinds]
diff.append(e[0] - e[1])
ax = plot_edge_dt_dist(diff[-1], 'record {}'.format(i))
print()
all_diff = np.concatenate(diff)
ax = plot_edge_dt_dist(all_diff, 'all records')
plt.show()
print('probability density of sync edge time error')
print('lidar edge occuring before bicycle edge is a positive time error')
print('\nstats:')
for k, v in scipy.stats.describe(all_diff)._asdict().items():
print(k, v)