Ejemplo n.º 1
0
def test_linearized():

    cell_params_hoc['custom_code'] = [join(model_path, 'custom_codes.hoc'),
                                       join(model_path, 'biophys3_Ih_linearized_mod.hoc')]

    cell_params_py['custom_fun_args'] = [{'conductance_type': 'Ih_linearized',
                                          'hold_potential': -70}]

    plt.seed(0)
    neuron.h('forall delete_section()')
    cell = LFPy.Cell(**cell_params_hoc)
    insert_synapses(synapseParameters_AMPA, cell, **insert_synapses_AMPA_args)
    insert_synapses(synapseParameters_NMDA, cell, **insert_synapses_NMDA_args)
    insert_synapses(synapseParameters_GABA_A, cell, **insert_synapses_GABA_A_args)
    cell.simulate(rec_vmem=True, rec_imem=True)
    plot_cell(cell, '5_linearized_hoc')

    plt.seed(0)
    neuron.h('forall delete_section()')
    cell = LFPy.Cell(**cell_params_py)
    insert_synapses(synapseParameters_AMPA, cell, **insert_synapses_AMPA_args)
    insert_synapses(synapseParameters_NMDA, cell, **insert_synapses_NMDA_args)
    insert_synapses(synapseParameters_GABA_A, cell, **insert_synapses_GABA_A_args)
    cell.simulate(rec_vmem=True, rec_imem=True)
    plot_cell(cell, '5_linearized_py')
Ejemplo n.º 2
0
    def test_cell_tstart_00(self):
        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'cm': 1,
            'Ra': 150,
            'v_init': -65,
            'passive': True,
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 100,
        }

        stimParams = {
            'pptype': 'SinSyn',
            'dur': 1000.,
            'pkamp': 1.,
            'freq': 100.,
            'bias': 0.,
            'record_current': False
        }

        stick0 = LFPy.Cell(tstart=0, tstop=200, **stickParams)
        synapse0 = LFPy.StimIntElectrode(stick0,
                                         stick0.get_closest_idx(0, 0, 1000),
                                         delay=0,
                                         phase=0.,
                                         **stimParams)
        stick0.simulate(rec_imem=True,
                        rec_vmem=True,
                        rec_current_dipole_moment=True)

        stick1 = LFPy.Cell(tstart=-100, tstop=100, **stickParams)
        synapse1 = LFPy.StimIntElectrode(stick1,
                                         stick1.get_closest_idx(0, 0, 1000),
                                         delay=-100,
                                         phase=0.,
                                         **stimParams)
        stick1.simulate(rec_imem=True,
                        rec_vmem=True,
                        rec_current_dipole_moment=True)

        inds = stick0.tvec >= 100
        np.testing.assert_allclose(stick0.vmem[:, inds], stick1.vmem)
        np.testing.assert_allclose(stick0.imem[:, inds], stick1.imem)
        np.testing.assert_allclose(stick0.current_dipole_moment[inds, :],
                                   stick1.current_dipole_moment)
Ejemplo n.º 3
0
def cell_thread(task_queue, done_queue):
    '''thread function for simulation of single neuron process'''
    for n in iter(task_queue.get, 'STOP'):
        print 'Cell number %s out of %d.' % (n, pop_params['n'] - 1)
        cell = LFPy.Cell(**cellparams)

        cell.set_pos(**soma_pos[withsyn_i[n]])
        cell.set_rotation(**rotation[withsyn_i[n]])
        cell.color = 'g'

        #synapses
        e_synparams = e_synparams_init.copy()
        for idx in allidx_e[n]:
            e_synparams = e_synparams_init.copy()
            e_synparams.update({'idx': int(idx), 'color': 'r'})
            e_spiketimes = [pl.array([spiketime])]

            s_e = LFPy.Synapse(cell, **e_synparams)
            s_e.set_spike_times(e_spiketimes[0])

        cell.simulate(**simparams)

        cell.strip_hoc_objects()

        done_queue.put([e_synparams, cell])
