Esempio n. 1
0
    def create_net():
        # Use a bit of a complicated spike and connection pattern with
        # heterogeneous delays

        # Note: it is important that all objects have the same name, this would
        # be the case if we were running this in a new process but to not rely
        # on garbage collection we will assign explicit names here
        source = SpikeGeneratorGroup(
            5,
            np.arange(5).repeat(3),
            [3, 4, 1, 2, 3, 7, 5, 4, 1, 0, 5, 9, 7, 8, 9] * ms,
            name='source')
        target = NeuronGroup(10, 'v:1', name='target')
        synapses = Synapses(source,
                            target,
                            model='w:1',
                            on_pre='v+=w',
                            name='synapses')
        synapses.connect('j>=i')
        synapses.w = 'i*1.0 + j*2.0'
        synapses.delay = '(5-i)*ms'
        state_mon = StateMonitor(target, 'v', record=True, name='statemonitor')
        input_spikes = SpikeMonitor(source, name='input_spikes')
        net = Network(source, target, synapses, state_mon, input_spikes)
        return net
Esempio n. 2
0
def test_store_restore_to_file_differing_nets():
    # Check that the store/restore mechanism is not used with differing
    # networks
    filename = tempfile.mktemp(suffix='state', prefix='brian_test')

    source = SpikeGeneratorGroup(5, [0, 1, 2, 3, 4], [0, 1, 2, 3, 4] * ms,
                                 name='source_1')
    mon = SpikeMonitor(source, name='monitor')
    net = Network(source, mon)
    net.store(filename=filename)

    source_2 = SpikeGeneratorGroup(5, [0, 1, 2, 3, 4], [0, 1, 2, 3, 4] * ms,
                                   name='source_2')
    mon = SpikeMonitor(source_2, name='monitor')
    net = Network(source_2, mon)
    assert_raises(KeyError, lambda: net.restore(filename=filename))

    net = Network(source)  # Without the monitor
    assert_raises(KeyError, lambda: net.restore(filename=filename))
Esempio n. 3
0
def test_spikegenerator():
    """
    Test dictionary representation of SpikeGenerator
    """

    # example 1
    size = 1
    index = [0]
    time = [10] * ms

    spike_gen = SpikeGeneratorGroup(size, index, time)
    spike_gen_dict = collect_SpikeGenerator(spike_gen, get_local_namespace(0))

    assert spike_gen_dict['N'] == size
    assert spike_gen_dict['indices'] == [0]
    assert spike_gen_dict['indices'].dtype == int

    assert spike_gen_dict['times'] == time
    assert spike_gen_dict['times'].has_same_dimensions(10 * ms)
    assert spike_gen_dict['times'].dtype == float

    # example 2
    spike_gen2 = SpikeGeneratorGroup(10, index, time, period=20 * ms)
    var = 0.00002
    spike_gen2.run_regularly('var = var + 1', dt=10 * ms, name='spikerr')
    spike_gen_dict = collect_SpikeGenerator(spike_gen2,
                                            get_local_namespace(0))

    assert spike_gen_dict['N'] == 10
    assert spike_gen_dict['period'] == [20] * ms
    assert spike_gen_dict['period'].has_same_dimensions(20 * ms)
    assert spike_gen_dict['period'].dtype == float

    # (check run_regularly)
    assert spike_gen_dict['run_regularly'][0]['name'] == 'spikerr'
    assert spike_gen_dict['run_regularly'][0]['code'] == 'var = var + 1'
    assert spike_gen_dict['run_regularly'][0]['dt'] == 10 * ms
    assert spike_gen_dict['run_regularly'][0]['when'] == 'start'
    assert spike_gen_dict['run_regularly'][0]['order'] == 0
    assert spike_gen_dict['identifiers']['var'] == var
    with pytest.raises(IndexError):
        spike_gen_dict['run_regularly'][1]
Esempio n. 4
0
def get_stimulus(start, stop, frequency):
    """
    start -- start time of stimulus
    stop -- stop time of stimulus
    frequency -- frequency of stimulus
    """

    times = np.arange(start / ms, stop / ms, 1 / (frequency / Hz) * 1e3) * ms
    stimulus = SpikeGeneratorGroup(1, [0] * len(times), times)

    return stimulus
Esempio n. 5
0
def test_simple_syntax():
    """
    Simple example
    """
    set_device('markdown')
    N = 10
    tau = 10 * ms
    v_th = 0.9 * volt
    v_rest = -79 * mV
    eqn = 'dv/dt = (v_th - v)/tau :volt'
    refractory = 'randn() * tau / N'
    rates = 'rand() * 5 * Hz'
    group = NeuronGroup(N, eqn, method='euler', threshold='v > v_th',
                        reset='v = v_rest; v = rand() * v_rest',
                        refractory=refractory,
                        events={'custom': 'v > v_th + 10 * mV',
                        'custom_1': 'v > v_th - 10 * mV'})
    group.run_on_event('custom', 'v = v_rest')
    group.run_on_event('custom_1', 'v = v_rest - 0.001 * mV')
    spikegen = SpikeGeneratorGroup(N, [0, 1, 2], [1, 2, 3] * ms,
                                   period=5 * ms)
    po_grp = PoissonGroup(N - 1, rates=rates)
    syn = Synapses(spikegen, group, model='w :volt',
                   on_pre='v = rand() * w + v_th; v = rand() * w',
                   on_post='v = rand() * w + v_rest; v = rand() * w',
                   delay=tau, method='euler')
    group.v[:] = v_rest
    group.v['i%2 == 0'] = 'rand() * v_rest'
    group.v[0:5] = 'v_rest + 10 * mV'
    condition = 'abs(i-j)<=5'
    syn.connect(condition=condition, p=0.999, n=2)
    syn.w = '1 * mV'
    net = Network(group, spikegen, po_grp, syn)
    mon = StateMonitor(syn, 'w', record=True)
    mon2 = SpikeMonitor(po_grp)
    mon3 = EventMonitor(group, 'custom')
    net.add(mon, mon2, mon3)
    net.run(0.01 * ms)
    md_str = device.md_text
    assert _markdown_lint(md_str)
    check = 'randn({sin({$w$}|$v_rest$ - $v$|/{\tau}})})'
    assert _markdown_lint(check)
    # check invalid strings
    with pytest.raises(SyntaxError):
        check = '**Initializing values at starting:*'
        assert _markdown_lint(check)
        check = '- Variable v$ of with $-79. mV$ to all members'
        assert _markdown_lint(check)
        check = 'randn({sin(})})'
        assert _markdown_lint(check)
        check = 'randn({sin({$w$}|$v_rest$ - $v$|/{\tau})})'
        assert _markdown_lint(check)
    device.reinit()
