Beispiel #1
0
    def test_PointSoucePotential_00(self):
        '''test PointSourcePotential implementation'''
        cell = get_cell(n_seg=3)
        sigma = 0.3
        r = np.array([[29.41099547, 43.06748789, -13.90864482, -40.44348899,
                       -29.4355596, -49.53871099, -33.70179906, 19.71508449,
                       -25.38725944, 42.52608652],
                      [24.36798674, -31.25870899, 22.6071361, -5.89078286,
                       44.44040172, 48.8092616, -34.2306679, -12.08847587,
                       -30.36317994, 30.79944143],
                      [-33.67242089, -9.71721014, 22.74564354, -27.14076556,
                       10.26397085, 30.1274518, -36.71772572, -22.21636375,
                       35.62274778, 41.273182]])
        psp = lfp.PointSourcePotential(cell=cell, x=r[0], y=r[1, ], z=r[2, ],
                                       sigma=sigma)
        M = psp.get_transformation_matrix()

        imem = np.array([[-1., 1.],
                         [0., 0.],
                         [1., -1.]])

        V_ex = M @ imem

        r_norm = np.empty((r.shape[1], cell.totnsegs))
        for i, (x, y, z) in enumerate(zip(cell.x.mean(axis=-1),
                                          cell.y.mean(axis=-1),
                                          cell.z.mean(axis=-1))):
            r_norm[:, i] = np.linalg.norm((r.T - np.r_[x, y, z]).T, axis=0)

        V_gt = (1 / (4 * np.pi * sigma * r_norm)) @ imem

        self.assertTrue(np.all(V_ex == V_gt))
Beispiel #2
0
    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])
Beispiel #3
0
    def test_PointSoucePotential_01(self):
        '''test PointSourcePotential implementation, when contact is within
        d/2 distance to segment'''
        cell = get_cell(n_seg=1)
        cell.d = np.array([2.])
        sigma = 0.3
        r = np.array([[0.1254235242],
                      [0.],
                      [cell.z.mean()]])
        psp = lfp.PointSourcePotential(cell=cell, x=r[0], y=r[1, ], z=r[2, ],
                                       sigma=sigma)
        M = psp.get_transformation_matrix()

        imem = np.array([[0., 1., -1.]]) * (4 * np.pi * sigma * cell.d[0] / 2)

        V_ex = M @ imem

        V_gt = np.array([[0., 1., -1.]])

        np.testing.assert_allclose(V_ex, V_gt)