Ejemplo n.º 4
0
def return_cell():

    neuron.load_mechanisms("HallermannEtAl2012")
    # Define cell parameters
    cell_parameters = {          # various cell parameters,
        'morphology' : 'unmyelinated_axon_Hallermann.hoc', # Mainen&Sejnowski, 1996
        'v_init' : -80.,    # initial crossmembrane potential
        'passive' : False,   # switch off passive mechs
        'nsegs_method' : 'lambda_f',
        'lambda_f' : 1000.,
        'dt' : 2.**-7,   # [ms] dt's should be in powers of 2
        'tstart' : -200.,    # start time of simulation, recorders start at t=0
        'tstop' : 2.,   # stop simulation at 2 ms.
    }

    cell = LFPy.Cell(**cell_parameters)
    cell.set_pos(x=-np.max(cell.xmid) / 2, z=2.5)

    #  To induce a spike:
    synapseParameters = {
        'idx' : 0,               # insert synapse on index "0", the soma
        'e' : 0.,                # reversal potential of synapse
        'syntype' : 'Exp2Syn',   # conductance based double-exponential synapse
        'tau1' : 0.1,            # Time constant, decay
        'tau2' : 0.1,            # Time constant, decay
        'weight' : 0.004,         # Synaptic weight
        'record_current' : False, # Will enable synapse current recording
    }

    # attach synapse with parameters and input time
    synapse = LFPy.Synapse(cell, **synapseParameters)
    synapse.set_spike_times(np.array([0.1]))

    cell.simulate(rec_vmem=True, rec_imem=True)
    return cell
Ejemplo n.º 5
0
def simulate(cell_parameters, synapse_parameters, grid_electrode_parameters, syninds, x_rot=0, y_rot=0, z_rot=0, active=False):
    """set synapse location. simulate cell, synapse and electrodes for input synapse location"""

    # create cell with parameters in dictionary
    if not active:
        cell = LFPy.Cell(**cell_parameters)
    else:
        cell = LFPy.TemplateCell(**cell_parameters)

    # rotate cell
    cell.set_rotation(x=x_rot)
    cell.set_rotation(y=y_rot)
    cell.set_rotation(z=z_rot)

    # insert synapses
    if type(syninds) == int:
        syninds = [syninds]
    for idx in syninds:
        synapse_parameters['idx'] = idx
        synapse = LFPy.Synapse(cell, **synapse_parameters)
        synapse.set_spike_times(np.array([20.]))

    # simulate cell
    cell.simulate(rec_imem = True,
                  rec_vmem = True,
                  rec_current_dipole_moment=True)

    #create grid electrodes
    grid_electrode = LFPy.RecExtElectrode(cell, **grid_electrode_parameters)
    grid_electrode.calc_lfp()

    return cell, synapse, grid_electrode
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
 def test_StimIntElectrode_02(self):
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'),
                      dt=1.,
                      v_init=-65.,
                      Ra=150.,
                      cm=1.,
                      passive=True,
                      passive_parameters=dict(g_pas=1. / 30000, e_pas=-65))
     stim = LFPy.StimIntElectrode(cell=cell,
                                  record_potential=True,
                                  **{
                                      'idx': 0,
                                      'pptype': 'SEClamp',
                                      'amp1': -65,
                                      'dur1': 10,
                                      'amp2': -55.,
                                      'dur2': 20,
                                      'amp3': -65,
                                      'dur3': 10,
                                  })
     cell.simulate()
     gt = np.zeros(cell.tvec.size) - 65.
     gt[(cell.tvec > 10.) & (cell.tvec <= 30.)] = -55.
     np.testing.assert_allclose(gt, cell.somav, rtol=1E-2)
     np.testing.assert_equal(cell.somav, stim.v)
Ejemplo n.º 8
0
def test_active_no_input():
    plt.seed(0)
    cell_params_hoc['custom_code'] = [join(model_path, 'custom_codes.hoc'),
                                      join(model_path, 'biophys3_active.hoc')]
    cell_params_py['custom_fun_args'] = [{'conductance_type': 'active'}]

    neuron.h('forall delete_section()')
    cell = LFPy.Cell(**cell_params_hoc)
    cell.simulate(rec_vmem=True, rec_imem=True)
    plot_cell(cell, '3_active_no_input_hoc')

    plt.seed(0)
    neuron.h('forall delete_section()')
    cell = LFPy.Cell(**cell_params_py)
    cell.simulate(rec_vmem=True, rec_imem=True)
    plot_cell(cell, '3_active_no_input_py')