Esempio n. 6
0
def test_spikemonitor():
    """
    Test collector function for SpikeMonitor
    """

    # example 1
    grp = NeuronGroup(5,
                      '''dv/dt = (v0 - v)/tau :volt''',
                      method='exact',
                      threshold='v > v_th',
                      reset='v = v0',
                      name="My_Neurons")
    tau = 10 * ms
    v0 = -70 * mV
    v_th = 800 * mV
    mon = SpikeMonitor(grp, 'v', record=[0, 4])
    mon_dict = collect_SpikeMonitor(mon)

    assert mon_dict['source'] == 'My_Neurons'
    assert mon_dict['variables'].sort() == ['i', 't', 'v'].sort()
    assert mon_dict['record'] == [0, 4]
    assert mon_dict['event'] == 'spike'
    assert mon_dict['when'] == 'thresholds'
    assert mon_dict['order'] == 1

    # example 2
    pos = PoissonGroup(5, rates=100 * Hz)
    smon = SpikeMonitor(pos, record=[0, 1, 2, 3, 4])
    smon_dict = collect_SpikeMonitor(smon)

    assert smon_dict['source'] == pos.name
    assert 'i' in smon_dict['variables']

    assert smon_dict['record'] == [0, 1, 2, 3, 4]
    assert smon_dict['when'] == 'thresholds'
    assert smon_dict['order'] == 1

    # example 3
    spk = SpikeGeneratorGroup(10, [2, 6, 8], [5 * ms, 10 * ms, 15 * ms])
    spkmon = SpikeMonitor(spk, ['t', 'i'], record=0)
    smon_dict = collect_SpikeMonitor(spkmon)

    assert smon_dict['record'] == np.array([0])
    assert 't' in smon_dict['variables']
    assert smon_dict['source'] == spk.name
    assert smon_dict['when'] == 'thresholds'
    assert smon_dict['order'] == 1
Esempio n. 7
0
def setup_generator(components):
    """
    Setup the spike generator with 4+1 neurons and a spike monitor.
    The first 4 neurons represent the 4 input components in the
    following order: [I.up, I.dn, Q.up, Q.dn]. The last neuron
    fires a stop signal at the end of each input stimulus
    
    Parameters
    ----------
    components : object
        previously defined network components

    Returns
    -------
    components : dict
        network components
    """
    gGen = SpikeGeneratorGroup(5, np.array([]), np.array([]) * ms, name='gGen')
    mGen = SpikeMonitor(gGen, name='mGen')
    components['generator'] = gGen
    components['monitors']['mGen'] = mGen
    return components
nAnfsPerInputFile = 40

nGbcsCoPerLson = 8  # Gjoni et al. 2018
nSbcsIpPerLson = 40  # Gjoni et al. 2018
#nGbcsCoPerLson = 1  # showing unitary IPSP
#nSbcsIpPerLson = 1 # showing unitary EPSP

#gbCoCellIndices = np.array([0])
#gbCoSpkTimes = np.array([10.0]) * ms

sbIpCellIndices = np.array([0])
sbIpSpkTimes = np.array([5.0]) * ms

#gbCoSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, gbCoCellIndices, gbCoSpkTimes)
sbIpSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, sbIpCellIndices,
                                    sbIpSpkTimes)

# Membrane and Ion-Channel parameters
C = 21.7 * pF  # 21.7pF: non-principal LSO neuron (Barnes-Davies et al. 2004)
Eh = -43 * mV
EK = -70 * mV  # -77*mV in mod file
El = -65 * mV
ENa = 50 * mV
nf = 0.85  # proportion of n vs p kinetics
zss = 0.5  # steady state inactivation of glt
# default temp_degC = 37., human body temperature in degree celcius
# q10 for ion-channel time-constants (RM2003, p.3106):
q10 = 3.**((temp_degC - 22.) / 10.)
# q10 for ion-channel gbar parameters (RM2003, p.3106):
q10gbar = 2.**((temp_degC - 22.) / 10.)
# hcno current (octopus cell)
Esempio n. 9
0
# Be careful to check that the offset data will stay within network boundaries

xoff = 2
yoff = 3
for k in range(num_orientations):
    pop_data_R[str(k)] = pop_data_R[str(k)] + xoff + yoff * input_size_x

#%% Spike generators - Simple Neruon stimuli
# Set two spike generators that will play the data recorded during the esecution
# of Monocular_neurons.py

simple_neurons_L = []
simple_neurons_R = []
for k in range(num_orientations):
    simple_neurons_L.append(
        SpikeGeneratorGroup(num_input_neurons, pop_data_L[str(k)],
                            pop_data_L[str(k) + 't']))
    simple_neurons_R.append(
        SpikeGeneratorGroup(num_input_neurons, pop_data_R[str(k)],
                            pop_data_R[str(k) + 't']))

#%% Setting up Network

start_time = time.time()

start = pop_data_L['start']
end = pop_data_L['end']

Net = teiliNetwork()

# Neurons
disparity_neurons = []
Esempio n. 10
0
def lson(lsoInputSpkFileTuple, temp_degC=37):

    defaultclock.dt = 0.02*ms # for better precision
    
    neuron_type = 'LsoNp1a' # non-principal, moderately slow (typical)
    Vrest = -64.1*mV # observed resting potential for model LsoNp1a
    
    nLsons = 1 # number of LSO neurons
    
    # As in Wang & Colburn (2012), the LSO model has simplified inputs.
    # Spike times from model auditory nerve fibers represent inputs
    # driven by the cochlear nucleus: contralateral inhibitory inputs
    # driven by globular bushy cells via the MNTB, and ipsilateral
    # excitatory inputs from spherical bushy cells.
    
    nAnfsPerInputFile = 40

    nGbcsCoPerLson = 8  # Gjoni et al. 2018
    nSbcsIpPerLson = 40 # Gjoni et al. 2018

#    sbCoSpkFile = inputSpkFileTuple[0]
#    sbIpSpkFile = lsoInputSpkFileTuple[1]
#    gbCoSpkFile = lsoInputSpkFileTuple[2]
#    gbIpSpkFile = inputSpkFileTuple[3]
    anCoSpkFile = lsoInputSpkFileTuple[0]
    anIpSpkFile = lsoInputSpkFileTuple[1]

    
#    sbCoIdxSpktimeArray = np.loadtxt(sbCoSpkFile)
#    sbCoCellIndices = sbCoIdxSpktimeArray[:, 0].astype(int)
#    sbCoSpkTimes = sbCoIdxSpktimeArray[:, 1] * ms
#    sbCoSpkGenGrp = SpikeGeneratorGroup(nSbcsCo, sbCoCellIndices, sbCoSpkTimes)
    
    gbCoIdxSpktimeArray = np.loadtxt(anCoSpkFile)
    gbCoCellIndices = gbCoIdxSpktimeArray[:, 0].astype(int)
    # For now, spiketimes from Zilany AN in SECONDS, so * 1000*ms
    gbCoSpkTimes = gbCoIdxSpktimeArray[:, 1] * 1000. * ms
    gbCoSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, gbCoCellIndices, gbCoSpkTimes)
    
    sbIpIdxSpktimeArray = np.loadtxt(anIpSpkFile)
    sbIpCellIndices = sbIpIdxSpktimeArray[:, 0].astype(int)
    # For now, spiketimes from Zilany AN in SECONDS, so * 1000*ms
    sbIpSpkTimes = sbIpIdxSpktimeArray[:, 1] * 1000. * ms
    sbIpSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, sbIpCellIndices, sbIpSpkTimes)
    
#    gbIpIdxSpktimeArray = np.loadtxt(gbIpSpkFile)
#    gbIpCellIndices = gbIpIdxSpktimeArray[:, 0].astype(int)
#    gbIpSpkTimes = gbIpIdxSpktimeArray[:, 1] * ms
#    gbIpSpkGenGrp = SpikeGeneratorGroup(nGbcsIp, gbIpCellIndices, gbIpSpkTimes)
    
