Пример #1
0
def simulate_IF(**kw):

    I_vec_in = kw.get('if_I_vec')

    tStim = 700 + 1300
    my_nest.ResetKernel({'local_num_threads': 1})

    sd = {
        'active': True,
        'params': {
            'to_memory': True,
            'to_file': False,
            'start': 500.0
        }
    }
    #     mm={'active':True,
    #         'params':{'interval':0.1,'to_memory':True,'to_file':False}}
    p = kw.get('if_params')
    if 'type_id' in p.keys(): del p['type_id']
    mnn = MyNetworkNode('dummy', model=kw.get('model'), n=1, params=p, sd=sd)

    I_e0 = my_nest.GetStatus(mnn[:])[0]['I_e']
    my_nest.SetStatus(mnn[:], params={'I_e': I_e0 + kw.get('I_E')})  # Set I_e

    I_vec_out, fIsi, mIsi, lIsi = mnn.run_IF(I_vec_in, tStim=tStim)

    d = {
        'x': I_vec_out,
        'first': 1000. / fIsi,
        'mean': 1000. / mIsi,
        'last': 1000. / lIsi,
    }

    return {'IF': Data_IF_curve(**d)}
Пример #2
0
def simulate_ahp(**kw):

    n = len(kw.get('ahp_curr'))
    I_vec = numpy.array(kw.get('ahp_curr'))

    simTime = 3000.  # ms
    my_nest.ResetKernel({'local_num_threads': 1})

    sd = {'active': True, 'params': {'to_memory': True, 'to_file': False}}
    mm = {
        'active': True,
        'params': {
            'interval': 0.1,
            'to_memory': True,
            'to_file': False
        }
    }
    p = kw.get('rs_params')

    if 'type_id' in p.keys(): del p['type_id']
    mnn = MyNetworkNode('dummy',
                        model=kw.get('model'),
                        n=n,
                        params=p,
                        mm=mm,
                        sd=sd)

    my_nest.SetStatus(mnn[:], params={'I_e': kw.get('ahp_I_e')})  # Set I_e

    scg = my_nest.Create('step_current_generator', n=n)
    rec = my_nest.GetStatus(mnn[:])[0]['receptor_types']

    for source, target, I in zip(scg, mnn[:], I_vec):
        my_nest.SetStatus([source], {
            'amplitude_times': [500., 1000.],
            'amplitude_values': [float(I), 0.]
        })
        my_nest.Connect([source], [target],
                        params={'receptor_type': rec['CURR']})

    my_nest.MySimulate(simTime)

    signal = mnn.spike_signal.time_slice(700, 3000)

    delays = []
    for i in range(n):
        #         print signal.spiketrains[i+1.0].spike_times
        v = numpy.diff(signal.spiketrains[i + 1.0].spike_times)
        v = numpy.append(v, [0])
        delays.append(max(v))

    dg = Data_generic(**{
        'x': I_vec,
        'y': delays,
        'xlabel': 'Time (ms)',
        'ylabel': 'Voltage (mV)'
    })

    return {'ahp': dg}
Пример #3
0
def simulate_network(**kw):
    my_nest.ResetKernel()
    my_nest.SetKernelStatus({
        'local_num_threads': 1,
        #                              'print_time':True
    })

    p_gi = par.dic['nest']['GI']
    p_st = par.dic['nest']['ST']
    for d in [p_gi, p_st]:
        if 'type_id' in d: del d['type_id']

    mm = {'active': True, 'params': {'to_memory': True, 'to_file': False}}
    st = MyNetworkNode('st', model='my_aeif_cond_exp', n=1, params=p_st, mm=mm)

    for key in ['GI_ST_gaba', 'CS_ST_ampa']:
        d = par.dic['nest'][key]
        if 'type_id' in d: del d['type_id']
        my_nest.CopyModel('static_synapse', key, d)

    d = {
        'rate_first': 30**2. * (1 + kw.get('gi_amp', 0)),
        'rate_second': 30**2.**(1 - kw.get('gi_amp', 0)),
        'period_first': 25.0,
        'period_second': 25.
    }
    inp_st_gaba = my_nest.Create('poisson_generator_periodic', n=1, params=d)

    d = {
        'rate_first': 400. * (1 + kw.get('st_amp', 0)),
        'rate_second': 400.**(1 - kw.get('st_amp', 0)),
        'period_first': 25.0,
        'period_second': 25.
    }
    inp_st_ampa = my_nest.Create('poisson_generator_periodic', n=1, params=d)

    my_nest.Connect(inp_st_gaba, st.ids, 0.08, 1., model='GI_ST_gaba')
    my_nest.Connect(inp_st_ampa, st.ids, 0.25, 1., model='CS_ST_ampa')

    my_nest.Simulate(kw.get('sim_time'), chunksize=1000.0)

    d = {}

    from core.network.data_processing import Data_unit_vm
    st_dus = Data_unit_vm('st', st.get_voltage_signal())
    d['st'] = {'vm_signal': st_dus}

    return d
