Exemplo n.º 1
0
    def test_bad_cell_position_in_slice(self):
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
        }

        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'passive_parameters': {'g_pas': 1. / 30000, 'e_pas': -65},
            'passive': True,
            'tstart': -10,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 1000,

        }
        stick = LFPy.Cell(**stickParams)
        stick.set_rotation(y=np.pi / 2)
        stick.simulate(rec_imem=True)

        stick.set_pos(z=-100)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA.get_transformation_matrix)

        stick.set_pos(z=300)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA.get_transformation_matrix)
Exemplo n.º 2
0
    def test_sqeeze_cell_and_bad_position(self):
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': None,
        }

        stickParams = {
            'morphology': os.path.join(
                LFPy.__path__[0],
                'test',
                'ball_and_sticks.hoc'),
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65},
            'passive': True,
            'tstart': -10,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 1000,
        }
        stick = LFPy.Cell(**stickParams)
        stick.set_rotation(y=np.pi / 2)
        stick.simulate(rec_imem=True)

        stick.set_pos(z=1)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        stick.set_pos(z=199)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': 0.1,
        }

        stick.set_pos(z=-1)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        stick.set_pos(z=201)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)
Exemplo n.º 3
0
    def test_position_shifted_slice(self):
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'z_shift': -200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11) - 100,
            'method': "pointsource",
            'squeeze_cell_factor': None,
        }

        stickParams = {
            'morphology': os.path.join(
                LFPy.__path__[0],
                'test',
                'ball_and_sticks.hoc'),
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65},
            'passive': True,
            'tstart': -10,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 100,
        }
        stick = LFPy.Cell(**stickParams)
        stick.set_rotation(y=np.pi / 2)
        stick.set_pos(z=-100)

        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        MEA._test_cell_extent()
Exemplo n.º 4
0
    def test_return_comp_outside_slice(self):
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': None,
        }

        stickParams = {
            'morphology': os.path.join(
                LFPy.__path__[0],
                'test',
                'ball_and_sticks.hoc'),
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65},
            'passive': True,
            'tstart': -10,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 1000,
        }
        stick = LFPy.Cell(**stickParams)
        stick.set_rotation(y=np.pi / 2)
        stick.set_pos(z=100)
        stick.simulate(rec_imem=True)
        MEA = LFPy.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._return_comp_outside_slice)
        true_bad_comp = np.array([2, 3, 6])

        stick.z[true_bad_comp, 0] = 1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zstart above")
        np.testing.assert_equal(true_bad_comp, bad_comp)
        stick.z[true_bad_comp, 0] = 100

        stick.z[true_bad_comp, 0] = -1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zstart below")
        np.testing.assert_equal(true_bad_comp, bad_comp)
        stick.z[true_bad_comp, 0] = 100

        stick.z[true_bad_comp, 1] = 1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zend above")
        np.testing.assert_equal(true_bad_comp, bad_comp)
        stick.z[true_bad_comp, 1] = 100

        stick.z[true_bad_comp, 1] = -1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zend below")
        np.testing.assert_equal(true_bad_comp, bad_comp)
        stick.z[true_bad_comp, 1] = 100
Exemplo n.º 5
0
        print(
            'Network build finished with {} connections and {} synapses in {} seconds'
            .format(total_conncount, total_syncount, create_connections_time))
        logfile.write('connections {}\n'.format(create_connections_time))
    tic = time()

    ############################################################################
    # Set up extracellular electrode
    ############################################################################
    if PSET.COMPUTE_LFP:
        electrode = LFPy.RecExtElectrode(**PSET.electrodeParams)
    else:
        electrode = None

    if PSET.COMPUTE_ECOG:
        ecog_electrode = LFPy.RecMEAElectrode(**PSET.ecogParameters)
        electrode = [electrode, ecog_electrode]

    ############################################################################
    # Recording of additional variables
    ############################################################################
    if RANK == 0:
        network.t = neuron.h.Vector()
        network.t.record(neuron.h._ref_t)
    else:
        network.t = None

    ############################################################################
    # run simulation, gather results across all RANKs
    ############################################################################
    # Assert that connect routines has finished across RANKS before starting
Exemplo n.º 6
0
    def test_slice_shift_invariance_pointsource(self):
        h = 200
        z_shift_1 = 0
        z_shift_2 = -352

        electrodeParams_1 = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': h,
            'z_shift': z_shift_1,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11) + z_shift_1,
            'squeeze_cell_factor': None,
        }

        electrodeParams_2 = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': h,
            'z_shift': z_shift_2,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11) + z_shift_2,
            'squeeze_cell_factor': None,
        }
        stimParams = {
            'pptype': 'SinSyn',
            'delay': -100.,
            'dur': 1000.,
            'pkamp': 1.,
            'freq': 100.,
            'phase': -np.pi / 2,
            'bias': 0.,
            'record_current': True
        }
        stickParams = {
            'morphology': os.path.join(
                LFPy.__path__[0],
                'test',
                'ball_and_sticks.hoc'),
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65},
            'passive': True,
            'tstart': -10,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 100,
        }
        stick = LFPy.Cell(**stickParams)
        stick.set_rotation(y=np.pi / 2)

        LFPy.StimIntElectrode(stick, stick.get_closest_idx(0, 0, 0),
                              **stimParams)

        stick.simulate(rec_imem=True)

        methods = ["pointsource", "linesource", "root_as_point"]

        for method in methods:
            electrodeParams_1["method"] = method
            electrodeParams_2["method"] = method

            stick.set_pos(z=z_shift_1 + h / 2)
            MEA_shift_1 = LFPy.RecMEAElectrode(stick, **electrodeParams_1)
            M_1 = MEA_shift_1.get_transformation_matrix()

            stick.set_pos(z=z_shift_2 + h / 2)
            MEA_shift_2 = LFPy.RecMEAElectrode(stick, **electrodeParams_2)
            M_2 = MEA_shift_2.get_transformation_matrix()

            np.testing.assert_allclose(M_1 @ stick.imem,
                                       M_2 @ stick.imem, rtol=1E-7)