#    anfIdxSpktimeArray = np.loadtxt(anfSpkFile)
#    anfIndices = anfIdxSpktimeArray[:, 0].astype(int)
#    nANF = 132
#    #anfSpkTimes = [i * second for i in anfIdxSpktimeArray[:, 1]]
#    anfSpkTimes = anfIdxSpktimeArray[:, 1] * 1000*ms
#    anfSpkGeneratorGrp = SpikeGeneratorGroup(nANF, anfIndices, anfSpkTimes)
    
    # Membrane and Ion-Channel parameters
#    C = 12*pF
    C = 21.7*pF # 21.7pF: non-principal LSO neuron (Barnes-Davies et al. 2004)
    Eh = -43*mV
    EK = -70*mV  # -77*mV in mod file
    El = -65*mV
    ENa = 50*mV
    nf = 0.85  # proportion of n vs p kinetics
    zss = 0.5  # steady state inactivation of glt
    # default temp_degC = 37., human body temperature in degree celcius
    # q10 for ion-channel time-constants (RM2003, p.3106):
    q10 = 3. ** ((temp_degC - 22.) / 10.)
    # q10 for ion-channel gbar parameters (RM2003, p.3106):
    q10gbar = 2. ** ((temp_degC - 22.) / 10.)
    # hcno current (octopus cell)
    frac = 0.0
    qt = 4.5 ** ((temp_degC - 33.) / 10.)
    # Synaptic parameters:
    Es_e = 0.*mV
    tausE = 1.5*ms
    Es_i = -90*mV
    tausI = 3.0*ms
    '''Synaptic weights are unitless according to Brian2.
    The effective unit is siemens, so they can work in amp, volt, siemens eqns.
    We multiply synaptic weight w_e by unit siemens when adding it to g_e.
    We use a local variable w_e for synaptic weight rather than the standard w:''' 
    w_elson = 4.5e-9 #0.7e-9
    w_ilson = 45.e-9 #7e-9 # 6e-9 @ 200Hz; 12e-9 @ 600 Hz
    '''Here's why:
    The synapses sbc3SynE.w synaptic weight references the Same State Variable as 
    as the neuron group sbc3Grp.w (klt activation w).
    Update sbc3Grp.w, and you set sbc3SynE.w to same value, and vice versa.
    This way klt activation and synaptic weight are identical and quite ridiculous.
    So use a local variable other than w for the synaptic weight!'''
    
    # Maximal conductances of different cell types in nS
    maximal_conductances = dict(
    LsoNp1a=(1000, 150, 0, 0, 1.85, 0, 7.4),
    type1c=(1000, 150, 0, 0, 0.5, 0, 2),
    type1t=(1000, 80, 0, 65, 0.5, 0, 2),
    type12=(1000, 150, 20, 0, 2, 0, 2),
    type21=(1000, 150, 35, 0, 3.5, 0, 2),
    type2=(1000, 150, 200, 0, 20, 0, 2),
    type2g2x=(2000, 300, 400, 0, 40, 0, 2),
    type2g1p5x=(1000, 150, 300, 0, 30, 0, 2),
    type2g1p2x=(1200, 180, 240, 0, 24, 0, 2),
    type2g0p5x=(1000, 150, 100, 0, 10, 0, 2),
    type2o=(1000, 150, 600, 0, 0, 40, 2) # octopus cell
    )
    gnabar, gkhtbar, gkltbar, gkabar, ghbar, gbarno, gl = [x * nS for x in maximal_conductances[neuron_type]]