Ejemplo n.º 9
0
def stickSimulationTesttvec(**kwargs):
    stick = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'stick.hoc'),
                      verbose=False,
                      **kwargs)
    stick.simulate(rec_imem=False)
    return stick.tvec
Ejemplo n.º 10
0
 def test_cell_strip_hoc_objects_00(self):
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'))
     cell.strip_hoc_objects()
     for attribute in dir(cell):
         self.assertNotEqual(str(type(getattr(cell, attribute))),
                             'hoc.HocObject')
Ejemplo n.º 11
0
    def test_cell_simulate_current_dipole_moment_02(self):
        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'cm': 1,
            'Ra': 150,
            'v_init': -65,
            'passive': True,
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'tstart': -100,
            'tstop': 100,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 100,
        }

        stimParams = {
            'e': 0,  # reversal potential
            'syntype': 'Exp2Syn',  # synapse type
            'tau1': 0.1,  # syn. time constant
            'tau2': 2.,  # syn. time constant
            'weight': 0.01,
        }

        for idx in range(31):  #31 segments
            if idx != 15:  # no net dipole moment because of stick symmetry
                stick = LFPy.Cell(**stickParams)
                synapse = LFPy.Synapse(stick, idx=idx, **stimParams)
                synapse.set_spike_times(np.array([10., 20., 30., 40., 50.]))
                stick.simulate(rec_imem=True, rec_current_dipole_moment=True)
                p = np.dot(stick.imem.T, np.c_[stick.xmid, stick.ymid,
                                               stick.zmid])
                np.testing.assert_allclose(p, stick.current_dipole_moment)
Ejemplo n.º 12
0
    def test_cell_chiral_morphology_02(self):
        '''test LFPy.Cell.chiral_morphology()'''
        cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                 'ball_and_sticks.hoc'))

        xstarts = cell.xstart.copy()
        xmids = cell.xmid.copy()
        xends = cell.xend.copy()
        ystarts = cell.ystart.copy()
        ymids = cell.ymid.copy()
        yends = cell.yend.copy()
        zstarts = cell.zstart.copy()
        zmids = cell.zmid.copy()
        zends = cell.zend.copy()
        # test rotation 180 deg around z-axis
        cell.chiral_morphology(axis='z')
        # assert that y- and z-coordinates are inverted, using absolute
        # tolerances
        np.testing.assert_allclose(cell.xstart, xstarts, atol=1e-07)
        np.testing.assert_allclose(cell.xmid, xmids, atol=1e-07)
        np.testing.assert_allclose(cell.xend, xends, atol=1e-07)
        np.testing.assert_allclose(cell.ystart, ystarts, atol=1e-07)
        np.testing.assert_allclose(cell.ymid, ymids, atol=1e-07)
        np.testing.assert_allclose(cell.yend, yends, atol=1e-07)
        np.testing.assert_allclose(cell.zstart, -zstarts, atol=1e-07)
        np.testing.assert_allclose(cell.zmid, -zmids, atol=1e-07)
        np.testing.assert_allclose(cell.zend, -zends, atol=1e-07)
Ejemplo n.º 13
0
 def test_cell_get_rand_prob_area_norm_from_idx(self):
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'))
     p = cell.get_rand_prob_area_norm_from_idx(idx=cell.get_idx(
         section='allsec'))
     self.assertListEqual(cell.get_rand_prob_area_norm().tolist(),
                          p.tolist())
