Ejemplo n.º 1
0
    def test_LineSourcePotential_02(self):
        '''test LineSourcePotential implementation when assigning
        a location inside cylindric volume'''
        cell = get_cell(n_seg=1)
        cell.z = cell.z * 10

        lsp = lfp.LineSourcePotential(cell=cell,
                                      x=np.array([.131441]),
                                      y=np.array([0.]),
                                      z=np.array([5.]),
                                      sigma=0.3)
        M = lsp.get_transformation_matrix()

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

        V_ex = M @ imem

        Deltas_n = 10.
        h_n = -5.
        r_n = cell.d[0] / 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 * lsp.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)
Ejemplo n.º 2
0
    def test_LineSourcePotential_03(self):
        '''test LineSourcePotential implementation'''
        cell = get_cell(n_seg=1)
        cell.z = cell.z * 10

        lsp = lfp.LineSourcePotential(cell=cell,
                                      x=np.array([2.]),
                                      y=np.array([0.]),
                                      z=np.array([-1.]),
                                      sigma=0.3)
        M = lsp.get_transformation_matrix()

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

        V_ex = M @ imem

        Deltas_n = 10.
        h_n = 1.
        r_n = 2.
        l_n = Deltas_n + h_n

        # Use Eq. C.13 case III (h>0, l>0) from Gary Holt's 1998 thesis
        V_gt = imem / (4 * np.pi * lsp.sigma * Deltas_n) * np.log(
            (np.sqrt(l_n**2 + r_n**2) + l_n) /
            (np.sqrt(h_n**2 + r_n**2) + h_n))

        np.testing.assert_allclose(V_ex, V_gt)
Ejemplo n.º 3
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])
Ejemplo n.º 4
0
# locations where extracellular potential is predicted
dx = 1
dz = 1
axis = np.round([x.min() - 10, x.max() + 10, y.min() - 10, y.max() + 10])
# axis = np.round(axis)
X, Y = np.meshgrid(
    np.linspace(axis[0], axis[1],
                int(np.diff(axis[:2]) // dx) + 1),
    np.linspace(axis[2], axis[3],
                int(np.diff(axis[2:]) // dz) + 1))
Z = np.zeros_like(X)

# LineSourcePotential object, get mapping for all segments per CV
lsp = lfpykit.LineSourcePotential(cell=cell_geometry,
                                  x=X.flatten(),
                                  y=Y.flatten(),
                                  z=Z.flatten())
M_tmp = lsp.get_transformation_matrix()

# Define response matrix from M with columns weighted by area of each frusta
M = np.zeros((lsp.x.size, I_m.shape[0]))
for i in range(I_m.shape[0]):
    inds = CV_ind == i
    M[:, i] = M_tmp[:, inds] @ (cell_geometry.area[inds] /
                                cell_geometry.area[inds].sum())

# Extracellular potential using segment information at last time step
# in x,y-plane coordinates
V_e = M @ cell_geometry.I_m[:, -1]