#    # Maximal conductances of different cell types in nS
#    maximal_conductances = dict(
#    type1c=(1000, 150, 0, 0, 0.5, 0, 2),
#    type1t=(1000, 80, 0, 65, 0.5, 0, 2),
#    type12=(1000, 150, 20, 0, 2, 0, 2),
#    type21=(1000, 150, 35, 0, 3.5, 0, 2),
#    type2=(1000, 150, 200, 0, 20, 0, 2),
#    type2gLTH2x=(1000, 150, 400, 0, 40, 0, 2),
#    type2gLTH0p5x=(1000, 150, 100, 0, 10, 0, 2),
#    type2o=(1000, 150, 600, 0, 0, 40, 2) # octopus cell
#    )
#    gnabar, gkhtbar, gkltbar, gkabar, ghbar, gbarno, gl = [x * nS for x in maximal_conductances[neuron_type]]
    
    # Classical Na channel
    eqs_na = """
    ina = gnabar*m**3*h*(ENa-v) : amp
    dm/dt=q10*(minf-m)/mtau : 1
    dh/dt=q10*(hinf-h)/htau : 1
    minf = 1./(1+exp(-(vu + 38.) / 7.)) : 1
    hinf = 1./(1+exp((vu + 65.) / 6.)) : 1
    mtau =  ((10. / (5*exp((vu+60.) / 18.) + 36.*exp(-(vu+60.) / 25.))) + 0.04)*ms : second
    htau =  ((100. / (7*exp((vu+60.) / 11.) + 10.*exp(-(vu+60.) / 25.))) + 0.6)*ms : second
    """
    
    # KHT channel (delayed-rectifier K+)
    eqs_kht = """
    ikht = gkhtbar*(nf*n**2 + (1-nf)*p)*(EK-v) : amp
    dn/dt=q10*(ninf-n)/ntau : 1
    dp/dt=q10*(pinf-p)/ptau : 1
    ninf = (1 + exp(-(vu + 15) / 5.))**-0.5 : 1
    pinf =  1. / (1 + exp(-(vu + 23) / 6.)) : 1
    ntau = ((100. / (11*exp((vu+60) / 24.) + 21*exp(-(vu+60) / 23.))) + 0.7)*ms : second
    ptau = ((100. / (4*exp((vu+60) / 32.) + 5*exp(-(vu+60) / 22.))) + 5)*ms : second
    """
    
    # Ih channel (subthreshold adaptive, non-inactivating)
    eqs_ih = """
    ih = ghbar*r*(Eh-v) : amp
    dr/dt=q10*(rinf-r)/rtau : 1
    rinf = 1. / (1+exp((vu + 76.) / 7.)) : 1
    rtau = ((100000. / (237.*exp((vu+60.) / 12.) + 17.*exp(-(vu+60.) / 14.))) + 25.)*ms : second
    """
    
    # KLT channel (low threshold K+)
    eqs_klt = """
    iklt = gkltbar*w**4*z*(EK-v) : amp
    dw/dt=q10*(winf-w)/wtau : 1
    dz/dt=q10*(zinf-z)/ztau : 1
    winf = (1. / (1 + exp(-(vu + 48.) / 6.)))**0.25 : 1
    zinf = zss + ((1.-zss) / (1 + exp((vu + 71.) / 10.))) : 1
    wtau = ((100. / (6.*exp((vu+60.) / 6.) + 16.*exp(-(vu+60.) / 45.))) + 1.5)*ms : second
    ztau = ((1000. / (exp((vu+60.) / 20.) + exp(-(vu+60.) / 8.))) + 50)*ms : second
    """
    
    # Ka channel (transient K+)
    eqs_ka = """
    ika = gkabar*a**4*b*c*(EK-v): amp
    da/dt=q10*(ainf-a)/atau : 1
    db/dt=q10*(binf-b)/btau : 1
    dc/dt=q10*(cinf-c)/ctau : 1
    ainf = (1. / (1 + exp(-(vu + 31) / 6.)))**0.25 : 1
    binf = 1. / (1 + exp((vu + 66) / 7.))**0.5 : 1
    cinf = 1. / (1 + exp((vu + 66) / 7.))**0.5 : 1
    atau =  ((100. / (7*exp((vu+60) / 14.) + 29*exp(-(vu+60) / 24.))) + 0.1)*ms : second
    btau =  ((1000. / (14*exp((vu+60) / 27.) + 29*exp(-(vu+60) / 24.))) + 1)*ms : second
    ctau = ((90. / (1 + exp((-66-vu) / 17.))) + 10)*ms : second
    """
    
    # Leak
    eqs_leak = """
    ileak = gl*(El-v) : amp
    """
    
    # h current for octopus cells
    eqs_hcno = """
    ihcno = gbarno*(h1*frac + h2*(1-frac))*(Eh-v) : amp
    dh1/dt=(hinfno-h1)/tau1 : 1
    dh2/dt=(hinfno-h2)/tau2 : 1
    hinfno = 1./(1+exp((vu+66.)/7.)) : 1
    tau1 = bet1/(qt*0.008*(1+alp1))*ms : second
    tau2 = bet2/(qt*0.0029*(1+alp2))*ms : second
    alp1 = exp(1e-3*3*(vu+50)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    bet1 = exp(1e-3*3*0.3*(vu+50)*9.648e4/(8.315*(273.16+temp_degC))) : 1 
    alp2 = exp(1e-3*3*(vu+84)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    bet2 = exp(1e-3*3*0.6*(vu+84)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    """
    
    eqs = """
    dv/dt = (ileak + ina + ikht + iklt + ika + ih + ihcno + I + Is_e + Is_i)/C : volt
    Is_e = gs_e * (Es_e - v) : amp
    gs_e : siemens
    Is_i = gs_i * (Es_i - v) : amp
    gs_i : siemens
    vu = v/mV : 1  # unitless v
    I : amp
    """
    #Added Is_i to RM2003
    
    eqs += eqs_leak + eqs_ka + eqs_na + eqs_ih + eqs_klt + eqs_kht + eqs_hcno
    
    
    lsonGrp = NeuronGroup(nLsons, eqs, method='exponential_euler', 
                        threshold='v > -30*mV', refractory='v > -45*mV')
    #gbcGrp.I = 2500.0*pA
    lsonGrp.I = 0.0*pA
    # Initialize model near v_rest with no inputs
    lsonGrp.v = Vrest
    vu = lsonGrp.v/mV # unitless v
    lsonGrp.m = 1./(1+exp(-(vu + 38.) / 7.))
    lsonGrp.h = 1./(1+exp((vu + 65.) / 6.))
    lsonGrp.n = (1 + exp(-(vu + 15) / 5.))**-0.5
    lsonGrp.p = 1. / (1 + exp(-(vu + 23) / 6.))
    lsonGrp.r = 1. / (1+exp((vu + 76.) / 7.))
    lsonGrp.w = (1. / (1 + exp(-(vu + 48.) / 6.)))**0.25
    lsonGrp.z = zss + ((1.-zss) / (1 + exp((vu + 71.) / 10.)))
    lsonGrp.a = (1. / (1 + exp(-(vu + 31) / 6.)))**0.25
    lsonGrp.b = 1. / (1 + exp((vu + 66) / 7.))**0.5
    lsonGrp.c = 1. / (1 + exp((vu + 66) / 7.))**0.5
    lsonGrp.h1 = 1./(1+exp((vu+66.)/7.))
    lsonGrp.h2 = 1./(1+exp((vu+66.)/7.))
    #lsonGrp.gs_e = 0.0*siemens
    
    #netGbcEq = Network(gbcGrp, report='text')
    #netGbcEq.run(50*ms, report='text')
    
    lsonSynI = Synapses(gbCoSpkGenGrp, lsonGrp, 
                     model='''dg_i/dt = -g_i/tausI : siemens (clock-driven)
                              gs_i_post = g_i : siemens (summed)''',
                     on_pre='g_i += w_ilson*siemens',
                     method = 'exact')
    lsonSynI.connect(i=np.arange(nGbcsCoPerLson), j=0)
    
    lsonSynE = Synapses(sbIpSpkGenGrp, lsonGrp, 
                     model='''dg_e/dt = -g_e/tausE : siemens (clock-driven)
                              gs_e_post = g_e : siemens (summed)''',
                     on_pre='g_e += w_elson*siemens',
                     method = 'exact')
    lsonSynE.connect(i=np.arange(nSbcsIpPerLson), j=0)

    lsonSpks = SpikeMonitor(lsonGrp)
    lsonState = StateMonitor(lsonGrp, ['v','gs_e'], record=True)

    run(8150*ms, report='text')
    
    plt.plot(lsonState.t / ms, lsonState[0].v / mV)
    #plt.plot(gbcState.t / ms, gbcState[0].gs_e)
    #plt.plot(gSynEState.t / ms, gSynEState[0].gs_e_post)
    #plt.plot(gSynEState.t / ms, gSynEState[0].g_e)
    
    plt.xlabel('t (ms)')
    plt.ylabel('v (mV)')
    plt.show()
    
    dBSPLStrCo = anCoSpkFile[28:30]
    dBSPLStrIp = anIpSpkFile[28:30]
    dBSPLCo = int(dBSPLStrCo)
    dBSPLIp = int(dBSPLStrIp)
    IIDdB = dBSPLCo - dBSPLIp
    if (IIDdB >= 0):
        IIDdBStr = 'IIDP' + str(IIDdB).zfill(2) + 'dBSPL'
    elif (IIDdB < 0):
        IIDdBStr = 'IIDN' + str(-IIDdB).zfill(2) + 'dBSPL'
    
    # Synaptic parameters in output filename
    if (abs(round(tausE/ms)-(tausE/ms)) < 0.1):
        Te = str(round(tausE/ms))
    else:
        #Te = str(tausE/ms)
        Te = str(round(10*tausE/ms)/10.)
    Te = Te.replace('.','p')

    if (abs(round(w_elson/1e-9)-(w_elson/1e-9)) < 0.1):
        We = str(round(w_elson/1e-9))
    else:
        #We = str(w_elson/1e-9)
        We = str(round(10*w_elson/1e-9)/10)
    We = We.replace('.','p')
    
    if (abs(round(tausI/ms)-(tausI/ms)) < 0.1):
        Ti = str(round(tausI/ms))
    else:
        Ti = str(tausI/ms)
    Ti = Ti.replace('.','p')
    
    if (abs(round(w_ilson/1e-9)-(w_ilson/1e-9)) < 0.1):
        Wi = str(round(w_ilson/1e-9))
    else:
        Wi = str(w_ilson/1e-9)
    Wi = Wi.replace('.','p')
    
#    lsonSpkFile = 'Lso1aSpTms' + anCoSpkFile[6:13] + anCoSpkFile[16:23] + 'Te'+Te + 'We'+We + 'Ti'+Ti + 'Wi'+Wi + EIPDstr + 'Co' + anCoSpkFile[38:40] + anCoSpkFile[23:31] + anCoSpkFile[45:]
    # CaCF, Te We Ti Wi, IID, SPLdBiNNcDD, .txt 
    lsonSpkFile = 'Lso1aSpTms' + anCoSpkFile[10:17] + 'Te'+Te + 'We'+We + 'Ti'+Ti + 'Wi'+Wi + IIDdBStr + 'co'+dBSPLStrCo + 'ip'+dBSPLStrIp + anCoSpkFile[35:]
    file0 = open(lsonSpkFile,'w')
    for index in range(len(lsonSpks.t)):
        file0.write(str(lsonSpks.i[index]) + " " + str(lsonSpks.t[index] / ms) + '\n')
    file0.close()
    
    return (lsonGrp, lsonSpks, lsonState)