Ejemplo n.º 14
0
    def test_cell_set_rotation_06(self):
        '''test LFPy.Cell.set_rotation()'''
        cell = LFPy.Cell(
            morphology=os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'))

        xstarts = cell.xstart.copy()
        xmids = cell.xmid.copy()
        xends = cell.xend.copy()
        ystarts = cell.ystart.copy()
        ymids = cell.ymid.copy()
        yends = cell.yend.copy()
        zstarts = cell.zstart.copy()
        zmids = cell.zmid.copy()
        zends = cell.zend.copy()
        # test rotation: 90 deg around x-axis, 90 deg around y-axis, 90 deg around z-axis
        cell.set_rotation(x=np.pi / 2., y=np.pi, z=np.pi / 4.)
        # revert rotation: -90 deg around x-axis, -90 deg around y-axis, -90 deg around z-axis, rotation_order='zyx'
        cell.set_rotation(x=-np.pi / 2.,
                          y=-np.pi,
                          z=-np.pi / 4.,
                          rotation_order='zyx')
        # assert that x-, y- and z-coordinates are same as beginning, using absolute
        # tolerances
        np.testing.assert_allclose(cell.xstart, xstarts, atol=1e-07)
        np.testing.assert_allclose(cell.xmid, xmids, atol=1e-07)
        np.testing.assert_allclose(cell.xend, xends, atol=1e-07)
        np.testing.assert_allclose(cell.ystart, ystarts, atol=1e-07)
        np.testing.assert_allclose(cell.ymid, ymids, atol=1e-07)
        np.testing.assert_allclose(cell.yend, yends, atol=1e-07)
        np.testing.assert_allclose(cell.zstart, zstarts, atol=1e-07)
        np.testing.assert_allclose(cell.zmid, zmids, atol=1e-07)
        np.testing.assert_allclose(cell.zend, zends, atol=1e-07)
Ejemplo n.º 15
0
 def test_cell_set_pos_06(self):
     '''test LFPy.Cell.set_pos'''
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'),
                      pt3d=True)
     np.testing.assert_allclose(cell.somapos,
                                [cell.xmid[0], cell.ymid[0], cell.zmid[0]])
Ejemplo n.º 16
0
 def test_cell_set_pos_02(self):
     '''test LFPy.Cell.set_pos'''
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'),
                      pt3d=True)
     cell.set_pos(10., 20., -30.)
     np.testing.assert_allclose(cell.somapos, [10., 20., -30.])
Ejemplo n.º 17
0
def cell_thread_PSC(task_queue, done_queue):
    '''thread function for simulation of single neuron process'''
    for n in iter(task_queue.get, 'STOP'):
        print 'Cell number %s out of %d.' % (n, pop_params['n'] - 1)
        cell = LFPy.Cell(**cellparams)

        e_synparams = e_synparams_init.copy()
        for idx in allidx_e[n]:
            e_synparams = e_synparams_init.copy()
            e_synparams.update({'idx': int(idx), 'color': (0.8, 0.8, 0.8)})
            e_spiketimes = [pl.array([spiketime])]

            s_e = LFPy.Synapse(cell, **e_synparams)
            s_e.set_spike_times(e_spiketimes[0])

        e_synparams = e_synparams_init.copy()

        LFPy.StimIntElectrode(cell, **pointprocparams)

        cell.simulate(**simparams2)
        cell.tvec = pl.arange(
            -1, cellparams['timeres_python'] * len(cell.tvec) - 1,
            cellparams['timeres_python'])

        cell.strip_hoc_objects()

        done_queue.put(cell)
Ejemplo n.º 18
0
    def test_Synapse_01(self):
        cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                 'ball_and_sticks.hoc'))
        syn0 = LFPy.Synapse(cell=cell,
                            idx=0,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=True,
                            record_potential=True)
        syn0.set_spike_times(np.array([10.]))

        syn1 = LFPy.Synapse(cell=cell,
                            idx=1,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=True,
                            record_potential=False)
        syn1.set_spike_times(np.array([20.]))

        syn2 = LFPy.Synapse(cell=cell,
                            idx=2,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=False,
                            record_potential=True)
        syn2.set_spike_times(np.array([30.]))

        syn3 = LFPy.Synapse(cell=cell,
                            idx=3,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=False,
                            record_potential=False)
        syn3.set_spike_times(np.array([40.]))

        cell.simulate()

        i = np.zeros(cell.tvec.size)
        i[cell.tvec > 10.] = -np.exp(-np.arange(
            (cell.tvec > 10.).sum()) * cell.dt / 5.)

        np.testing.assert_allclose(i, syn0.i, rtol=1E-1)
        np.testing.assert_equal(cell.somav, syn0.v)

        self.assertTrue(hasattr(syn1, 'i'))
        i = np.zeros(cell.tvec.size)
        i[cell.tvec > 20.] = -np.exp(-np.arange(
            (cell.tvec > 20.).sum()) * cell.dt / 5.)
        self.assertFalse(hasattr(syn1, 'v'))
        np.testing.assert_allclose(i, syn1.i, rtol=1E-1)

        self.assertFalse(hasattr(syn2, 'i'))
        self.assertTrue(hasattr(syn2, 'v'))

        self.assertFalse(hasattr(syn3, 'i'))
        self.assertFalse(hasattr(syn3, 'v'))
