def test_generate_quaternion(self): print('=== Testing generate_quaternion() ===') rot = quat.rotation() rot.generate_quaternion(config_fname) self.quat_tests(rot) rot.generate_quaternion(config_fname) quat_fname = recon_folder+b'/data/quat.dat' with open(quat_fname, 'w') as f: w = csv.writer(f, delimiter=' ') w.writerow([rot.num_rot]) w.writerows(rot.quat) config = DragonflyConfig(config_fname) config.modify_entry('emc', 'sym_icosahedral', '1') rot.generate_quaternion(config_fname) self.assertTrue(rot.icosahedral_flag) self.assertEqual(rot.num_rot, 75) npt.assert_array_almost_equal(rot.quat[0], [1., 0., 0., 0., 0.00881278]) npt.assert_array_almost_equal(rot.quat[1], [0.98830208, -0.12973191, -0.08017873, 0., 0.01192908]) config.remove_entry('emc', 'sym_icosahedral') rot.free_quat() rot = quat.rotation() config.modify_entry('emc', 'in_quat_file', 'data/quat.dat') self.assertRaises(AssertionError, rot.generate_quaternion, config_fname) config.remove_entry('emc', 'num_div') rot.generate_quaternion(config_fname) self.quat_tests(rot) os.remove(quat_fname) config.modify_entry('emc', 'num_div', '4') config.remove_entry('emc', 'in_quat_file')
def test_voronoi_subset(self): print('=== Testing voronoi_subset() ===') qfine = quat.rotation() qfine.quat_gen(4) qcoarse = quat.rotation() qcoarse.quat_gen(2) mapping = qfine.voronoi_subset(qcoarse) self.assertEqual(qfine.num_rot, mapping.shape[0]) npt.assert_array_equal([0, 1, 2, 3, 4], mapping[:5]) npt.assert_array_equal([215, 216, 394, 396, 398], mapping[-5:]) qfine.free_quat() qcoarse.free_quat()
def cilindrify(V, edges_, radius, n=5): angles = np.arange(n) * (2 * np.pi / n) X = np.arange(n) rectangles = np.c_[X, (X + 1) % n, (X + n), (X + 1) % n + n, X + n, (X + 1) % n] edges = np.array([e for e in edges_ if _norm(V[e[0]] - V[e[1]]) > 0]) N = len(edges) p = np.zeros(shape=[N * 2 * n, 3], dtype=float) r = np.random.normal(0, 1, 3) for i, e in enumerate(edges): p1 = V[e[0]] p2 = V[e[1]] l = p2 - p1 l /= _norm(l) t = np.cross(r, l) t /= _norm(t) bi = i * 2 * n vertex_offsets = np.array([quat.rotation(l, a)(t) for a in angles]) * radius[i] p[bi : bi + 2 * n] = np.r_[(p1 + vertex_offsets), (p2 + vertex_offsets)] f = rectangles[np.newaxis, :, :] + (np.arange(N) * n * 2)[:, np.newaxis, np.newaxis] return p, f
def test_quat_gen(self): print('=== Testing quat_gen() ===') rot = quat.rotation() self.assertEqual(rot.quat_gen(4), 3240) self.quat_tests(rot) for i in range(1, 13, 1): self.assertEqual(rot.quat_gen(i), 10 * (5 * i**3 + i))
def test_quat_gen(self): print('=== Testing quat_gen() ===') rot = quat.rotation() self.assertEqual(rot.quat_gen(4), 3240) self.quat_tests(rot) for i in range(1,13,1): self.assertEqual(rot.quat_gen(i), 10*(5*i**3 + i))
def test_free_quat(self): print('=== Testing free_quat() ===') rot = quat.rotation() rot.quat_gen(4) rot.divide_quat(6, 7, 1) rot.free_quat() rot.free_quat() self.assertIsNone(rot.num_rot)
def test_divide_quat(self): print('=== Testing divide_quat() ===') rot = quat.rotation() rot.quat_gen(4) rot.divide_quat(0, 1, 1) self.assertEqual(rot.num_rot_p, 3240) rot.divide_quat(5, 7, 1) self.assertEqual(rot.num_rot_p, 463) rot.divide_quat(6, 7, 1) self.assertEqual(rot.num_rot_p, 462)
def test_parse_quat(self): print('=== Testing parse_quat() ===') rot = quat.rotation() self.assertEqual(rot.parse_quat(b''), -1) rot.quat_gen(4) quat_fname = recon_folder + b'/data/quat.dat' with open(quat_fname, 'w') as f: w = csv.writer(f, delimiter=' ') w.writerow([rot.num_rot]) w.writerows(rot.quat) self.assertEqual(rot.parse_quat(quat_fname), 3240) self.quat_tests(rot) os.remove(quat_fname)
def test_parse_quat(self): print('=== Testing parse_quat() ===') rot = quat.rotation() self.assertEqual(rot.parse_quat(b''), -1) rot.quat_gen(4) quat_fname = recon_folder+b'/data/quat.dat' with open(quat_fname, 'w') as f: w = csv.writer(f, delimiter=' ') w.writerow([rot.num_rot]) w.writerows(rot.quat) self.assertEqual(rot.parse_quat(quat_fname), 3240) self.quat_tests(rot) os.remove(quat_fname)
def test_generate_quaternion(self): print('=== Testing generate_quaternion() ===') rot = quat.rotation() rot.generate_quaternion(config_fname) self.quat_tests(rot) rot.generate_quaternion(config_fname) quat_fname = recon_folder + b'/data/quat.dat' with open(quat_fname, 'w') as f: w = csv.writer(f, delimiter=' ') w.writerow([rot.num_rot]) w.writerows(rot.quat) config = DragonflyConfig(config_fname) config.modify_entry('emc', 'sym_icosahedral', '1') rot.generate_quaternion(config_fname) self.assertTrue(rot.icosahedral_flag) self.assertEqual(rot.num_rot, 75) npt.assert_array_almost_equal(rot.quat[0], [1., 0., 0., 0., 0.00881278]) npt.assert_array_almost_equal( rot.quat[1], [0.98830208, -0.12973191, -0.08017873, 0., 0.01192908]) config.remove_entry('emc', 'sym_icosahedral') rot.free_quat() rot = quat.rotation() config.modify_entry('emc', 'in_quat_file', 'data/quat.dat') self.assertRaises(AssertionError, rot.generate_quaternion, config_fname) config.remove_entry('emc', 'num_div') rot.generate_quaternion(config_fname) self.quat_tests(rot) os.remove(quat_fname) config.modify_entry('emc', 'num_div', '4') config.remove_entry('emc', 'in_quat_file')