# end of mkgbcs
Esempio n. 11
0
def rotating_bar(length=10,
                 input_size_x=240,
                 input_size_y=180,
                 offx=0,
                 offy=0,
                 angle_step=10,
                 ts_offset=10 * ms):
    """
    This function returns a single spikegenerator group (Brian object),
    and the events related to it.
    It produces a stimuli of a rotating bar, ideal for testing orientation 
    selective populations
    
    Args:
        length (int): `length` of the bar in pixel.
        input_size_x(int) : size of the input population x coordinate
                            by default set as the DAVIS resolution
        input_size_y(int) : size of the input population y coordinate
                            by default set as the DAVIS resolution
        offx(int): horizontal offset of the stimuli center (0, or centered in the 
                                                        middle by default)
        offy(int): vertical offset of the stimuli center (0, or centered in the 
                                                        middle by default)
        angle step(int) : the number of steps that the bar will use in order
                            to rotate starting from 0 to 2*pi
        ts_offset (seconds_brian): time between each consecutive fire of the population
                                        (time occurring between each bar position)
                                        It's only applied in the spike generator,
                                        the event timestamps don't have units!
    Returns:
        SpikeGenerator obj: Brian2 objects which holds the spiketimes as well
            as the respective neuron indices
        events list: A list containing the events as x,y coordinates, polatirty
                    and timestamps
    """
    x_coord = []
    y_coord = []
    pol = []
    ts = []
    center = (input_size_x / 2 + offx, input_size_y / 2 + offy)
    angles = np.linspace(0, np.pi * 2, angle_step)
    for i, cAngle in enumerate(angles):
        endy_1 = center[1] + ((length / 2) * np.sin((cAngle)))
        endx_1 = center[0] + ((length / 2) * np.cos((cAngle)))
        endy_2 = center[1] - ((length / 2) * np.sin((cAngle)))
        endx_2 = center[0] - ((length / 2) * np.cos((cAngle)))
        start = np.asarray((endx_1, endy_1))
        end = np.asarray((endx_2, endy_2))
        max_direction, max_length = max(enumerate(abs(end - start)),
                                        key=operator.itemgetter(1))
        dv = (end - start) / max_length
        line = [dda_round(start)]
        for step in range(int(max_length)):
            line.append(dda_round((step + 1) * dv + start))
        for coord in line:
            x_coord.append(coord[0])
            y_coord.append(coord[1])
            ts.append(i)
            pol.append(1)
    events = np.zeros((4, len(x_coord)))
    events[0, :] = np.asarray(x_coord)
    events[1, :] = np.asarray(y_coord)
    events[2, :] = np.asarray(ts)
    events[3, :] = np.asarray(pol)

    ind = xy2ind(events[0, :], events[1, :], input_size_x)
    stimuli_generator = SpikeGeneratorGroup(input_size_x * input_size_y,
                                            indices=ind,
                                            times=ts * ts_offset,
                                            name='rotating_bar')
    return stimuli_generator, events
Esempio n. 12
0
# Chopping data and renaming variables(explicit separation of ON and OFF events)
indOn = indInp2[0][0][(indInp2[0][1][:] * us >= start) *
                      (indInp2[0][1][:] * us <= end)]
indOff = indInp2[1][0][(indInp2[1][1][:] * us >= start) *
                       (indInp2[1][1][:] * us <= end)]
timeOn = indInp2[0][1][(indInp2[0][1][:] * us >= start) *
                       (indInp2[0][1][:] * us <= end)]
timeOff = indInp2[1][1][(indInp2[1][1][:] * us >= start) *
                        (indInp2[1][1][:] * us <= end)]
timeOn = (timeOn * ms) - start
timeOff = (timeOff * ms) - start

# select if you want to process ON or OFF events

retina = SpikeGeneratorGroup(image_res,
                             indices=indOn,
                             times=timeOn,
                             name='gPre')

#retina = SpikeGeneratorGroup(image_res, indices=indOff, times=timeOff, name='gPre')

#%% Artificial stimuli
# Rotating bar with known angles, used to assest the net ability to encode orientation

length = 15
center_offx = 0
center_offy = 0
angle_step = 40
ts_offset = 10 * defaultclock.dt

retina, events = rotating_bar(length, input_size_x, input_size_y, center_offx,
                              center_offy, angle_step, ts_offset)
Esempio n. 13
0
def test_from_papers_example():
    """
    Test Izhikevich_2007 example
    `brian2.readthedocs.io/en/stable/examples/frompapers.Izhikevich_2007.html`
    """
    set_device('markdown', build_on_run=False)
    # Parameters
    simulation_duration = 6 * second
    # Neurons
    taum = 10*ms
    Ee = 0*mV
    vt = -54*mV
    vr = -60*mV
    El = -74*mV
    taue = 5*ms

    # STDP
    taupre = 20*ms
    taupost = taupre
    gmax = .01
    dApre = .01
    dApost = -dApre * taupre / taupost * 1.05
    dApost *= gmax
    dApre *= gmax

    # Dopamine signaling
    tauc = 1000*ms
    taud = 200*ms
    taus = 1*ms
    epsilon_dopa = 5e-3

    # Setting the stage

    # Stimuli section
    input_indices = array([0, 1, 0, 1, 1, 0,
                           0, 1, 0, 1, 1, 0])
    input_times = array([500,  550, 1000, 1010, 1500, 1510,
                         3500, 3550, 4000, 4010, 4500, 4510])*ms
    input = SpikeGeneratorGroup(2, input_indices, input_times)

    neurons = NeuronGroup(2, '''dv/dt = (ge * (Ee-vr) + El - v) / taum : volt
                                dge/dt = -ge / taue : 1''',
                          threshold='v>vt', reset='v = vr',
                          method='exact')
    neurons.v = vr
    neurons_monitor = SpikeMonitor(neurons)

    synapse = Synapses(input, neurons,
                       model='''s: volt''',
                       on_pre='v += s')
    synapse.connect(i=[0, 1], j=[0, 1])
    synapse.s = 100. * mV

    # STDP section
    synapse_stdp = Synapses(neurons, neurons,
                    model='''mode: 1
                            dc/dt = -c / tauc : 1 (clock-driven)
                            dd/dt = -d / taud : 1 (clock-driven)
                            ds/dt = mode * c * d / taus : 1 (clock-driven)
                            dApre/dt = -Apre / taupre : 1 (event-driven)
                            dApost/dt = -Apost / taupost : 1 (event-driven)''',
                    on_pre='''ge += s
                            Apre += dApre
                            c = clip(c + mode * Apost, -gmax, gmax)
                            s = clip(s + (1-mode) * Apost, -gmax, gmax)
                            ''',
                    on_post='''Apost += dApost
                            c = clip(c + mode * Apre, -gmax, gmax)
                            s = clip(s + (1-mode) * Apre, -gmax, gmax)
                            ''',
                    method='euler'
                           )
    synapse_stdp.connect(i=0, j=1)
    synapse_stdp.mode = 0
    synapse_stdp.s = 1e-10
    synapse_stdp.c = 1e-10
    synapse_stdp.d = 0
    synapse_stdp_monitor = StateMonitor(synapse_stdp, ['s', 'c', 'd'],
                                        record=[0])
    # Dopamine signaling section
    dopamine_indices = array([0, 0, 0])
    dopamine_times = array([3520, 4020, 4520])*ms
    dopamine = SpikeGeneratorGroup(1, dopamine_indices, dopamine_times)
    dopamine_monitor = SpikeMonitor(dopamine)
    reward = Synapses(dopamine, synapse_stdp, model='''''',
                      on_pre='''d_post += epsilon_dopa''',
                      method='exact')
    reward.connect()

    # Simulation
    # Classical STDP
    synapse_stdp.mode = 0
    run(simulation_duration/2)
    # Dopamine modulated STDP
    synapse_stdp.mode = 1
    run(simulation_duration/2)
    device.build()
    md_str = device.md_text
    assert _markdown_lint(md_str)
    device.reinit()
