def simulate(from_disk=0, kw={}, net='Net_0', script_name=__file__.split('/')[-1][0:-3], setup=Setup(50,20) ): setup=Setup(50,20) file_name = kw.get('file_name', dr.HOME_DATA+'/'+script_name) file_name_figs = kw.get('file_name_figs', dr.HOME_DATA+'/fig/'+script_name) sd=get_storage_list([net], file_name, '')[0] d={} if from_disk==0: print net dd={net:simulate_network(**kw)} dd=compute_attrs(dd, net, setup) save(sd, dd) if from_disk==1: filt= [net]+['gi','st', 'gi_st']+['spike_signal'] dd = load(sd, *filt) pp(dd) dd=compute_attrs(dd, net, setup) save(sd, dd) elif from_disk==2: filt = [net]+['gi','st', 'gi_st']+['firing_rate', 'phases_diff_with_cohere'] dd = load(sd, *filt) d = misc.dict_update(d, dd) return d, file_name_figs
def main(): k = get_kwargs_builder() from os.path import expanduser home = expanduser("~") attr = ['firing_rate', 'mean_rates', 'spike_statistic'] kwargs_dic = { 'mean_rates': { 't_start': k['start_rec'] }, 'spike_statistic': { 't_start': k['start_rec'] }, } file_name = (home + '/results/papers/inhibition/network/' + __file__.split('/')[-1][0:-3]) models = ['M1', 'M2', 'FS', 'GI', 'GA', 'ST', 'SN'] info, nets, _ = get_networks() sd = Storage_dic.load(file_name) sd.add_info(info) sd.garbage_collect() d = {} for net, from_disk in zip(nets, [1] * 2): if not from_disk: dd = run(net) dd = compute(dd, models, attr, **kwargs_dic) save(sd, dd) elif from_disk: filt = [net.get_name()] + models + attr dd = load(sd, *filt) d = misc.dict_update(d, dd) figs = [] figs.append(show_fr(d, models)) figs.append(show_hr(d, models)) sd.save_figs(figs) if DISPLAY: pylab.show() pylab.show()
def _run(storage_dic, d, net, from_disk, attr, **kwargs): model = net.get_single_unit() kwargs_dic = {attr: kwargs} if not from_disk: dd = {net.get_name(): net.simulation_loop()} dd = compute(dd, [model], [attr], **kwargs_dic) save(storage_dic, dd) elif from_disk: # filt = [net.get_name()] + [model] + ['spike_signal'] # dd = load(storage_dic, *filt) # dd = compute(dd, [model], [attr], **kwargs_dic) # save(storage_dic, dd) filt = [net.get_name()] + [model] + [attr] dd = load(storage_dic, *filt) dd = reduce_levels(dd, [model] + [attr]) d = misc.dict_update(d, dd) return d
def simulate( from_disk=0, kw={}, net='Net_0', script_name=__file__.split('/')[-1][0:-3], setup=Setup(50, 20), ): file_name = kw.get('file_name', dr.HOME_DATA + '/' + script_name) file_name_figs = kw.get('file_name_figs', dr.HOME_DATA + '/fig/' + script_name) sd = get_storage_list([net], file_name, '')[0] d = {} if from_disk == 0: print net dd = {} for call in kw.get('calls', [ simulate_irregular_firing, simulate_ahp, simulate_IV, simulate_IF, get_nullcline, simulate_rebound_spike, ]): misc.dict_update(dd, {net: call(**kw)}) save(sd, dd) elif from_disk == 1: filt = kw.get('filter', [net] + ['IV', 'IF', 'ahp', 'nullcline'] + ['rs_scatter'] + ['rs_voltage_{0}'.format(i) for i in range(6)] + ['irf_voltage_{0}'.format(i) for i in range(3)]) dd = load(sd, *filt) d = misc.dict_update(d, dd) return d, file_name_figs
def _run_XX(flag, storage_dic, stim, d, net, from_disk): model = net.get_single_unit() inp = net.get_single_unit_input() if flag == 'IV': attr = 'IV_curve' stim_name = 'node.' + model + '.nest_params.I_e' call = getattr(net, 'sim_IV_curve') if flag == 'IF': attr = 'IF_curve' stim_name = 'node.' + model + '.nest_params.I_e' call = getattr(net, 'sim_IF_curve') if flag == 'FF': attr = 'FF_curve' stim_name = 'node.' + inp + '.rate' call = getattr(net, 'sim_FF_curve') if not from_disk: k = { 'stim': stim, 'stim_name': stim_name, 'stim_time': net.get_sim_time(), 'model': model } dd = {net.get_name(): call(**k)} dd = compute(dd, [model], [attr]) save(storage_dic, dd) elif from_disk: filt = [net.get_name()] + [model] + [attr] dd = load(storage_dic, *filt) pp(dd) dd = reduce_levels(dd, [model] + [attr]) d = misc.dict_update(d, dd) return d
def _optimize(flag, net, storage_dic, d, from_disk, **kwargs): model = net.get_single_unit() inp = net.get_single_unit_input() attr = 'fmin' f = [model] if flag == 'opt_rate': x = ['node.' + inp + '.rate'] if flag == 'opt_curr': x = ['node.' + model + '.nest_params.I_e'] x0 = kwargs.get('x0', 900.) opt = {'netw': {'optimization': {'f': f, 'x': x, 'x0': x0}}} net.par.update_dic_rep(opt) kwargs_fmin = { 'model': net, 'call_get_x0': 'get_x0', 'call_get_error': 'sim_optimization', 'verbose': kwargs.get('verbose', True) } if not from_disk: f = Fmin(net.name, **kwargs_fmin) dd = {net.get_name(): {model: {attr: f.fmin()}}} print dd save(storage_dic, dd) elif from_disk: filt = [net.get_name()] + [model] + [attr] dd = load(storage_dic, *filt) dd = reduce_levels(dd, [model] + [attr]) d = misc.dict_update(d, dd) return d
def simulate(from_disk=0, kw={}, net='Net_0', script_name=__file__.split('/')[-1][0:-3], setup=Setup(50,20), ): file_name = kw.get('file_name', dr.HOME_DATA+'/'+script_name) file_name_figs = kw.get('file_name_figs', dr.HOME_DATA+'/fig/'+script_name) sd=get_storage_list([net], file_name, '')[0] d={} if from_disk==0: print net dd={} for call in kw.get('calls',[simulate_irregular_firing, simulate_ahp, simulate_IV, simulate_IF, get_nullcline, simulate_rebound_spike,]): misc.dict_update(dd,{net:call(**kw)}) save(sd, dd) elif from_disk==1: filt = kw.get('filter', [net]+['IV', 'IF', 'ahp', 'nullcline'] +['rs_scatter']+['rs_voltage_{0}'.format(i) for i in range(6)] +['irf_voltage_{0}'.format(i) for i in range(3)]) dd = load(sd, *filt) d = misc.dict_update(d, dd) return d, file_name_figs
nets = ['Net_{0:0>2}'.format(i) for i in range(len(kw_list))] sd_list = get_storage_list(nets, path, '') d = {} for net, sd, kw in zip(nets, sd_list, kw_list): if from_disk == 0: # and net=='Net_05': print net dd = {net: simulate_network(**kw)} dd = compute_attrs(dd, net) save(sd, dd) if from_disk == 1: filt = [net] + ['gi', 'st', 'gi_st'] + ['spike_signal'] dd = load(sd, *filt) pp(dd) dd = compute_attrs(dd, net) save(sd, dd) elif from_disk == 2: filt = [net] + ['gi', 'st', 'gi_st' ] + ['firing_rate', 'phases_diff_with_cohere'] dd = load(sd, *filt) d = misc.dict_update(d, dd) pp(d) fig, axs = get_fig_axs() for i in range(len(nets)):
simulate_rebound_spike, ]: misc.dict_update(dd,{net:call(**kw)}) save(sd, dd) # if from_disk==1: # filt= [net]+['gi','st', 'gi_st']+['spike_signal'] # dd = load(sd, *filt) # pp(dd) # dd=compute_attrs(dd, net) # save(sd, dd) elif from_disk==1: filt = [net]+['IV', 'IF', 'nullcline'] +['rs_scatter'] dd = load(sd, *filt) d = misc.dict_update(d, dd) pp(d) fig, axs=get_fig_axs() colors=misc.make_N_colors('jet', len(nets)) for i in range(len(nets)): dtmp=d['Net_0{0}'.format(i)] if 'IV' not in dtmp.keys(): continue dtmp['IV'].plot(axs[0], **{'color':colors[i]}) dtmp=d['Net_0{0}'.format(i)] if 'IV' not in dtmp.keys(): continue
def plot(file_name, figs, setup, flag, **k): nets = ['Net_0', 'Net_1'] attr = ['firing_rate', 'mean_rates', 'spike_statistic'] attr2 = ['psd', 'activity_histogram', 'activity_histogram_stat'] attr_coher = ['phase_diff', 'phases_diff_with_cohere', 'mean_coherence'] models = ['M1', 'M2', 'FS', 'GI', 'GA', 'ST', 'SN', 'GP'] models_coher = [ 'GI_GA', 'GI_GI', 'GA_GA', 'GA_ST', 'GI_ST', 'GP_GP', 'ST_ST', 'GP_ST', ] # Adding nets no file name sd_list = get_storage_list(nets, file_name, '') d = {} for sd, net in zip(sd_list, nets): filt = ([net] + models + models_coher + attr + attr2 + attr_coher) dd = load(sd, *filt) # cmp_statistical_test(models, dd) d = misc.dict_update(d, dd) kw = setup.plot_summed2() kw['alphas'] = [1., 1.] kw['coherence_xcut'] = [0, 50] kw['coherence_color'] = ['grey', 'k'] kw['coherence_p_conf95_linestyle'] = '--' kw['hatchs_ti_ti'] = ['', ''] kw['label_model'] = 'Black=Model' kw['label_exp'] = 'White=Exp., Mallet et al 2008' kw['linewidth'] = 1. kw['set_text_on_bars'] = False kw['top_label'] = False kw['phases_diff_with_cohere_colors'] = ['grey', 'k'] kw['phases_diff_with_cohere_xcut'] = [-numpy.pi * 0.97, numpy.pi**0.97] kw['phases_diff_with_cohere_remove_peaks'] = True kw['scale'] = 1 kw['spk_stats_color_axis'] = 1 kw['spk_stats_colors'] = ['k', 'w'] kw['spk_stats_colors_ti_ta'] = ['k', 'w'] kw['xlim_cohere'] = [-1, 51] kw.update(k) figs.append(base_oscillation.show_summed2(d, **kw)) kw = setup.plot_summed_STN() kw['alphas'] = [1., 1.] kw['coherence_color'] = ['grey', 'k'] kw['coherence_p_conf95_linestyle'] = '--' kw['hatchs_ti_ti'] = ['', ''] kw['label_model'] = 'Black=Model' kw['label_exp'] = 'White=Exp., Mallet et al 2008' kw['linewidth'] = 1. kw['phases_diff_with_cohere_xcut'] = [-numpy.pi * 0.97, numpy.pi**0.97] kw['phases_diff_with_cohere_remove_peaks'] = True kw['phases_diff_with_cohere_colors'] = ['grey', 'k'] kw['scale'] = 1 kw['set_text_on_bars'] = False kw['spk_stats_colors'] = ['k', 'w'] kw['spk_stats_colors_ti_ta'] = ['k', 'w'] kw['spk_stats_color_axis'] = 1 kw['top_label'] = False kw['xlim_cohere'] = [-1, 51] if flag == 'slow_wave': kw['ylim_cohere'] = [0, 1.0] elif flag == 'beta': kw['ylim_cohere'] = [0, 0.4] kw['coherence_xcut'] = [0, 50] kw.update(k) figs.append(base_oscillation.show_summed_STN(d, **kw)) return figs
def plot(file_name, figs, setup, flag, **k): nets=['Net_0', 'Net_1'] attr = [ 'firing_rate', 'mean_rates', 'spike_statistic' ] attr2=['psd', 'activity_histogram', 'activity_histogram_stat'] attr_coher = [ 'phase_diff', 'phases_diff_with_cohere', 'mean_coherence' ] models = ['M1', 'M2', 'FS', 'GI', 'GA', 'ST', 'SN', 'GP'] models_coher = ['GI_GA', 'GI_GI', 'GA_GA', 'GA_ST', 'GI_ST', 'GP_GP', 'ST_ST', 'GP_ST',] # Adding nets no file name sd_list=get_storage_list(nets, file_name, '') d = {} for sd, net in zip(sd_list, nets): filt = ([net] + models + models_coher + attr + attr2 + attr_coher) dd = load(sd, *filt) # cmp_statistical_test(models, dd) d = misc.dict_update(d, dd) kw=setup.plot_summed2() kw['alphas']=[1.,1.] kw['coherence_xcut']=[0,50] kw['coherence_color']=['grey', 'k'] kw['coherence_p_conf95_linestyle']='--' kw['hatchs_ti_ti']=['',''] kw['label_model']='Black=Model' kw['label_exp']='White=Exp., Mallet et al 2008' kw['linewidth']=1. kw['set_text_on_bars']=False kw['top_label']=False kw['phases_diff_with_cohere_colors']=['grey','k'] kw['phases_diff_with_cohere_xcut']=[-numpy.pi*0.97, numpy.pi**0.97] kw['phases_diff_with_cohere_remove_peaks']=True kw['scale']=1 kw['spk_stats_color_axis']=1 kw['spk_stats_colors']=['k', 'w'] kw['spk_stats_colors_ti_ta']=['k','w'] kw['xlim_cohere']=[-1, 51] kw.update(k) figs.append(base_oscillation.show_summed2(d, **kw)) kw=setup.plot_summed_STN() kw['alphas']=[1.,1.] kw['coherence_color']=['grey','k'] kw['coherence_p_conf95_linestyle']='--' kw['hatchs_ti_ti']=['',''] kw['label_model']='Black=Model' kw['label_exp']='White=Exp., Mallet et al 2008' kw['linewidth']=1. kw['phases_diff_with_cohere_xcut']=[-numpy.pi*0.97, numpy.pi**0.97] kw['phases_diff_with_cohere_remove_peaks']=True kw['phases_diff_with_cohere_colors']=['grey','k'] kw['scale']=1 kw['set_text_on_bars']=False kw['spk_stats_colors']=['k', 'w'] kw['spk_stats_colors_ti_ta']=['k','w'] kw['spk_stats_color_axis']=1 kw['top_label']=False kw['xlim_cohere']=[-1, 51] if flag=='slow_wave': kw['ylim_cohere']=[0, 1.0] elif flag=='beta': kw['ylim_cohere']=[0, 0.4] kw['coherence_xcut']=[0,50] kw.update(k) figs.append(base_oscillation.show_summed_STN(d, **kw)) return figs