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
示例#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_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
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
'''
Created on Oct 20, 2014

@author: mikael
'''

import numpy
from core import my_nest
my_nest.SetKernelStatus({"total_num_virtual_procs": 4})
pg = my_nest.Create("poisson_generator", 20, params={"rate": 50000.0})
n = my_nest.Create('aeif_cond_exp', 20)
# n = my_nest.Create('iaf_neuron', 20)
w = [10. for _ in n]
d = [1. for _ in n]
sd = my_nest.Create("spike_detector",
                    params={
                        "to_file": False,
                        "to_memory": True
                    })

post = n
post_ids = list(numpy.unique(post))
status = my_nest.GetStatus(list(numpy.unique(post)), 'local')
lockup = dict(zip(post_ids, status))
l = [1 if lockup[p] else 0 for p in post]
print l

pre = [p for p, b in zip(pg, l) if b]
post = [p for p, b in zip(n, l) if b]
my_nest.Connect_speed(pre, post, w, d)
my_nest.ConvergentConnect(n, sd)
import numpy
import pylab

from os.path import expanduser
from core import my_nest
import mpi4py

HOME = expanduser("~")
MODULE_PATH = (HOME + '/opt/NEST/dist/install-nest-2.2.2/lib/nest/ml_module')
my_nest.Install(MODULE_PATH)

#ip=my_nest.Create('spike_generator',params={'spike_times':[10.,20.]})
ip = my_nest.Create('poisson_generator', 3, params={'rate': 3500.})
pn = my_nest.Create('parrot_neuron', 3)
sd = my_nest.Create('spike_detector')
n = my_nest.Create('iaf_cond_exp', 3, params={'C_m': 200.0, 'V_th': -50.})
vt = my_nest.Create('volume_transmitter')
my_nest.Connect(ip, pn)
my_nest.Connect([pn[2]], [n[2]], params={'weight': 10.})
my_nest.Connect([n[2]], sd)

my_nest.Connect([n[2]], vt)

my_nest.Connect(pn[0:2], n[0:2])
my_nest.SetDefaults('bcpnn_dopamine_synapse', params={'vt': vt[0]})
my_nest.Connect([n[0]], [n[1]], model='bcpnn_dopamine_synapse')

p_sd = {"withgid": True, 'to_file': False, 'to_memory': True}
sd = my_nest.Create('spike_detector', 5, params=p_sd)
pd = my_nest.Create('poisson_generator', 5, params={'rate': 100.})
my_nest.Connect(pd, sd)
示例#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