Пример #1
0
def show_plot(axs,
              name,
              d,
              models=['M1', 'M2', 'FS', 'GA', 'GI', 'ST', 'SN'],
              **k):
    dd = {}
    by_sets = k.pop('by_sets', False)

    for keys, val in misc.dict_iter(d):

        if keys[-1] != name:
            continue
        if by_sets and keys[0][0:3] != 'set':
            continue

        first_keys = keys[:-2]
        if type(first_keys) == str:
            first_keys = [first_keys]

        new_keys = ['_'.join(first_keys)] + keys[-2:]

        dd = misc.dict_recursive_add(dd, new_keys, val)

    d = dd

    #     if k.get('fig_and_axes', False):

    #     else:
    #         fig, axs=ps.get_figure(n_rows=len(models), n_cols=1, w=1000.0, h=800.0,
    #                            fontsize=k.get('fontsize',10))
    labels = k.pop('labels', sorted(d.keys()))
    #     colors=misc.make_N_colors('Paired', max(len(labels), 6))
    colors = k.pop('colors', misc.make_N_colors('jet', max(len(labels), 1)))
    linestyles = ['-'] * len(labels)

    j = 0
    nets = k.get('nets', sorted(d.keys()))
    for key in nets:
        v = d[key]
        #         axs[0].set_title(k)
        for i, model in enumerate(models):
            kk = {
                'label': model + ' ' + labels[j],
                'linestyle': linestyles[j],
                'color': colors[j]
            }
            if 'win' in k.keys():
                kk['win'] = k['win']
            if 't_start' in k.keys():
                kk['t_start'] = k['t_start']
            if 't_stop' in k.keys():
                kk['t_stop'] = k['t_stop']

            print model
            if model in v.keys():
                v[model][name].plot(ax=axs[i], **kk)
        j += 1

    for ax in axs:
        ax.legend()
Пример #2
0
def show_hist(name, d, models=['M1', 'M2', 'FS', 'GA', 'GI', 'ST', 'SN'], **k):

    fig, axs = ps.get_figure(n_rows=len(models),
                             n_cols=1,
                             w=1000.0,
                             h=800.0,
                             fontsize=10)
    labels = k.pop('labels', sorted(d.keys()))

    colors = misc.make_N_colors('jet', len(labels))
    linestyles = ['solid'] * len(labels)
    linewidth = [2.0] * len(labels)
    j = 0

    for key in sorted(d.keys()):
        v = d[key]
        #         axs[0].serunt_title(k)

        for i, model in enumerate(models):
            if 'spike_stastistic' in v[model]:
                st = v[model]['spike_statistic']
                st.rates = {
                    'mean': round(st.rates['mean'], 2),
                    'std': round(st.rates['std'], 2),
                    'CV': round(st.rates['CV'], 2)
                }
                s = str(st.rates)
            else:
                s = ''
#             print s
#             print labels[j]
            k.update({
                'label': (model + ' ' + labels[j] + ' ' + s),
                'histtype': 'step',
                'linestyle': linestyles[j],
                'color': colors[j],
                'linewidth': linewidth[j]
            })
            #             print k
            h = v[model][name].hist(ax=axs[i], **k)

            ylim = list(axs[i].get_ylim())
            ylim[0] = 0.0
            axs[i].set_ylim(ylim)
            axs[i].legend_box_to_line()
        j += 1


#     import pylab
#     pylab.show()
    return fig, axs
Пример #3
0
def show_opt_hist(d, axs, name):
    colors = misc.make_N_colors('jet', len(d['opt_rate'].keys()))
    i = 0
    for key in sorted(d['opt_rate'].keys()):
        data = d['opt_rate'][key]
        data.plot(axs[0], name, **{'color': colors[i]})
        i += 1
    for key in sorted(d['hist'].keys()):
        data = d['hist'][key]
        data.hist(axs[0])

    linestyles = ['solid'] * len(colors)
    linewidth = [2] * len(colors)
    beautify_hist(axs[0], colors, linestyles, linewidth)
Пример #4
0
def show_neuron_numbers(d, models, **k):
    attr='firing_rate'    
    linestyle=['-','--']
    
    labels=k.pop('labels', models) 
    colors=misc.make_N_colors('jet', max(len(labels), 1))
    
    fig, axs=ps.get_figure(n_rows=1, n_cols=1, w=500.0, h=500.0, fontsize=10)    
    l_ids=[]
    ax=axs[0]
    for k, model in enumerate(models):

        max_set=0
        
        for j, name in enumerate(sorted([d.keys()[0]])):
            v=d[name]
            sets=[s for s in sorted(v.keys()) if s[0:3]=='set']
            
            ids=0
            for i, _set in enumerate(sets):
                
                if not model in v[_set].keys():
                    break
                
                obj=v[_set][model][attr]
                
                ids+=len(obj.ids)
                if max_set<=i:
                    max_set+=1            
        l_ids.append(ids)
    
    
     
    obj=Data_bar(**{'y':numpy.array(l_ids)})   
    obj.bar(ax)

    ax.set_xticklabels(labels)
    return fig
Пример #5
0
        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)):
        d['Net_0{0}'.format(i)]['gi']['firing_rate'].plot(
            axs[i], **{'win': 1.})
        d['Net_0{0}'.format(i)]['st']['firing_rate'].plot(
            axs[i], **{'win': 1.})
        axs[i].set_xlim(0.0, 1500.0)

    colors = misc.make_N_colors('copper', len(kw_list))

    #     for net, c in zip(nets, colors):
    #         kw={ 'all':True,
    #            'color':c,
    #            'p_95':False,}
    #         d[net]['gi_st']['phases_diff_with_cohere'].hist(axs[-1], **kw)
    #     axs[-1].set_xlim(-numpy.pi, numpy.pi)

    pylab.show()

    # pylab.plot(d['n'])
