def test_get_next_time(self): n = 100 ps = 100 * q.mm psm = ps.simplified.magnitude p = np.linspace(0, np.pi, n) sin = np.sin(p) * 1e-3 cos = np.cos(p) * 1e-3 zeros = np.zeros(n) traj_m_0 = Trajectory(zip(p * 1e-3, zeros, zeros) * q.m, velocity=1 * q.mm / q.s) traj_m_1 = Trajectory([(0, 0, 0)] * q.m) ball_0 = MetaBall(traj_m_0, .5 * q.m) ball_1 = MetaBall(traj_m_1, .5 * q.m) traj = Trajectory(zip(cos, sin, zeros) * q.m, velocity=1 * q.mm / q.s) comp = CompositeBody(traj, bodies=[ball_0, ball_1]) dt = comp.get_maximum_dt(ps) # Normal trajectories # Test the beginning, middle and end because of time complexity for t_0 in [0 * q.s, comp.time / 2, comp.time - 10 * dt]: t_1 = comp.get_next_time(t_0, ps) d = comp.get_distance(t_0, t_1).simplified.magnitude np.testing.assert_almost_equal(psm, d) # Trajectories which sum up to no movement traj_m = Trajectory(zip(zeros, -p, zeros) * q.m, velocity=1 * q.mm / q.s) ball = MetaBall(traj_m, .5 * q.m) traj = Trajectory(zip(p, zeros, zeros) * q.m, velocity=1 * q.mm / q.s) comp = CompositeBody(traj, bodies=[ball]) self.assertEqual(np.inf * q.s, comp.get_next_time(0 * q.s, ps))
def test_static_composite(self): ps = 1 * q.um traj = Trajectory([(0, 0, 0)] * q.m) mb_0 = MetaBall(traj, 10 * q.um) mb_1 = MetaBall(traj, 10 * q.um) comp = CompositeBody(traj, bodies=[mb_0, mb_1]) self.assertEqual(np.inf * q.s, comp.get_next_time(0 * q.s, ps))
def main(): syris.init() args = parse_args() n = 256 shape = (n, n) ps = 1 * q.um num_projections = None cube_edge = n / 4 * ps fmt = os.path.join(args.output, "projection_{:04}.tif") x = np.linspace(n // 4 + n // 8, 3 * n // 4 + n // 8, num=10) y = z = np.zeros(x.shape) cube_0 = make_cube_body(n, ps, cube_edge) cube_1 = make_cube_body(n, ps, cube_edge, phase_shift=np.pi * q.rad) # Vertical motion component has such velocity that the cubes are displaced by their edge length # 1 pixel for making sure we have one "complete" sinogram velocity = (cube_edge - ps) / cube_0.trajectory.time traj_y = geom.Trajectory(list(zip(y, x, z)) * ps, pixel_size=ps, velocity=velocity) composite = CompositeBody(traj_y, bodies=[cube_0, cube_1]) # Total time is the rotation time because we want one tomographic data set total_time = cube_0.trajectory.time dt = composite.get_next_time(0 * q.s, ps) if num_projections is None: num_projections = int(np.ceil((total_time / dt).simplified.magnitude)) print(" num_projs:", num_projections) print(" rotation time:", cube_0.trajectory.time) print(" vertical motion time:", traj_y.time) print(" simulation time:", total_time) for i in range(num_projections): t = total_time / num_projections * i composite.move(t) projection = composite.project(shape, ps).get() imageio.imwrite(fmt.format(i), projection) show(projection) plt.show()
def main(): syris.init() args = parse_args() n = 256 shape = (n, n) ps = 1 * q.um num_projections = None cube_edge = n / 4 * ps fmt = os.path.join(args.output, 'projection_{:04}.tif') x = np.linspace(n / 4 + n / 8, 3 * n / 4 + n / 8, num=10) y = z = np.zeros(x.shape) cube_0 = make_cube_body(n, ps, cube_edge) cube_1 = make_cube_body(n, ps, cube_edge, phase_shift=np.pi * q.rad) # Vertical motion component has such velocity that the cubes are displaced by their edge length # 1 pixel for making sure we have one "complete" sinogram velocity = (cube_edge - ps) / cube_0.trajectory.time traj_y = geom.Trajectory(zip(y, x, z) * ps, pixel_size=ps, velocity=velocity) composite = CompositeBody(traj_y, bodies=[cube_0, cube_1]) # Total time is the rotation time because we want one tomographic data set total_time = cube_0.trajectory.time dt = composite.get_next_time(0 * q.s, ps) if num_projections is None: num_projections = int(np.ceil((total_time / dt).simplified.magnitude)) print ' num_projs:', num_projections print ' rotation time:', cube_0.trajectory.time print ' vertical motion time:', traj_y.time print ' simulation time:', total_time for i in range(num_projections): t = total_time / num_projections * i composite.move(t) projection = composite.project(shape, ps).get() tifffile.imsave(fmt.format(i), projection) show(projection) plt.show()