Ejemplo n.º 19
0
def cell_w_synapse_from_sections(morphology):
    '''
    Make cell and synapse objects, set spike, simulate and return cell
    '''
    cellParams = {
        'morphology': morphology,
        'cm': 1,
        'Ra': 150,
        'v_init': -65,
        'passive': True,
        'passive_parameters': {
            'g_pas': 1. / 30000,
            'e_pas': -65
        },
        'dt': 2**-6,
        'tstart': -50,
        'tstop': 50,
        'delete_sections': False
    }

    synapse_parameters = {
        'e': 0.,
        'syntype': 'ExpSyn',
        'tau': 5.,
        'weight': .001,
        'record_current': True,
        'idx': 1
    }

    cell = LFPy.Cell(**cellParams)
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([1.]))
    cell.simulate(rec_current_dipole_moment=True, rec_vmem=True)
    return cell
Ejemplo n.º 20
0
    def test_sigma_inputs(self):
        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'passive_parameters': {'g_pas': 1. / 30000, 'e_pas': -65},
            'passive': True,
            'tstart': 0,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 1000,

        }
        stick = LFPy.Cell(**stickParams)

        electrodeParams = {
            'cell': stick,
            'sigma': [0.3, 0.3, 0.3, 0.3],
            'x': np.ones(11) * 100.,
            'y': np.zeros(11),
            'z': np.linspace(1000, 0, 11),
        }

        np.testing.assert_raises(
            ValueError,
            LFPy.RecExtElectrode,
            **electrodeParams)
Ejemplo n.º 21
0
def return_cell_morphology(cell_name, cell_folder, pt3d=False):
    """ Function to load cell models

    Parameters:
    -----------
    cell_name : string
        Name of the cell type.
    cell_folder : string
        Folder containing cell models.
    pt3d : bool
        If True detailed 3d morphology is used

    Returns:
    --------
    cell : object
        LFPy cell object
    """
    import mpi4py.MPI
    import LFPy

    if not os.path.isdir(join(cell_folder, cell_name)):
        raise NotImplementedError('Cell model %s is not found in %s' \
                                  % (cell_name, cell_folder))

    morphologyfile = os.listdir(join(cell_folder, cell_name, 'morphology'))[0]
    morphology = join(cell_folder, cell_name, 'morphology', morphologyfile)

    cell = LFPy.Cell(morphology=morphology, pt3d=pt3d)
    return cell
Ejemplo n.º 22
0
def test_morphology(hold_potential, cellname):

    timeres = 2**-4
    cut_off = 0
    tstopms = 100
    tstartms = -cut_off
    model_path = cellname

    cell_params = {
        'morphology': join(model_path, '%s.hoc' % cellname),
        #'rm' : 30000,               # membrane resistance
        #'cm' : 1.0,                 # membrane capacitance
        #'Ra' : 100,                 # axial resistance
        'v_init': hold_potential,             # initial crossmembrane potential
        'passive': False,           # switch on passive mechs
        'nsegs_method': 'lambda_f',  # method for setting number of segments,
        'lambda_f': 100,           # segments are isopotential at this frequency
        'timeres_NEURON': timeres,   # dt of LFP and NEURON simulation.
        'timeres_python': timeres,
        'tstartms': tstartms,          # start time, recorders start at t=0
        'tstopms': tstopms,
        'custom_fun': [active_declarations],  # will execute this function
        'custom_fun_args': [{'use_channels': ['Ih_frozen', 'Im_frozen', 'INaP_frozen'],
                             'cellname': model_path,
                             'hold_potential': hold_potential}],
    }

    cell = LFPy.Cell(**cell_params)

    if 1:
        [plt.plot([cell.xstart[i], cell.xend[i]], [cell.zstart[i], cell.zend[i]], 'k') for i in xrange(cell.totnsegs)]
        [plt.text(cell.xmid[i], cell.zend[i], '%1.2f' % cell.diam[i], color='r') for i in xrange(cell.totnsegs)]

        plt.axis('equal')
        plt.show()
