Source code for PyOptoUS.kine
"""
.. module:: kine
:synopsis: helper module for kinematics
"""
import numpy as np
from scipy.interpolate import interp1d
[docs]def dot2(a, b):
"""Compute K matrix products between a M x N array and a K x N x P
array in a vectorized way.
:param np.ndarray a, b: the two arrays to be multiplied.
:return: K x M x P array
:rtype: np.ndarray
"""
return np.transpose(np.dot(np.transpose(b,(0,2,1)),a.T),(0,2,1))
[docs]def getVersor(a):
norm = np.sqrt(np.sum(np.multiply(np.mat(a),np.mat(a)),axis=1))
r = a / norm
return np.mat(r)
[docs]def resampleMarker(M, step=None, x=None, origFreq=None):
if x <> None and origFreq <> None:
N = M.shape[0]
dt = 1. / origFreq
x1 = np.linspace(0, (N-1)*dt, num=N)
f = interp1d(x1, M, axis=0)
x2 = np.array(x)
M = f(x2)
elif step <> None:
N = M.shape[0]
x1 = np.linspace(0, N-1, num=N)
f = interp1d(x1, M, axis=0)
x2 = np.arange(0, N-1, step)
M = f(x2)
else:
raise Exception('Impossible to resample')
return M