from brian2 import ms, mV, cm, uF, mS
from brian2 import NeuronGroup, StateMonitor, Network, collect
from brian2 import Synapses, SpikeGeneratorGroup, defaultclock, array
import matplotlib.pyplot as plt

# =============================================================================
# Simulation parameters
simtime         = 100 * ms
defaultclock.dt = 0.1 * ms
# =============================================================================

# =============================================================================
# EXTERNAL INPUTS
indices = array([0])
times = array([50]) * ms
EXT1 = SpikeGeneratorGroup(1, indices, times)
EXT2 = SpikeGeneratorGroup(1, indices, times)

# =============================================================================

print ("Building the Network...")

# Parameters for Excitatory Neurons
E_L       = -80. * mV      # reversal (rest) membrane potential
V_thr     = -45. * mV      # threshold for spike
V_reset   = -80. * mV      # reset potential after an emission of a spike
C_m_E     = 1.0 * uF/cm**2 # membrane capacitance
g_L       = 0.1 * mS/cm**2 # leak conductunce
g_c       = 0.2 * mS/cm**2 # coupling conductance
tau_rp_E  = 2.0 * ms       # refractory period
#    sbIpSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, sbIpCellIndices, sbIpSpkTimes)

nAnfsPerInputFile = 40

nGbcsCoPerLson = 8  # Gjoni et al. 2018
nSbcsIpPerLson = 40  # Gjoni et al. 2018
#nGbcsCoPerLson = 1  # showing unitary IPSP
#nSbcsIpPerLson = 1 # showing unitary EPSP

gbCoCellIndices = np.array([0])
gbCoSpkTimes = np.array([5.0]) * ms

#sbIpCellIndices = np.array([0, 0])
#sbIpSpkTimes = np.array([10.0, 40.0]) * ms

gbCoSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, gbCoCellIndices,
                                    gbCoSpkTimes)
#sbIpSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, sbIpCellIndices, sbIpSpkTimes)