Exemplo n.º 7
0
        [top_of_cortex] *
        num_ECoG_elecs),  # Assume that top of cortex is 50 um above cell top
    'n': 200,
    'r': 500,  # ECoG radii are often 500-1000 um
    'N': N,
    'method': "pointsource",
}

#perform NEURON simulation, results saved as attributes in the cell instance
cell.simulate(rec_imem=True)

# Initialize electrode geometry, then calculate the LFP, using the
# electrode classes. Note that now cell is given as input to electrode
# and created after the NEURON simulations are finished
electrode = LFPy.RecExtElectrode(cell, **electrodeParameters)
electrode.calc_lfp()
electrode.LFP -= np.average(electrode.LFP, axis=1)[:, None]

electrode_MoI = LFPy.RecMEAElectrode(cell, **elec_with_MoIParameters)
electrode_MoI.calc_lfp()
electrode_MoI.LFP -= np.average(electrode_MoI.LFP, axis=1)[:, None]

ecog_electrode = LFPy.RecMEAElectrode(cell, **ecogParameters)
ecog_electrode.calc_lfp()
ecog_electrode.LFP -= np.average(ecog_electrode.LFP, axis=1)[:, None]

#plotting some variables and geometry, saving output to .pdf.
fig = plot_LFP_and_ECoG(cell, electrode, electrode_MoI, ecog_electrode)
fig.savefig('example_ECoG.pdf', dpi=300)
plt.show()
Exemplo n.º 8
0
MEA_electrode_parameters = {
    'sigma_T' : 0.3,      # extracellular conductivity
    'sigma_G' : 0.0,      # MEA glass electrode plate conductivity
    'sigma_S' : 1.5,      # Saline bath conductivity
    'x' : X.flatten(),  # electrode requires 1d vector of positions
    'y' : Y.flatten(),
    'z' : Z.flatten(),
    "method": "soma_as_point",
    'N' : np.array([[0, 0, 1]]*X.size), #surface normals
    'r' : 50,              # contact site radius
    'n' : 100,               # datapoints for averaging,
    "seedvalue": 12,
    "squeeze_cell_factor": 0.4,
}


# Run simulation, electrode object argument in cell.simulate
print("running simulation...")
cell.simulate(rec_imem=True, rec_vmem=True)


# Create electrode objects
electrode = LFPy.RecExtElectrode(cell, **grid_electrode_parameters)
MEA = LFPy.RecMEAElectrode(cell, **MEA_electrode_parameters)

# Calculate LFPs
MEA.calc_lfp()
electrode.calc_lfp()
plot_results(cell, synapse, MEA, electrode)
plt.show()
Exemplo n.º 9
0
              '{} connections and {} synapses in {} seconds'.format(
                  total_conncount, total_syncount, create_connections_time))
        logfile.write('connections {}\n'.format(create_connections_time))
    tic = time()

    ##########################################################################
    # Set up extracellular electrodes and devices
    ##########################################################################
    probes = []

    if PSET.COMPUTE_LFP:
        electrode = LFPy.RecExtElectrode(cell=None, **PSET.electrodeParams)
        probes.append(electrode)

    if PSET.COMPUTE_ECOG:
        ecog_electrode = LFPy.RecMEAElectrode(cell=None, **PSET.ecogParameters)
        probes.append(ecog_electrode)

    if PSET.COMPUTE_P:
        current_dipole_moment = LFPy.CurrentDipoleMoment(cell=None)
        probes.append(current_dipole_moment)

    ##########################################################################
    # Recording of additional variables
    ##########################################################################
    if RANK == 0:
        network.t = neuron.h.Vector()
        network.t.record(neuron.h._ref_t)
    else:
        network.t = None
Exemplo n.º 10
0
elec_z_mea = np.array([0, 0])

sigma = 1  # S/m
noise_level = 10  # uV

# Define electrode parameters
mea_parameters = {
    'sigma_T': sigma,  # Saline bath conductivity
    'sigma_S': sigma,  # Saline bath conductivity
    'sigma_G': 0,  # Saline bath conductivity
    'x': elec_x_mea,  # electrode requires 1d vector of positions
    'y': elec_y_mea,
    'z': elec_z_mea,
    "method": "soma_as_point",
}
mea_electrode = LFPy.RecMEAElectrode(cell, **mea_parameters)

mea_electrode.calc_lfp()
# mea_electrode.LFP *= 2  # Because of non-conducting electrode plane

soma_diam = 10
elec_x = np.linspace(-200 + soma_diam / 2, -100 + soma_diam / 2, 50)
elec_y = np.zeros(len(elec_x))
elec_z = np.ones(len(elec_x)) * 65

# Define electrode parameters
elec_parameters = {
    'sigma': sigma,  # Saline bath conductivity
    'x': elec_x,  # electrode requires 1d vector of positions
    'y': elec_y,
    'z': elec_z,