def main(dataset='measurements.npy'): data = np.load(dataset, mmap_mode='r') print 'loaded', dataset, data.shape plots = list(range(N * N)) frames = [[] for _ in plots] for subj in data: for block in subj[1:]: for trial in block: if trial[0, C.col('trial-hand')] == C.right: for frame in trial: for i in plots: if within_region(frame, i): frames[i].append(frame) break u, v = np.mgrid[0:2 * np.pi:11j, 0:np.pi:7j] sphx = np.cos(u) * np.sin(v) sphy = np.sin(u) * np.sin(v) sphz = np.cos(v) fig = plt.figure() for i, postures in enumerate(frames): if not postures: continue if i != 2: continue postures = np.array(postures) for m in range(50): marker = postures[:, 17+m*4:17+(m+1)*4] drops = marker[:, 3] < 0 marker[drops, :3] = marker[~drops, :3].mean(axis=0) means = postures.mean(axis=0) stds = postures.std(axis=0) #ax = util.axes(fig, 111) #for frame in postures[::5]: # util.plot_skeleton(ax, frame, alpha=0.1) ax = util.axes(fig, 110 * N + i + 1) util.plot_skeleton(ax, means, alpha=1.0) for m in range(50): mx, my, mz = means[17+m*4:20+m*4] sx, sy, sz = stds[17+m*4:20+m*4] / 2 ax.plot_wireframe(sphx * sx + mx, sphz * sz + mz, sphy * sy + my, color=C.MARKER_COLORS[m], alpha=0.3) #tgtx, tgty, tgtz = postures.mean(axis=0)[ # C.cols('target-x', 'target-y', 'target-z')] #ax.plot([tgtx], [tgtz], [tgty], 'o', color='#111111') #for m in range(50): # marker = postures[:, 17 + 4 * m:17 + 4 * (m+1)] # position = marker.mean(axis=0) # size = marker.std(axis=0) # ax.plot_surface() util.set_limits(ax, center=(0, -0.5, 1), span=1) ax.w_xaxis.set_pane_color((1, 1, 1, 1)) ax.w_yaxis.set_pane_color((1, 1, 1, 1)) ax.w_zaxis.set_pane_color((1, 1, 1, 1)) ax.set_title(['Top Right', 'Top Left', 'Bottom Right', 'Bottom Left'][i]) #for m in range(50): # x, z, y = frame[m*4:m*4+3] # ax.text(x, y, z, str(m)) plt.gcf().set_size_inches(12, 10) #plt.savefig('reach-targets-with-variance.pdf', dpi=600) plt.show()
def p0x88_to_chess_notation(x): icol = col(x) irow = rank(x) return chr(icol + 97) + str(irow + 1)
def p0x88_to_tuple(position): return (col(position), rank(position))
def main(dataset='measurements.npy', plot_mean=0): plot_mean = plot_mean > 0 X = np.load(dataset, mmap_mode='r') print 'loaded', dataset, X.shape series = collections.defaultdict(list) for subject in X: for block in subject: for trial in block: weight = trial[0, C.col('block-weight')] if weight != C.UNWEIGHTED: continue hand = trial[0, C.col('block-hand')] if hand != C.DOMINANT: continue speed = trial[0, C.col('trial-speed')] for src, tgt in PAIRS: d = distances(trial, src, tgt) series[src, tgt].append((speed, d.mean(), d.std())) for i, (src, tgt) in enumerate(PAIRS): speed, mean, std = np.array(series[(src, tgt)]).T dependent = [std, mean][plot_mean] model = LinearRegression() model.fit(speed[:, None], np.log(dependent)) idx = np.arange(len(speed)) np.random.shuffle(idx) spines = [] if i == 0: spines.append('left') if not plot_mean: spines.append('bottom') ax = lmj.plot.axes((1, len(series), i + 1), spines=spines) #ax.errorbar(speed, mean, yerr=std, fmt='o', alpha=0.9) ax.plot(speed[idx[:100]], dependent[idx[:100]], 'o', color='#111111', alpha=0.7) ax.plot([speed.min(), speed.max()], np.exp(model.predict([[speed.min()], [speed.max()]])), '-', color='#cc3333', lw=3) ax.set_ylim((10, 1000)) ax.set_yscale('log') if plot_mean: ax.set_title('{} - {}'.format(src.capitalize(), tgt.capitalize())) ax.set_xticks([]) ax.xaxis.set_ticks_position('none') else: ax.set_xlabel('Tracing Speed (m/s)') if i == 0: ax.set_ylabel('{} Distance (mm)'.format(['SD of', 'Mean'][plot_mean])) else: ax.set_yticks([]) ax.yaxis.set_ticks_position('none') out = 'error-vs-speed-{}.pdf'.format(['std', 'mean'][plot_mean]) print 'saving', out lmj.plot.gcf().set_size_inches(12, 3) lmj.plot.savefig(out, dpi=600)