# Membrane and Ion-Channel parameters
C = 12 * pF
Eh = -43 * mV
EK = -70 * mV  # -77*mV in mod file
El = -65 * mV
ENa = 55 * mV  # 55*mV in RM2003; 50*mv by Brette
nf = 0.85  # proportion of n vs p kinetics
zss = 0.5  # steady state inactivation of glt
# default temp_degC = 37., human body temperature in degree celcius
# q10 for ion-channel time-constants (RM2003, p.3106):
q10 = 3.**((temp_degC - 22.) / 10.)
# q10 for ion-channel gbar parameters (RM2003, p.3106):
q10gbar = 2.**((temp_degC - 22.) / 10.)
def lson(lsoInputSpkFileTuple, temp_degC=37):

    defaultclock.dt = 0.02 * ms  # for better precision

    neuron_type = 'type2'  # medium-fast membrane f0 180-260Hz, CF4kHz
    #temp_degC=37.
    Vrest = -63.6 * mV  # resting potential for type1c from RM2003

    nLsons = 1  # number of LSO neurons

    nGbcsCo = 4
    #    nGbcsIp = 4
    #    nSbcsCo = 4
    nSbcsIp = 4

    #    nSbcs = 4
    #    nAnfsPerSbc = 3
    #    nGbcs = 4
    #    nAnfsPerGbc=30

    nAnfsPerInputFile = 40

    nGbcsCoPerLson = 8  # Gjoni et al. 2018
    nSbcsIpPerLson = 40  # Gjoni et al. 2018

    #    sbCoSpkFile = inputSpkFileTuple[0]
    #    sbIpSpkFile = lsoInputSpkFileTuple[1]
    #    gbCoSpkFile = lsoInputSpkFileTuple[2]
    #    gbIpSpkFile = inputSpkFileTuple[3]
    anCoSpkFile = lsoInputSpkFileTuple[0]
    anIpSpkFile = lsoInputSpkFileTuple[1]

    #    sbCoIdxSpktimeArray = np.loadtxt(sbCoSpkFile)
    #    sbCoCellIndices = sbCoIdxSpktimeArray[:, 0].astype(int)
    #    sbCoSpkTimes = sbCoIdxSpktimeArray[:, 1] * ms
    #    sbCoSpkGenGrp = SpikeGeneratorGroup(nSbcsCo, sbCoCellIndices, sbCoSpkTimes)

    gbCoIdxSpktimeArray = np.loadtxt(anCoSpkFile)
    gbCoCellIndices = gbCoIdxSpktimeArray[:, 0].astype(int)
    # For now, spiketimes from Zilany AN in SECONDS, so * 1000*ms
    gbCoSpkTimes = gbCoIdxSpktimeArray[:, 1] * 1000. * ms
    gbCoSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, gbCoCellIndices,
                                        gbCoSpkTimes)

    sbIpIdxSpktimeArray = np.loadtxt(anIpSpkFile)
    sbIpCellIndices = sbIpIdxSpktimeArray[:, 0].astype(int)
    # For now, spiketimes from Zilany AN in SECONDS, so * 1000*ms
    sbIpSpkTimes = sbIpIdxSpktimeArray[:, 1] * 1000. * ms
    sbIpSpkGenGrp = SpikeGeneratorGroup(nAnfsPerInputFile, sbIpCellIndices,
                                        sbIpSpkTimes)

    #    gbIpIdxSpktimeArray = np.loadtxt(gbIpSpkFile)
    #    gbIpCellIndices = gbIpIdxSpktimeArray[:, 0].astype(int)
    #    gbIpSpkTimes = gbIpIdxSpktimeArray[:, 1] * ms
    #    gbIpSpkGenGrp = SpikeGeneratorGroup(nGbcsIp, gbIpCellIndices, gbIpSpkTimes)

    #    anfIdxSpktimeArray = np.loadtxt(anfSpkFile)
    #    anfIndices = anfIdxSpktimeArray[:, 0].astype(int)
    #    nANF = 132
    #    #anfSpkTimes = [i * second for i in anfIdxSpktimeArray[:, 1]]
    #    anfSpkTimes = anfIdxSpktimeArray[:, 1] * 1000*ms
    #    anfSpkGeneratorGrp = SpikeGeneratorGroup(nANF, anfIndices, anfSpkTimes)

    # Membrane and Ion-Channel parameters
    C = 12 * pF
    EH = -43 * mV
    EK = -70 * mV  # -77*mV in mod file
    EL = -65 * mV
    ENa = 55 * mV  # 55*mV in RM2003; 50*mv by Brette
    nf = 0.85  # proportion of n vs p kinetics
    zss = 0.5  # steady state inactivation of glt
    # default temp_degC = 37., human body temperature in degree celcius
    # q10 for ion-channel time-constants (RM2003, p.3106):
    q10 = 3.**((temp_degC - 22.) / 10.)
    # q10 for ion-channel gbar parameters (RM2003, p.3106):
    q10gbar = 2.**((temp_degC - 22.) / 10.)
    # hcno current (octopus cell)
    frac = 0.0
    qt = 4.5**((temp_degC - 33.) / 10.)
    # Synaptic parameters:
    Es_e = 0. * mV
    tausE = 0.5 * ms
    Es_i = -90 * mV
    tausI = 1.0 * ms
    '''Synaptic weights are unitless according to Brian2.
    The effective unit is siemens, so they can work in amp, volt, siemens eqns.
    We multiply synaptic weight w_e by unit siemens when adding it to g_e.
    We use a local variable w_e for synaptic weight rather than the standard w:'''
    w_elson = 5e-9
    w_ilson = 50e-9  # 6e-9 @ 200Hz; 12e-9 @ 600 Hz
    '''Here's why:
    The synapses sbc3SynE.w synaptic weight references the Same State Variable as 
    as the neuron group sbc3Grp.w (klt activation w).
    Update sbc3Grp.w, and you set sbc3SynE.w to same value, and vice versa.
    This way klt activation and synaptic weight are identical and quite ridiculous.
    So use a local variable other than w for the synaptic weight!'''

    # Maximal conductances of different cell types in nS
    maximal_conductances = dict(
        type1c=(1000, 150, 0, 0, 0.5, 0, 2),
        type1t=(1000, 80, 0, 65, 0.5, 0, 2),
        type12=(1000, 150, 20, 0, 2, 0, 2),
        type21=(1000, 150, 35, 0, 3.5, 0, 2),
        type2=(1000, 150, 200, 0, 20, 0, 2),
        type2g1p5x=(1000, 150, 300, 0, 30, 0, 2),
        type2g0p5x=(1000, 150, 100, 0, 10, 0, 2),
        type2o=(1000, 150, 600, 0, 0, 40, 2)  # octopus cell
    )
    gnabar, gkhtbar, gkltbar, gkabar, ghbar, gbarno, gl = [
        x * nS for x in maximal_conductances[neuron_type]
    ]

    # Classical Na channel
    eqs_na = """
    ina = gnabar*m**3*h*(ENa-v) : amp
    dm/dt=q10*(minf-m)/mtau : 1
    dh/dt=q10*(hinf-h)/htau : 1
    minf = 1./(1+exp(-(vu + 38.) / 7.)) : 1
    hinf = 1./(1+exp((vu + 65.) / 6.)) : 1
    mtau =  ((10. / (5*exp((vu+60.) / 18.) + 36.*exp(-(vu+60.) / 25.))) + 0.04)*ms : second
    htau =  ((100. / (7*exp((vu+60.) / 11.) + 10.*exp(-(vu+60.) / 25.))) + 0.6)*ms : second
    """

    # KHT channel (delayed-rectifier K+)
    eqs_kht = """
    ikht = gkhtbar*(nf*n**2 + (1-nf)*p)*(EK-v) : amp
    dn/dt=q10*(ninf-n)/ntau : 1
    dp/dt=q10*(pinf-p)/ptau : 1
    ninf = (1 + exp(-(vu + 15) / 5.))**-0.5 : 1
    pinf =  1. / (1 + exp(-(vu + 23) / 6.)) : 1
    ntau = ((100. / (11*exp((vu+60) / 24.) + 21*exp(-(vu+60) / 23.))) + 0.7)*ms : second
    ptau = ((100. / (4*exp((vu+60) / 32.) + 5*exp(-(vu+60) / 22.))) + 5)*ms : second
    """

    # Ih channel (subthreshold adaptive, non-inactivating)
    eqs_ih = """
    ih = ghbar*r*(EH-v) : amp
    dr/dt=q10*(rinf-r)/rtau : 1
    rinf = 1. / (1+exp((vu + 76.) / 7.)) : 1
    rtau = ((100000. / (237.*exp((vu+60.) / 12.) + 17.*exp(-(vu+60.) / 14.))) + 25.)*ms : second
    """

    # KLT channel (low threshold K+)
    eqs_klt = """
    iklt = gkltbar*w**4*z*(EK-v) : amp
    dw/dt=q10*(winf-w)/wtau : 1
    dz/dt=q10*(zinf-z)/ztau : 1
    winf = (1. / (1 + exp(-(vu + 48.) / 6.)))**0.25 : 1
    zinf = zss + ((1.-zss) / (1 + exp((vu + 71.) / 10.))) : 1
    wtau = ((100. / (6.*exp((vu+60.) / 6.) + 16.*exp(-(vu+60.) / 45.))) + 1.5)*ms : second
    ztau = ((1000. / (exp((vu+60.) / 20.) + exp(-(vu+60.) / 8.))) + 50)*ms : second
    """

    # Ka channel (transient K+)
    eqs_ka = """
    ika = gkabar*a**4*b*c*(EK-v): amp
    da/dt=q10*(ainf-a)/atau : 1
    db/dt=q10*(binf-b)/btau : 1
    dc/dt=q10*(cinf-c)/ctau : 1
    ainf = (1. / (1 + exp(-(vu + 31) / 6.)))**0.25 : 1
    binf = 1. / (1 + exp((vu + 66) / 7.))**0.5 : 1
    cinf = 1. / (1 + exp((vu + 66) / 7.))**0.5 : 1
    atau =  ((100. / (7*exp((vu+60) / 14.) + 29*exp(-(vu+60) / 24.))) + 0.1)*ms : second
    btau =  ((1000. / (14*exp((vu+60) / 27.) + 29*exp(-(vu+60) / 24.))) + 1)*ms : second
    ctau = ((90. / (1 + exp((-66-vu) / 17.))) + 10)*ms : second
    """

    # Leak
    eqs_leak = """
    ileak = gl*(EL-v) : amp
    """

    # h current for octopus cells
    eqs_hcno = """
    ihcno = gbarno*(h1*frac + h2*(1-frac))*(EH-v) : amp
    dh1/dt=(hinfno-h1)/tau1 : 1
    dh2/dt=(hinfno-h2)/tau2 : 1
    hinfno = 1./(1+exp((vu+66.)/7.)) : 1
    tau1 = bet1/(qt*0.008*(1+alp1))*ms : second
    tau2 = bet2/(qt*0.0029*(1+alp2))*ms : second
    alp1 = exp(1e-3*3*(vu+50)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    bet1 = exp(1e-3*3*0.3*(vu+50)*9.648e4/(8.315*(273.16+temp_degC))) : 1 
    alp2 = exp(1e-3*3*(vu+84)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    bet2 = exp(1e-3*3*0.6*(vu+84)*9.648e4/(8.315*(273.16+temp_degC))) : 1
    """

    eqs = """
    dv/dt = (ileak + ina + ikht + iklt + ika + ih + ihcno + I + Is_e + Is_i)/C : volt
    Is_e = gs_e * (Es_e - v) : amp
    gs_e : siemens
    Is_i = gs_i * (Es_i - v) : amp
    gs_i : siemens
    vu = v/mV : 1  # unitless v
    I : amp
    """
    #Added Is_i to RM2003

    eqs += eqs_leak + eqs_ka + eqs_na + eqs_ih + eqs_klt + eqs_kht + eqs_hcno

    lsonGrp = NeuronGroup(nLsons,
                          eqs,
                          method='exponential_euler',
                          threshold='v > -30*mV',
                          refractory='v > -45*mV')
    #gbcGrp.I = 2500.0*pA
    lsonGrp.I = 0.0 * pA
    # Initialize model near v_rest with no inputs
    lsonGrp.v = Vrest
    #vu = EL/mV # unitless v
    vu = lsonGrp.v / mV  # unitless v
    lsonGrp.m = 1. / (1 + exp(-(vu + 38.) / 7.))
    lsonGrp.h = 1. / (1 + exp((vu + 65.) / 6.))
    lsonGrp.n = (1 + exp(-(vu + 15) / 5.))**-0.5
    lsonGrp.p = 1. / (1 + exp(-(vu + 23) / 6.))
    lsonGrp.r = 1. / (1 + exp((vu + 76.) / 7.))
    lsonGrp.w = (1. / (1 + exp(-(vu + 48.) / 6.)))**0.25
    lsonGrp.z = zss + ((1. - zss) / (1 + exp((vu + 71.) / 10.)))
    lsonGrp.a = (1. / (1 + exp(-(vu + 31) / 6.)))**0.25
    lsonGrp.b = 1. / (1 + exp((vu + 66) / 7.))**0.5
    lsonGrp.c = 1. / (1 + exp((vu + 66) / 7.))**0.5
    lsonGrp.h1 = 1. / (1 + exp((vu + 66.) / 7.))
    lsonGrp.h2 = 1. / (1 + exp((vu + 66.) / 7.))
    #lsonGrp.gs_e = 0.0*siemens

    #netGbcEq = Network(gbcGrp, report='text')
    #netGbcEq.run(50*ms, report='text')

    lsonSynI = Synapses(gbCoSpkGenGrp,
                        lsonGrp,
                        model='''dg_i/dt = -g_i/tausI : siemens (clock-driven)
                              gs_i_post = g_i : siemens (summed)''',
                        on_pre='g_i += w_ilson*siemens',
                        method='exact')
    lsonSynI.connect(i=np.arange(nGbcsCoPerLson), j=0)

    lsonSynE = Synapses(sbIpSpkGenGrp,
                        lsonGrp,
                        model='''dg_e/dt = -g_e/tausE : siemens (clock-driven)
                              gs_e_post = g_e : siemens (summed)''',
                        on_pre='g_e += w_elson*siemens',
                        method='exact')
    lsonSynE.connect(i=np.arange(nSbcsIpPerLson), j=0)

    lsonSpks = SpikeMonitor(lsonGrp)
    lsonState = StateMonitor(lsonGrp, ['v', 'gs_e'], record=True)

    run(300 * ms, report='text')

    # Console Output Won't Clear from Script
    # Memory issue with so many repeated simulations:
    # Comment out the plt commands
    #plt.plot(lsonState.t / ms, lsonState[0].v / mV)
    #plt.xlabel('t (ms)')
    #plt.ylabel('v (mV)')
    #plt.show()

    # Output file - EIPD in output filename. Spiketimes in file
    EPhsStrCo = anCoSpkFile[27:31]
    EPhsStrIp = anIpSpkFile[27:31]
    if (EPhsStrCo[0] == 'N'):
        EPhsIntCo = -1 * int(EPhsStrCo[1:4])
    else:
        EPhsIntCo = int(EPhsStrCo[0:3])
    if (EPhsStrIp[0] == 'N'):
        EPhsIntIp = -1 * int(EPhsStrIp[1:4])
    else:
        EPhsIntIp = int(EPhsStrIp[0:3])