Ejemplo n.º 23
0
    def test_isotropic_version_of_anisotropic_methods(self):

        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'passive': True,
            'tstart': 0,
            'tstop': 20,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 1000,
        }
        stimParams = {
            'pptype': 'SinSyn',
            'delay': -100.,
            'dur': 1000.,
            'pkamp': 1.,
            'freq': 100.,
            'phase': -np.pi / 2,
            'bias': 0.,
            'record_current': True
        }

        isotropic_electrodeParams = {
            'sigma': 0.3,
            'x': np.ones(11) * 100.,
            'y': np.zeros(11),
            'z': np.linspace(1000, 0, 11),
        }
        anisotropic_electrodeParams = isotropic_electrodeParams.copy()
        anisotropic_electrodeParams["sigma"] = [
            isotropic_electrodeParams["sigma"]
        ] * 3

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

        for method in methods:
            isotropic_electrodeParams["method"] = method
            anisotropic_electrodeParams["method"] = method

            isotropic_electrode = LFPy.RecExtElectrode(
                **isotropic_electrodeParams)
            anisotropic_electrode = LFPy.RecExtElectrode(
                **anisotropic_electrodeParams)

            stick = LFPy.Cell(**stickParams)
            stick.set_pos(z=-stick.zstart[0])

            synapse = LFPy.StimIntElectrode(stick,
                                            stick.get_closest_idx(0, 0, 1000),
                                            **stimParams)
            stick.simulate([isotropic_electrode, anisotropic_electrode],
                           rec_imem=True,
                           rec_vmem=True)

            np.testing.assert_allclose(isotropic_electrode.LFP,
                                       anisotropic_electrode.LFP)
Ejemplo n.º 24
0
def test_plot_neuron():
    hay_cell = LFPy.Cell(morphology=hay_morphology,
                         pt3d=True,
                         delete_sections=True)

    # basic plotting
    ax_xy = nplt.plot_neuron(cell=hay_cell, plane='xy')
    ax_yz = nplt.plot_neuron(cell=hay_cell, plane='yz')
    ax_xz = nplt.plot_neuron(cell=hay_cell, plane='xz')
    ax_3d = nplt.plot_neuron(cell=hay_cell, plane='3d')
    fig_proj, axes = nplt.plot_neuron(cell=hay_cell,
                                      projections3d=True,
                                      alpha=0.1)

    # with morphology
    ax_xy = nplt.plot_neuron(morphology=hay_morphology, plane='xy')

    # with args
    ax = nplt.plot_neuron(morphology=hall_morphology, plane='xy', alpha=0.2)
    ax = nplt.plot_neuron(morphology=hall_morphology,
                          plane='xy',
                          exclude_sections=['axon', 'my', 'node'])
    ax = nplt.plot_neuron(morphology=hall_morphology,
                          plane='xy',
                          xlim=[-50, 50],
                          ylim=[-50, 200])
    ax = nplt.plot_neuron(morphology=hall_morphology,
                          plane='xy',
                          color_soma='C0',
                          color_dend='C1',
                          color_apic='C2',
                          color='black')
Ejemplo n.º 25
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)
Ejemplo n.º 26
0
def test_plot_detailed_neuron():
    ax_xyd = nplt.plot_detailed_neuron(morphology=hall_morphology, plane='xy')
    ax_xzd = nplt.plot_detailed_neuron(morphology=hall_morphology, plane='xz')
    ax_yzd = nplt.plot_detailed_neuron(morphology=hall_morphology, plane='yz')
    ax_3dd = nplt.plot_detailed_neuron(morphology=hall_morphology, plane='3d')

    # with cell
    hall_cell = LFPy.Cell(morphology=hall_morphology,
                          pt3d=True,
                          delete_sections=True)
    ax_xyd = nplt.plot_detailed_neuron(cell=hall_cell, plane='xy')

    # with args
    ax = nplt.plot_detailed_neuron(morphology=hall_morphology,
                                   plane='xy',
                                   alpha=0.2)
    ax = nplt.plot_detailed_neuron(morphology=hall_morphology,
                                   plane='xy',
                                   exclude_sections=['axon', 'my', 'node'])
    ax = nplt.plot_detailed_neuron(morphology=hall_morphology,
                                   plane='xy',
                                   xlim=[-50, 50],
                                   ylim=[-50, 200])
    ax = nplt.plot_detailed_neuron(morphology=hall_morphology,
                                   plane='xy',
                                   color_soma='C0',
                                   color_dend='C1',
                                   color_apic='C2',
                                   color='black')
