def test_RecExtElectrode_04(self): """test RecExcElectrode implementation, method='root_as_point' and rootinds parameter""" cell = get_cell(n_seg=4) sigma = 0.3 r = np.array([1, 0, 2]) # all point sources el0 = lfp.PointSourcePotential(cell=cell, x=np.array([r[0]]), y=np.array([r[1]]), z=np.array([r[2]]), sigma=sigma) M0 = el0.get_transformation_matrix() # all line sources el1 = lfp.LineSourcePotential(cell=cell, x=np.array([r[0]]), y=np.array([r[1]]), z=np.array([r[2]]), sigma=sigma) M1 = el1.get_transformation_matrix() # vary which index is treated as point ids = np.arange(cell.totnsegs) for i in range(cell.totnsegs): el = lfp.RecExtElectrode(cell=cell, x=r[0], y=r[1], z=r[2], sigma=sigma, method='root_as_point', rootinds=np.array([i])) M = el.get_transformation_matrix() np.testing.assert_almost_equal(M0[0, i], M[0, i]) np.testing.assert_equal(M1[0, ids != i], M[0, ids != i]) # multiple roots for i in range(cell.totnsegs - 1): rootinds = np.array([i, i + 1]) notroots = np.ones(cell.totnsegs, dtype=bool) notroots[rootinds] = False el = lfp.RecExtElectrode(cell=cell, x=r[0], y=r[1], z=r[2], sigma=sigma, method='root_as_point', rootinds=rootinds) M = el.get_transformation_matrix() np.testing.assert_allclose(M0[0, rootinds], M[0, rootinds]) np.testing.assert_equal(M1[0, notroots], M[0, notroots])
def test_RecExtElectrode_03(self): """test RecExcElectrode implementation, method='pointsource' with anisotropy""" cell = get_cell(n_seg=1) cell.x = np.array([[0., 2.4]]) cell.y = np.array([[0., 2.4]]) cell.z = np.array([[0., 2.4]]) sigma = [0.6, 0.3, 0.45] r = np.array([[0.], [0.], [0.]]) el = lfp.RecExtElectrode(cell=cell, x=r[0], y=r[1], z=r[2], sigma=sigma, method='pointsource') M = el.get_transformation_matrix() imem = np.array([[0., 1., -1.]]) V_ex = M @ imem sigma_r = np.sqrt(sigma[1] * sigma[2] * 1.2**2 + sigma[0] * sigma[2] * 1.2**2 + sigma[0] * sigma[1] * 1.2**2) V_gt = np.array([[0., 1., -1.]]) / (4 * np.pi * sigma_r) np.testing.assert_allclose(V_ex, V_gt)
def test_RecExtElectrode_01(self): """test LineSourcePotential implementation, method='linesource'""" cell = get_cell(n_seg=1) cell.z = cell.z * 10 el = lfp.RecExtElectrode(cell=cell, x=np.array([2.]), y=np.array([0.]), z=np.array([5.]), sigma=0.3, method='linesource') M = el.get_transformation_matrix() imem = np.array([[0., 1., -1.]]) V_ex = M @ imem Deltas_n = 10. h_n = -5. r_n = 2. l_n = Deltas_n + h_n # Use Eq. C.13 case II (h<0, l>0) from Gary Holt's 1998 thesis V_gt = imem / (4 * np.pi * el.sigma * Deltas_n) * np.log( (np.sqrt(h_n**2 + r_n**2) - h_n) * (np.sqrt(l_n**2 + r_n**2) + l_n) / r_n**2) np.testing.assert_allclose(V_ex, V_gt)
def test_RecExtElectrode_02(self): """test RecExcElectrode implementation, method='root_as_point'""" cell = get_cell(n_seg=1) sigma = 0.3 r = np.array([[cell.d[0]], [0.], [cell.z.mean()]]) el = lfp.RecExtElectrode(cell=cell, x=r[0], y=r[1, ], z=r[2, ], sigma=sigma, method='root_as_point') M = el.get_transformation_matrix() imem = np.array([[0., 1., -1.]]) * (4 * np.pi * sigma * cell.d[0]) V_ex = M @ imem V_gt = np.array([[0., 1., -1.]]) np.testing.assert_allclose(V_ex, V_gt)