#    EIPD = (EPhsIntCo - EPhsIntIp) % 360
    EIPDint = (EPhsIntCo - EPhsIntIp)  # unwrapped Envelope IPD
    #EIPDstr = str(EIPDint)
    if (EIPDint == 15):
        EIPDstr = 'EIPDP015'
    elif (EIPDint == 30):
        EIPDstr = 'EIPDP030'
    elif (EIPDint == 45):
        EIPDstr = 'EIPDP045'
    elif (EIPDint == 60):
        EIPDstr = 'EIPDP060'
    elif (EIPDint == 75):
        EIPDstr = 'EIPDP075'
    elif (EIPDint == 90):
        EIPDstr = 'EIPDP090'
    elif (EIPDint == -15):
        EIPDstr = 'EIPDN015'
    elif (EIPDint == -30):
        EIPDstr = 'EIPDN030'
    elif (EIPDint == -45):
        EIPDstr = 'EIPDN045'
    elif (EIPDint == -60):
        EIPDstr = 'EIPDN060'
    elif (EIPDint == -75):
        EIPDstr = 'EIPDN075'
    elif (EIPDint == -90):
        EIPDstr = 'EIPDN090'
    elif (EIPDint > 0):
        EIPDstr = 'EIPDP' + str(EIPDint)
    elif (EIPDint < 0):
        EIPDstr = 'EIPDN' + str(-EIPDint)
    elif (EIPDint == 0):
        EIPDstr = 'EIPDP000'

#    if (EIPDint < 0):
#        EIPDstr = EIPDstr.replace('-','N')

# Synaptic parameters in output filename
    if (abs(round(tausE / ms) - (tausE / ms)) < 0.1):
        Te = str(round(tausE / ms))
    else:
        Te = str(tausE / ms)
    Te = Te.replace('.', 'p')

    if (abs(round(w_elson / 1e-9) - (w_elson / 1e-9)) < 0.1):
        We = str(round(w_elson / 1e-9))
    else:
        We = str(w_elson / 1e-9)
    We = We.replace('.', 'p')

    if (abs(round(tausI / ms) - (tausI / ms)) < 0.1):
        Ti = str(round(tausI / ms))
    else:
        Ti = str(tausI / ms)
    Ti = Ti.replace('.', 'p')

    if (abs(round(w_ilson / 1e-9) - (w_ilson / 1e-9)) < 0.1):
        Wi = str(round(w_ilson / 1e-9))
    else:
        Wi = str(w_ilson / 1e-9)
    Wi = Wi.replace('.', 'p')

    lsonSpkFile = 'Lso2SpTms' + anCoSpkFile[6:13] + anCoSpkFile[
        16:
        23] + 'Te' + Te + 'We' + We + 'Ti' + Ti + 'Wi' + Wi + EIPDstr + 'Co' + anCoSpkFile[
            38:40] + anCoSpkFile[23:31] + anCoSpkFile[45:]
    file0 = open(lsonSpkFile, 'w')
    for index in range(len(lsonSpks.t)):
        file0.write(
            str(lsonSpks.i[index]) + " " + str(lsonSpks.t[index] / ms) + '\n')
    file0.close()

    return (lsonGrp, lsonSpks, lsonState)


# end of mkgbcs
Esempio n. 17
0
    ii_synapses = get_synapses(
        "ii_synapses",
        inh_neurons,
        inh_neurons,
        C=0.1,
        l=l_lambda,
        tau_I=6 * ms,
        A=-19 * nA,
        U=0.32,
        D=0.144 * second,
        F=0.06 * second,
        delay=0.8 * ms,
    )

    # place holder for stimulus
    stimulus = SpikeGeneratorGroup(1, [], [] * ms, name="stimulus")

    spike_monitor_stimulus = SpikeMonitor(stimulus)

    static_synapses_exc = Synapses(stimulus,
                                   exc_neurons,
                                   "A : ampere (shared, constant)",
                                   on_pre="I_stimulus += A")
    static_synapses_exc.connect(p=1)
    static_synapses_exc.A = 18 * nA

    static_synapses_inh = Synapses(stimulus,
                                   inh_neurons,
                                   "A : ampere (shared, constant)",
                                   on_pre="I_stimulus += A")
    static_synapses_inh.connect(p=1)