def test_rotate_and_move_dipole(self, quadrant_points): vx = sphere.potential_homogeneous_dipole( 1., 1., [0.5, 0, 0], [1, 0, 0], quadrant_points) M = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]]) vy = sphere.potential_homogeneous_dipole( 1., 1., [0, 0.5, 0], [0, 1, 0], M.dot(quadrant_points.T).T) M = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) vz = sphere.potential_homogeneous_dipole( 1., 1., [0, 0, 0.5], [0, 0, 1], M.dot(quadrant_points.T).T) np.testing.assert_allclose(vx, vy) np.testing.assert_allclose(vx, vz)
def test_compare_homogeneous(self, quadrant_points): p = sphere.fibonacci_sphere(11, 2) v1 = sphere.potential_dipole_3layers( [0.8, 0.9, 2], 1., 1., [0, 0, 0.5], [1, 1, 1], p, 500) v2 = sphere.potential_homogeneous_dipole( 2., 1., [0, 0, 0.5], [1, 1, 1], p) assert np.allclose(v1, v2)
def test_tangential_dipole(self, quadrant_points): ''' Tests the relationship between a 3-sphere and single sphere model, Ari et. al 1998 ''' b_bar = 0.5 b_tilde = 0.316 m_bar = 1. m_tilde = 1./1.531 V_3layers = sphere.potential_dipole_3layers([.87, .92, 1.], 1., .0125, [b_bar, 0, 0], [0, m_bar, 0], quadrant_points) V_homo = sphere.potential_homogeneous_dipole(1., 1., [b_tilde, 0, 0], [0, m_tilde, 0], quadrant_points) assert np.allclose(V_3layers, V_homo, rtol=5e-2)
def test_reciprocity(): cond = [1, 1, 1] radii = [0.7, 0.85, 1] electrodes = np.array(((1, 0, 0), (-1, 0, 0)), dtype=float) dipole_pos = np.array( ((0.5, 0, 0), (0.5 + 1e-10, 0., 0), (0.5, 1e-10, 0), (0.5, 0, 1e-10), (0.5 - 1e-10, 0., 0), (0.5, -1e-10, 0), (0.5, 0, -1e-10)), dtype=float) dipole_moment = np.array((1, 1, 1), dtype=float) pot = sphere.potential_3layers_surface_electrodes(radii, cond, electrodes[0, :], electrodes[1, :], dipole_pos) E_field = (pot[1:4] - pot[4:7]) / 2e-13 dipole_pot = sphere.potential_homogeneous_dipole(1., 1., dipole_pos[0], dipole_moment, electrodes) np.testing.assert_allclose(dipole_pot[0] - dipole_pot[1], -E_field.dot(dipole_moment), rtol=1e-4)
def test_move_dipole_xyz(self, quadrant_points): v = sphere.potential_homogeneous_dipole( 1., 1., [0.5, 0.5, 0.5], [1, 0, 0], quadrant_points) v2 = sphere.potential_homogeneous_dipole( 1., 1., [-0.5, -0.5, -0.5], [-1, 0, 0], -quadrant_points) np.testing.assert_almost_equal(v, v2)
def test_tilt_dipole_x(self, quadrant_points): v = sphere.potential_homogeneous_dipole( 1., 1., [0, 0, 0], [1, 0, 0], quadrant_points) np.testing.assert_almost_equal(v[quadrant_points[:, 0] > 0], -v[quadrant_points[:, 0] < 0])
def test_symmetry_z_axis(self, quadrant_points): v = sphere.potential_homogeneous_dipole( 1., 1., [0, 0, 0], [0, 0, 1], quadrant_points) np.testing.assert_almost_equal(v[quadrant_points[:, 2] > 0], -v[quadrant_points[:, 2] < 0])
def test_dipole_source_at_center(self): points = np.array([[0, 0.7071, 0.7071]]) v = sphere.potential_homogeneous_dipole( 1., 1., [0, 0, 0], [0, 0, 1], points) v_simple = 3 / (4 * np.pi * 1e-6) * (1 / np.sqrt(2)) assert np.abs((v[0] - v_simple) / v_simple) < 1e-3