def create_maxima_testing_data(): n = 128 points = make_circle(n=n) * 1e3 ps = 10 * q.mm furthest = 1 * q.m tr = Trajectory(points, ps, furthest, velocity=1 * q.m / q.s) duration = tr.time.simplified.magnitude t = np.linspace(0, 2 * duration, n) * q.s # Sine-like velocity profile s = 0.5 * tr.length * (np.sin(t.magnitude / duration * 2 * np.pi) + 1) time_dist = list(zip(t, s)) # Use small num_points to make sure we move more than 1 px tr = Trajectory(points, ps, furthest, time_dist=time_dist, num_points=n) distances = tr.get_distances() dtck = interp.splprep(distances, u=tr.parameter, s=0, k=1)[0] return tr, dtck, ps, t
def create_maxima_testing_data(): n = 128 points = make_circle(n=n) * 1e3 ps = 10 * q.mm furthest = 1 * q.m tr = Trajectory(points, ps, furthest, velocity=1 * q.m / q.s) duration = tr.time.simplified.magnitude t = np.linspace(0, 2 * duration, n) * q.s # Sine-like velocity profile s = 0.5 * tr.length * (np.sin(t.magnitude / duration * 2 * np.pi) + 1) time_dist = zip(t, s) # Use small num_points to make sure we move more than 1 px tr = Trajectory(points, ps, furthest, time_dist=time_dist, num_points=n) distances = tr.get_distances() dtck = interp.splprep(distances, u=tr.parameter, s=0, k=1)[0] return tr, dtck, ps, t
def test_get_distances(self): """Compare analytically computed distances with the ones obtained from trajectory.""" points = make_circle(n=128) x, y, z = zip(*points) furthest = 3 * q.mm ps = 10 * q.um tr = Trajectory(points, ps, furthest, velocity=1 * q.mm / q.s) d_points = np.abs(tr.points[:, 0][:, np.newaxis] - tr.points) t = np.linspace(0, 2 * np.pi, tr.points.shape[1]) x, y, z = zip(*make_circle(n=tr.points.shape[1])) dx = -np.sin(t) dy = np.cos(t) dz = z derivatives = np.array(zip(dx, dy, dz)).T.copy() d_derivatives = get_rotation_displacement(derivatives[:, 0], derivatives, furthest) distances = (d_points + d_derivatives).simplified.magnitude np.testing.assert_almost_equal(distances, tr.get_distances())
def test_get_distances(self): """Compare analytically computed distances with the ones obtained from trajectory.""" points = make_circle(n=128) x, y, z = list(zip(*points)) furthest = 3 * q.mm ps = 10 * q.um tr = Trajectory(points, ps, furthest, velocity=1 * q.mm / q.s) d_points = np.abs(tr.points[:, 0][:, np.newaxis] - tr.points) t = np.linspace(0, 2 * np.pi, tr.points.shape[1]) x, y, z = list(zip(*make_circle(n=tr.points.shape[1]))) dx = -np.sin(t) dy = np.cos(t) dz = z derivatives = np.array(list(zip(dx, dy, dz))).T.copy() d_derivatives = get_rotation_displacement(derivatives[:, 0], derivatives, furthest) distances = (d_points + d_derivatives).simplified.magnitude np.testing.assert_almost_equal(distances, tr.get_distances())