def make_cell(morphologyPath, cell_z_pos, upsideDown=False):

    cell_parameters = {
        'morphology': morphologyPath,
        'v_init': -65,
        'passive': True,
        'nsegs_method': 'lambda_f',
        'lambda_f': 100,  # Higher number means higher spatial resolution of the cell
        'timeres_NEURON': 2**-3,  # Should be a power of 2
        'timeres_python': 2**-3,
        'tstartms': 0,
        'tstopms': 50,
    }
    cell = LFPy.Cell(**cell_parameters)
    # Specify the position and rotation of the cell
    cell.set_pos(zpos=cell_z_pos)
    if upsideDown:
        cell.set_rotation(y=np.pi)

    plot_morph = True
    if plot_morph:
        ax2 = plt.subplot(1, 2, 1, aspect=1, xlabel='x [$\mu m$]', ylabel='y [$\mu m$]', axisbg='c')
        ax4 = plt.subplot(1, 2, 2, aspect=1, xlabel='x [$\mu m$]', ylabel='z [$\mu m$]', axisbg='c', sharex=ax2)

        for idx in range(cell.totnsegs):  # Argsort to have important compartments in front (visible)
            if idx == 0:
                ax2.plot(cell.xmid[0], cell.ymid[0], 'o', ms=15, mec='none', c='k')
                ax4.plot(cell.xmid[0], cell.zmid[0], 'o', ms=15, mec='none', c='k')
            else:
                #  Plot soma as ball
                ax2.plot([cell.xstart[idx], cell.xend[idx]], [cell.ystart[idx], cell.yend[idx]], c='k', lw=1.5)
                ax4.plot([cell.xstart[idx], cell.xend[idx]], [cell.zstart[idx], cell.zend[idx]], c='k', lw=1.5)
        
        plt.show()
Ejemplo n.º 28
0
def make_cell(morphology, morph_type='l23'):
    """set synapse location. simulate cell, synapse and electrodes for input synapse location"""

    cell_parameters = {
        'v_init': -70,
        'morphology': morphology,
        'passive_parameters': {
            'g_pas': 1. / 30000,
            'e_pas': -70
        },  # S/cm^2, mV
        'Ra': 150,  # Ω cm
        'cm': 1,  # µF/cm^2
        'nsegs_method': "lambda_f",
        "lambda_f": 100,
        'dt': 2**-4,  # [ms] Should be a power of 2
        'tstart': -10,  # [ms] Simulation start time
        'tstop': 250,  # [ms] Simulation end time
        "pt3d": True,
        'passive': True
    }

    # create cell with parameters in dictionary
    print('initiate cell')
    cell = LFPy.Cell(**cell_parameters)

    # rotate cell
    if morph_type == 'l23':
        cell.set_rotation(x=-np.pi / 2)
        cell.set_rotation(y=-np.pi / 7)
    else:
        cell.set_rotation(x=np.pi / 2)

    return cell
Ejemplo n.º 29
0
 def test_PointProcess_00(self):
     cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                              'ball_and_sticks.hoc'))
     pp = LFPy.PointProcess(cell=cell, idx=0)
     self.assertTrue(
         np.alltrue(np.array([pp.x, pp.y, pp.z]) == cell.somapos))
     self.assertEqual(pp.idx, 0)
Ejemplo n.º 30
0
def return_bbp_cell_morphology(cell_name, cell_folder, pt3d=False):
    """ Function to load cell models

    Parameters:
    -----------
    cell_name : string
        Name of the cell type.
    cell_folder : string
        Folder containing cell models.
    pt3d : bool
        If True detailed 3d morphology is used

    Returns:
    --------
    cell : object
        LFPy cell object
    """
    LFPy, neuron = import_LFPy_neuron()
    cell_folder = Path(cell_folder)

    if not (cell_folder / cell_name).is_dir():
        raise NotImplementedError(
            f'Cell model {cell_name} is not found in {cell_folder}')

    morphology_files = [
        f for f in (cell_folder / cell_name / 'morphology').iterdir()
    ]
    if len(morphology_files) > 1:
        raise Exception(
            f"More than 1 morphology file found for cell {cell_name}")
    morphology = morphology_files[0]

    cell = LFPy.Cell(morphology=str(morphology), pt3d=pt3d)
    return cell