st = np.sin(theta) return np.array([[ct, 0, st], [0, 1, 0], [-st, 0, ct]]) def rz(theta): ct = np.cos(theta) st = np.sin(theta) return np.array([[ct, -st, 0], [st, ct, 0], [0, 0, 1]]) def axes(fig, which=111): ax = fig.add_subplot(which, projection='3d') #ax.axis('off') return ax TARGET = C.cols('target-x', 'target-y', 'target-z') FINGER = C.cols('finger-x', 'finger-y', 'finger-z') HEAD = C.cols('head-x', 'head-y', 'head-z') atan = np.arctan2 def canonical(frame, marker): hx, hy, hz = frame[HEAD] - frame[FINGER] ax = 0#atan(hz, hy) ay = -atan(hx, hz) az = 0 return np.dot(rx(ax), np.dot(ry(ay), marker - frame[FINGER])) def identity(frame, marker): return marker
import climate import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D import constants as C import util TARGET = C.cols('target-x', 'target-y', 'target-z') N = 2 X = ((0.4, 0.6), (-0.6, -0.4)) # -0.6 to 0.6 Y = ((1.7, 1.9), (0.6, 0.8)) # 0.6 to 1.9 Z = (-0.1, 0.1) # -0.6 to 0.6 def within_region(frame, i): b, a = divmod(i, N) x, y, z = frame[TARGET] return (X[a][0] < x < X[a][1] and Y[b][0] < y < Y[b][1] and Z[0] < z < Z[1]) 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:
def distances(trial, src='target', tgt='finger'): src = trial[:, C.cols('{}-{}'.format(src, x) for x in 'xyz')] tgt = trial[:, C.cols('{}-{}'.format(tgt, x) for x in 'xyz')] return 1000 * np.sqrt(((src - tgt) ** 2).sum(axis=1))