Пример #6
0
#             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
        dtmp['IF'].plot(axs[1],
                        part='first',
                        **{
                            'color': colors[i],
                            'linestyle': '-'
                        })
        dtmp['IF'].plot(axs[1],
                        part='mean',
#     v=[ah.y, ah_GP.y]
    

#     v=d['data'][key]['Net_0']['GI_FS']['phases_diff_with_cohere']

    l1.append(ah.y)
    l2.append(ah_GP.y)
    
l=numpy.array(l1[organize['TATIFS']])

pp(l)

# FSN
#####
pp(l)
colors=misc.make_N_colors('copper', len(l))

ln=list_names[organize['TATIFS']]
pp(ln)
ln=[a[2]+','+a[4] for a in ln]
pp(ln)
  
for i, trace in enumerate(l):
    x=numpy.linspace(0,1000,len(trace))
#     norm=sum(trace)*(x[-1]-x[0])/len(x)
#     norm=numpy.mean(x)
    ax.plot(x, (numpy.array(trace)-trace[0]), color=colors[i])


ax.set_xlim([0,1000])
  
Пример #8
0
#             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
        dtmp['IF'].plot(axs[1], part='first',**{'color':colors[i],'linestyle':'-'})
        dtmp['IF'].plot(axs[1], part='mean', **{'color':colors[i],'linestyle':'--'})


        dtmp=d['Net_0{0}'.format(i)]
        if 'nullcline' not in dtmp.keys(): continue
        dtmp['nullcline'].plot(axs[2],**{'color':colors[i]})
Пример #9
0
def show_bulk(d, models, attr, **k):
    
#     attr='mean_rate_slices'    
    linestyle=['-','--']
    
    labels=k.pop('labels', sorted(d.keys()))  
    colors=misc.make_N_colors('jet', max(len(labels), 1))
    
    fig, axs=ps.get_figure(n_rows=7, n_cols=1, w=1200.0, h=800.0, fontsize=10)    
    res=k.pop('res')
    i=0
    xticks=[]
    for j in range(res):
        for k in range(res):
            if j==k:
                xticks.append(i)
            i+=1
                    
    
    for k, model in enumerate(models):        
        ax=axs[k]
#         max_set=0
        for j, name in enumerate(sorted(d.keys())):
            v=d[name]
            sets=[s for s in v.keys() if s[0:3]=='set']
            for i, _set in enumerate(sets):
                
                if not model in v[_set].keys():
                    break
                
                obj=v[_set][model][attr]
                obj.plot(ax, **{'color':colors[j],
                                'linestyle':linestyle[i],
                                'label':labels[j]
                                })
#                 if max_set<=i:
#                     max_set+=1
        
        max_set=len(sets)
        ax.set_ylabel(model+' (spikes/s)')
        ax.set_xticks(xticks)
        #Get artists and labels for legend and chose which ones to display
        if k!=0:
            continue    
        handles, _labels = ax.get_legend_handles_labels()
        display = range(0,len(d.keys())*max_set, max_set)
            

        #Create custom artists
        linetype_labels=[]
        linetype_handles=[]
        for i in range(max_set):
            linetype_handles.append(pylab.Line2D((0,1),(0,0),
                                                 color='k', 
    
                                                 linestyle=linestyle[i]))
            linetype_labels.append('Action '+str(i))

                
        #Create legend from custom artist/label lists
        ax.legend([handle for i,handle in enumerate(handles) 
                   if i in display]+linetype_handles,
          [label for i,label in enumerate(_labels) 
                   if i in display]+linetype_labels, bbox_to_anchor=(1.22, 1.))
        
        
    return fig       
Пример #10
0
#########################################
ax=axs[2]
 
l=[]
for key in sorted(d['data'].keys()):
    v=d['data'][key]['Net_1']['GI_ST']['phases_diff_with_cohere']
    l.append(v)
l=l[organize['CTXSTRdelay']][::-1]

ln0=list_names[organize['CTXSTRdelay']][::-1]
ln=[str(int(float(a[-1]))) for a in ln0]

# ln0=list_names[organize['CSdelay']][1::2]
# ln+=['2.5, ' + str(int(float(a[-1]))) for a in ln0]

colors=misc.make_N_colors('copper', len(l))
  
for i, trace in enumerate(l):
    x=numpy.linspace(-numpy.pi*3,numpy.pi*3,len(trace))
    norm=sum(trace)*(x[-1]-x[0])/len(x)
    ax.plot(x, trace/norm, color=colors[i])
ax.set_xlim([-numpy.pi,numpy.pi])
  
 
sm = pylab.cm.ScalarMappable(cmap='copper', 
                             norm=pylab.normalize(vmin=0, vmax=len(ln)-1))
sm._A = []
    
box = ax.get_position()
pos=[box.x0+1.03*box.width, box.y0+box.height*0.1,
     0.01, box.height*0.8]
        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)):
        d['Net_0{0}'.format(i)]['gi']['firing_rate'].plot(axs[i], **{'win':1.})
        d['Net_0{0}'.format(i)]['st']['firing_rate'].plot(axs[i], **{'win':1.})
        axs[i].set_xlim(0.0,1500.0)
 
    colors=misc.make_N_colors('copper', len(kw_list))
    
    
#     for net, c in zip(nets, colors):
#         kw={ 'all':True,
#            'color':c,
#            'p_95':False,}
#         d[net]['gi_st']['phases_diff_with_cohere'].hist(axs[-1], **kw)
#     axs[-1].set_xlim(-numpy.pi, numpy.pi)
 
    pylab.show() 
    
    
    
    
    # pylab.plot(d['n'])