Пример #4
0
def simulate_IV(**kw):

    I_vec = kw.get('iv_I_vec')
    my_nest.ResetKernel({'local_num_threads': 1})

    sd = {
        'active': True,
        'params': {
            'to_memory': True,
            'to_file': False,
            'start': 500.0
        }
    }
    mm = {
        'active': True,
        'params': {
            'interval': 0.1,
            'to_memory': True,
            'to_file': False
        }
    }
    p = kw.get('iv_params')
    if 'type_id' in p.keys(): del p['type_id']
    mnn = MyNetworkNode('dummy',
                        model=kw.get('model'),
                        n=1,
                        params=p,
                        mm=mm,
                        sd=sd)

    I_e0 = my_nest.GetStatus(mnn[:])[0]['I_e']
    my_nest.SetStatus(mnn[:], params={'I_e': I_e0 + kw.get('I_E')})  # Set I_e

    x, y = mnn.run_IV_I_clamp(I_vec)
    print x, y
    dg = Data_generic(**{
        'x': x,
        'y': y,
        'xlabel': 'Current (pA)',
        'ylabel': 'Voltage (mV)'
    })

    return {'IV': dg}
Пример #5
0
def simulate_rebound_spike(**kw):
    
    n=len(kw.get('rs_curr'))
    
    simTime  = 3000.  # ms
    my_nest.ResetKernel({'local_num_threads':1})

    sd={'active':True, 'params':{'to_memory':True,'to_file':False}}
    mm={'active':True,
        'params':{'interval':0.1,'to_memory':True,'to_file':False}}
    p=kw.get('rs_params')
    
    if 'type_id' in p.keys(): del p['type_id']
    mnn=MyNetworkNode('dummy',model=kw.get('model'), n=n, params=p, mm=mm, sd=sd)
    
    my_nest.SetStatus(mnn[:], params={'I_e':.5}) # Set I_e
    I_e = my_nest.GetStatus(mnn.ids,'I_e')[0]    
    
    scg = my_nest.Create( 'step_current_generator',n=n )  
    rec=my_nest.GetStatus(mnn[:])[0]['receptor_types']
    
    i=0
    for t, c in zip(kw.get('rs_time'), kw.get('rs_curr')):
        my_nest.SetStatus([scg[i]], {'amplitude_times':[500.,t+500.],
                                'amplitude_values':[float(c),0.]})
        my_nest.Connect( [scg[i]], [mnn[i]],  params = { 'receptor_type' : rec['CURR'] } )
        i+=1
    
    my_nest.MySimulate(simTime)
    mnn.voltage_signal.my_set_spike_peak( 21, spkSignal= mnn.spike_signal )
    
    d={}
    for i in range(n):
        voltage=mnn.voltage_signal.analog_signals[i+1].signal
        x=numpy.linspace(0,simTime, len(voltage))
        dg=Data_generic(**{'x':x, 'y':voltage, 'xlabel':'Time (ms)', 'ylabel':'Voltage (mV)'})
        misc.dict_update(d, {'rs_voltage_{0}'.format(i):dg})
    rd=mnn.spike_signal.raw_data()
    dg=Data_scatter(**{'x':rd[:,0], 'y':rd[:,1], 'xlabel':'Time (ms)', 'ylabel':'Voltage (mV)'})
    misc.dict_update(d, {'rs_scatter':dg})
    
    return d
