示例#1
0
    def test_get_multi_dipole_potential01(self):
        morphology = os.path.join(LFPy.__path__[0], 'test',
                                  'ball_and_sticks.hoc')
        electrode_locs = np.array([[0., 0., 10000.]])
        cell, electrode = cell_w_synapse_from_sections_w_electrode(
            morphology, electrode_locs)
        sigma = 0.3
        t_point = 0

        MD_inf = LFPy.InfiniteVolumeConductor(sigma)
        pot_MD = MD_inf.get_multi_dipole_potential(cell, electrode_locs)
        pot_cb = electrode.LFP

        np.testing.assert_almost_equal(pot_MD, pot_cb)
        np.testing.assert_allclose(pot_MD, pot_cb, rtol=1E-3)
示例#2
0
    def test_calc_potential(self):
        '''test comparison between four-sphere model and model for
        infinite homogeneous space
        when sigma is constant and r4 goes to infinity'''
        sigmas = [0.3, 0.3, 0.3 + 1e-16, 0.3]
        radii = [10., 20 * 1e6, 30. * 1e6, 40. * 1e6]
        rz = np.array([0., 0., 3.])
        p = np.array([[0., 0., 100.], [50., 50., 0.]])
        r_elec = np.array([[0., 0., 9.], [0., 0., 15.], [0., 0., 25.],
                           [0., 0., 40.], [0., 9., 0.], [0., 15., 0.],
                           [0., 25., 0.], [0., 40., 0.]])
        four_s = LFPy.FourSphereVolumeConductor(radii, sigmas, r_elec)
        pots_4s = four_s.calc_potential(p, rz)
        inf_s = LFPy.InfiniteVolumeConductor(0.3)
        pots_inf = inf_s.get_dipole_potential(p, r_elec - rz)

        np.testing.assert_allclose(pots_4s, pots_inf, rtol=1e-6)
示例#3
0
def make_data(morphology,
              syninds,
              dip_loc=None,
              cell_model=None,
              x_rot=0,
              y_rot=0,
              z_rot=0,
              active=False):

    sigma = 0.3  #extracellular conductivity
    k = 1e6  # convert from mV to nV

    # compute LFP close to neuron
    # set up electrodes close to neuron
    X, Z = np.meshgrid(np.linspace(-550, 550, 101),
                       np.linspace(-250, 850, 101))
    Y = np.zeros(X.shape)
    # simulate cell
    (cell_parameters, synapse_parameters,
     grid_electrode_parameters) = set_parameters(morphology,
                                                 X,
                                                 Y,
                                                 Z,
                                                 sigma=sigma,
                                                 cell_model=cell_model)
    cell, synapse, grid_electrode_LFP = simulate(cell_parameters,
                                                 synapse_parameters,
                                                 grid_electrode_parameters,
                                                 syninds,
                                                 x_rot=x_rot,
                                                 y_rot=y_rot,
                                                 z_rot=z_rot,
                                                 active=active)

    # multicompartment modeling of LFP close to cell
    cb_LFP_close = grid_electrode_LFP * k

    # multi-dipole modeling of LFP close to cell
    multi_dips, multi_dip_locs = cell.get_multi_current_dipole_moments()
    inf_vol = LFPy.InfiniteVolumeConductor(sigma)
    gridpoints_close = np.array([X.flatten(), Y.flatten(), Z.flatten()]).T
    multi_dip_LFP_close = inf_vol.get_multi_dipole_potential(
        cell, gridpoints_close) * k

    # single-dipole modeling of LFP close to cell
    cdm = LFPy.CurrentDipoleMoment(cell)
    single_dip = cdm.get_transformation_matrix() @ cell.imem
    syninds = cell.synidx
    if dip_loc is not None:
        r_mid = dip_loc
    else:
        r_soma_syns = [
            cell.get_intersegment_vector(idx0=0, idx1=i) for i in syninds
        ]
        r_mid = np.average(r_soma_syns, axis=0)
        r_mid = r_mid / 2. + cell.somapos

    db_LFP_close = inf_vol.get_dipole_potential(single_dip,
                                                gridpoints_close - r_mid) * k

    # compute LFP far from neuron
    # set up electrodes
    X_f, Z_f = np.meshgrid(np.linspace(-15000, 15001, 101),
                           np.linspace(-15000, 15000, 101))
    Y_f = np.zeros(X.shape)
    grid_electrode_parameters = {
        'x': X_f.flatten(),
        'y': Y_f.flatten(),
        'z': Z_f.flatten()
    }
    # simulate cell
    cell, synapse, grid_electrode_far_LFP = simulate(cell_parameters,
                                                     synapse_parameters,
                                                     grid_electrode_parameters,
                                                     syninds,
                                                     x_rot=x_rot,
                                                     y_rot=y_rot,
                                                     z_rot=z_rot,
                                                     active=active)

    # multicompartment modeling of LFP far from cell
    cb_LFP_far = grid_electrode_far_LFP * k
    # multi-dipole modeling of LFP far from cell
    gridpoints_far = np.array([X_f.flatten(), Y_f.flatten(), Z_f.flatten()]).T
    multi_dip_LFP_far = inf_vol.get_multi_dipole_potential(
        cell, gridpoints_far) * k
    # single-dipole modeling of LFP far from cell
    db_LFP_far = inf_vol.get_dipole_potential(single_dip,
                                              gridpoints_far - r_mid) * k

    cdm = LFPy.CurrentDipoleMoment(cell)
    single_dip = cdm.get_transformation_matrix() @ cell.imem
    time_max = np.argmax(np.abs(np.linalg.norm(single_dip, axis=0)))
    LFP_max = 100.  #nV #np.round(np.max(np.abs(grid_electrode_LFP[:, time_max])))

    return (cell, cb_LFP_close, cb_LFP_far, multi_dip_LFP_close,
            multi_dip_LFP_far, db_LFP_close, db_LFP_far, LFP_max, time_max,
            multi_dips, multi_dip_locs, single_dip, r_mid, X, Z, X_f, Z_f)