Пример #6
0
def simulate_network(**kw):
    my_nest.ResetKernel()
    my_nest.SetKernelStatus({
        'local_num_threads': 4,
        #                              'print_time':True
    })

    p_gi = par.dic['nest']['GI']
    p_st = par.dic['nest']['ST']

    p_st.update(kw.get('p_st', {}))

    for d in [p_gi, p_st]:
        if 'type_id' in d: del d['type_id']

    sd = {
        'active': True,
        'params': {
            'to_memory': True,
            'to_file': False,
            'start': 500.0
        }
    }
    gi = MyNetworkNode('gi',
                       model='my_aeif_cond_exp',
                       n=kw.get('gi_n'),
                       params=p_gi,
                       sd=sd)
    #     st=MyNetworkNode('gi',model='my_aeif_cond_exp', n=kw.get('st_n'), params=p_gi, sd=sd)
    st = MyNetworkNode('st',
                       model='my_aeif_cond_exp',
                       n=kw.get('st_n'),
                       params=p_st,
                       sd=sd)

    for key in [
            'GI_ST_gaba', 'GI_GI_gaba', 'ST_GI_ampa', 'EI_GI_ampa',
            'CS_ST_ampa'
    ]:
        d = par.dic['nest'][key]
        if 'type_id' in d: del d['type_id']
        my_nest.CopyModel('static_synapse', key, d)

    df = my_nest.GetDefaults('my_aeif_cond_exp')['receptor_types']
    for post in st:
        idx = random.sample(range(kw.get('gi_n')), 30)
        #         params={'receptor_type':df['GABAA_1']}
        delay = kw['gi_st_delay']
        model = 'GI_ST_gaba'
        my_nest.Connect([pre for i, pre in enumerate(gi) if i in idx],
                        [post] * 30, [0.08] * 30, [delay] * 30, model)

    for pre in gi:
        idx = random.sample(range(kw.get('gi_n')), 30)
        #         params={'receptor_type':df['GABAA_1']}
        delay = kw['gi_gi_delay']
        model = 'GI_GI_gaba'
        my_nest.Connect([pre] * 30,
                        [post for i, post in enumerate(gi) if i in idx],
                        [1.3] * 30, [delay] * 30, model)

    for pre in gi:
        idx = random.sample(range(kw.get('st_n')), 30)
        #         params={'receptor_type':df['AMPA_1']}
        delay = kw['st_gi_delay']
        model = 'ST_GI_ampa'
        my_nest.Connect([pre for i, pre in enumerate(st) if i in idx],
                        [post] * 30, [0.35] * 30, [delay] * 30, model)

    d = {
        'rate_first': 1400. * (1 + kw.get('gi_amp', 0)),
        'rate_second': 1400.**(1 - kw.get('gi_amp', 0)),
        'period_first': 25.0,
        'period_second': 25.
    }
    inp_gi = my_nest.Create('poisson_generator_periodic',
                            n=kw.get('gi_n'),
                            params=d)

    d = {
        'rate_first': 400. * (1 + kw.get('st_amp', 0)),
        'rate_second': 400.**(1 - kw.get('st_amp', 0)),
        'period_first': 25.0,
        'period_second': 25.
    }
    inp_st = my_nest.Create('poisson_generator_periodic',
                            n=kw.get('st_n'),
                            params=d)

    my_nest.Connect(inp_gi, gi.ids, 0.25, 1., model='EI_GI_ampa')
    my_nest.Connect(inp_st, st.ids, 0.25, 1., model='CS_ST_ampa')

    my_nest.Simulate(kw.get('sim_time'), chunksize=1000.0)

    d = {}

    from core.network.data_processing import Data_unit_spk, Data_units_relation
    gi_dus = Data_unit_spk('gi', gi.get_spike_signal())
    d['gi'] = {'spike_signal': gi_dus}
    st_dus = Data_unit_spk('st', st.get_spike_signal())
    d['st'] = {'spike_signal': st_dus}

    d['gi_st'] = {'spike_signal': Data_units_relation('gi_st', gi_dus, st_dus)}

    return d
Пример #7
0
def simulate_irregular_firing(**kw):

    n = len(kw.get('irf_curr'))
    I_vec = numpy.array(kw.get('irf_curr'))

    simTime = 2000.  # ms
    my_nest.ResetKernel({'local_num_threads': 1})

    sd = {'active': True, 'params': {'to_memory': True, 'to_file': False}}
    mm = {
        'active': True,
        'params': {
            'interval': 0.1,
            'to_memory': True,
            'to_file': False
        }
    }
    p = kw.get('rs_params')

    if 'type_id' in p.keys(): del p['type_id']
    mnn = MyNetworkNode('dummy',
                        model=kw.get('model'),
                        n=n,
                        params=p,
                        mm=mm,
                        sd=sd)

    I_e0 = my_nest.GetStatus(mnn.ids, 'I_e')[0]

    for i, I_e in enumerate(I_vec):
        my_nest.SetStatus([mnn[i]], params={'I_e': I_e + I_e0})

    scg = my_nest.Create('step_current_generator', n=n)
    noise = my_nest.Create('noise_generator', params={'mean': 0., 'std': 10.})
    rec = my_nest.GetStatus(mnn[:])[0]['receptor_types']

    for source, target, I in zip(scg, mnn[:], I_vec):
        my_nest.SetStatus([source], {
            'amplitude_times': [1., simTime],
            'amplitude_values': [-5., float(I)]
        })
        my_nest.Connect([source], [target],
                        params={'receptor_type': rec['CURR']})
        my_nest.Connect(noise, [target], params={'receptor_type': rec['CURR']})

    my_nest.MySimulate(simTime)
    mnn.voltage_signal.my_set_spike_peak(21, spkSignal=mnn.spike_signal)

    d = {}
    for i in range(n):
        voltage = mnn.voltage_signal.analog_signals[i + 1].signal
        x = numpy.linspace(0, simTime, len(voltage))
        dg = Data_generic(**{
            'x': x,
            'y': voltage,
            'xlabel': 'Time (ms)',
            'ylabel': 'Voltage (mV)'
        })
        misc.dict_update(d, {'irf_voltage_{0}'.format(i): dg})


#     my_nest.MySimulate(simTime)
#     mnn.get_signal( 'v','V_m', stop=simTime ) # retrieve signal
#     mnn.get_signal( 's') # retrieve signal
#     mnn.signals['V_m'].my_set_spike_peak( 15, spkSignal= mnn.signals['spikes'] )

    return d