def histogram_of_couplings(args, params, bins=10): """ plot """ INDEX, _, _, _, _, _, _, _, _, _, _, _, _, _,\ E0, EmuV, EsV, ETv = \ np.load('../3d_scan/data/full_data.npy') COUPLINGS = coupling_over_data(args, params) ############################################################################### """ removing cell31 !!!!!! """ INDEX, E0, EmuV, EsV, ETv, COUPLINGS = removing_cells(INDEX, E0, EmuV,\ EsV, ETv, COUPLINGS, cells=['cell31']) ############################################################################### YLABELS1 = [r"$\langle \nu_\mathrm{out}\rangle$"]+\ [r"coupling (Hz)"]+\ ['coupling increase (%) \n for '+p for p in args.PROTOCOLS[1:]] fig, AX = plt.subplots(1, len(args.PROTOCOLS) + 1, figsize=(3 * (1 + len(args.PROTOCOLS)), 2.5)) fig.subplots_adjust(bottom=.3, left=.1, wspace=.3, hspace=.3) for ax, i, label in zip(AX, list(range(len(args.PROTOCOLS) + 1)), YLABELS1): hist, be = np.histogram(COUPLINGS[:, i], bins=bins) ax.bar(.5 * (be[:-1] + be[1:]), hist, width=be[1] - be[0], color='k', alpha=.5) set_plot(ax, xlabel=label, ylabel='cell #') return fig
def correlating_electrophy_and_coupling(args, params): """ plot """ INDEX, _, _, _, _, _, _, _, _, _, _, _, _, _,\ E0, EmuV, EsV, ETv = \ np.load('../3d_scan/data/full_data.npy') COUPLINGS = coupling_over_data(args, params) # ############################################################################### # """ removing cell31 !!!!!! """ # INDEX, E0, EmuV, EsV, ETv, COUPLINGS = removing_cells(INDEX, E0, EmuV,\ # EsV, ETv, COUPLINGS, cells=['cell31']) # ############################################################################### YLABELS1 = [r"$\langle \nu_\mathrm{out}\rangle$"]+\ [r"coupling (Hz)"]+\ ['coupling increase (%) \n for '+p for p in args.PROTOCOLS[1:]] E_LABELS = [r"$\langle V_\mathrm{thre}^\mathrm{eff} \rangle_\mathcal{D}$ (mV)",\ r"$\langle \partial \nu / \partial \mu_V \rangle_\mathcal{D}$ (Hz/mV)",\ r"$\langle \partial \nu / \partial \sigma_V \rangle_\mathcal{D}$ (Hz/mV)",\ r"$\langle \partial \nu / \partial \tau_V^{N} \rangle_\mathcal{D}$ (Hz/%)"] X = [E0, EmuV, EsV, ETv] Y = [COUPLINGS[:, i] for i in range(COUPLINGS.shape[1])] INDEXES, MARKER, SIZE = [], ['^', 'd', '*', 's'], [12, 11, 17, 10] for cell in args.NEURONS: print(cell, np.where(np.array(INDEX) == cell)) INDEXES.append(np.where(INDEX == cell)[0][0]) fig, AX = plt.subplots(len(Y), len(X), figsize=(20, 18)) fig.subplots_adjust(wspace=.3, hspace=.3) for i in range(len(X)): for j in range(len(Y)): for k in range(len(MARKER)): AX[j, i].plot([X[i][INDEXES[k]]], [Y[j][INDEXES[k]]],\ lw=0, color='lightgray', marker=MARKER[k], label='cell '+str(k+1), ms=SIZE[k]) AX[j, i].plot([X[i][INDEXES[k]]], [Y[j][INDEXES[k]]],\ lw=0, color='k', marker='o') AX[j, i].scatter(X[i], Y[j], color='k', marker='o') cc, pp = pearsonr(X[i], Y[j]) x = np.linspace(X[i].min(), X[i].max()) AX[j, i].plot(x, np.polyval( np.polyfit(np.array(X[i], dtype='f8'), np.array(Y[j], dtype='f8'), 1), x), 'k--', lw=.5) AX[j, i].annotate('c='+str(np.round(cc,1))+', p='+'%.1e' % pp,\ (0.15,1), xycoords='axes fraction') if i in [0, 3]: AX[j, i].invert_xaxis() set_plot(AX[j, i], ['left', 'bottom'], ylabel=YLABELS1[j], xlabel=E_LABELS[i]) return fig
def space_time_vsd_style_plot(t, X, array, Xwindow = 30., tzoom=[-150, 300.], zlabel='rate (Hz)',\ xlabel='time (ms)', ylabel='cortical space', title='', zticks = None, zlim=None, with_latency_analysis=False, bar_mm=2, Nlevels=10, params={'pixels_per_mm':1.}, xzoom=None, yzoom=None): """ takes an array of shape (t, X, Y) and plots its value in 2d for different times ! at 8 different times it returns the figure """ if yzoom is None: yzoom = [0, array.shape[1]] else: yzoom = np.array(yzoom)*params['pixels_per_mm'] if xzoom is None: xzoom = [t[0], t[-1]] iXcenter = np.argmax(np.mean(array, axis=0)) iTcenter = np.argmax(np.mean(array, axis=1)) fig, ax = plt.subplots(1, figsize=(3.8,2.)) # plt.suptitle(title, fontsize=22) plt.subplots_adjust(bottom=.23, top=.97, right=.85, left=.1) c = ax.contourf(t, X, array.T, np.linspace(min([0,array.min()]), array.max(), Nlevels), cmap=mpl.cm.viridis) if zticks is None: zticks = np.round(np.linspace(min([0,array.min()]), array.max(), 5),1) plt.colorbar(c, label=zlabel, ticks=zticks) ax.annotate(str(int(bar_mm))+'mm', (-.1, 0.1), xycoords='axes fraction', rotation=90, fontsize=13) # ba if with_latency_analysis: TT, XX = find_latencies_over_space_simple(t, X, array, signal_criteria=5e-2,\ amp_criteria=1./5., discard=20) ax.plot(TT, XX, 'w--', lw=1) # bar annotation # now in pixel coordinates bar_mm *= params['pixels_per_mm'] ax.annotate('50ms', (0.2, -0.1), xycoords='axes fraction', fontsize=13) set_plot(ax, [], xticks=[], yticks=[], ylim=[X[iXcenter]-Xwindow/2., X[iXcenter]+Xwindow/2.], xlim=xzoom) ax.plot([xzoom[0], xzoom[0]], ax.get_ylim()[0]+np.array([0, bar_mm]), 'k-', lw=3) ax.plot([xzoom[0], xzoom[0]+50], ax.get_ylim()[0]*np.ones(2), 'k-', lw=3) return ax, fig
def single_experiment(i_nrn, balance=-54e-3): ## FIRING RATE RESPONSE for control feG, fiG, feI, fiI, synch, muV, sV, TvN, muGn = get_fluct_var( i_nrn, balance=balance) Fout0 = final_func(ALL_CELLS[i_nrn]['P'], muV, sV, TvN,\ ALL_CELLS[i_nrn]['Gl'] , ALL_CELLS[i_nrn]['Cm']) fig, ax = plt.subplots(figsize=(4, 3)) ## Then for other protocols PROTOCOLS = [ 'unbalanced activity', 'proximal activity', 'distal activity', 'synchrony' ] coupling = np.zeros(len(PROTOCOLS) + 2) coupling[0] = Fout0[0] coupling[1] = Fout0.mean() ax.plot(Fout0, 'k-', lw=2) COLORS = ['r', 'b', 'g', 'c'] ii = 0 for p, i in zip(PROTOCOLS, list(range(2, len(coupling)))): feG, fiG, feI, fiI, synch, muV, sV, TvN, muGn = get_fluct_var( i_nrn, exp_type=p, balance=balance) Fout2 = final_func(ALL_CELLS[i_nrn]['P'], muV, sV, TvN,\ ALL_CELLS[i_nrn]['Gl'], ALL_CELLS[i_nrn]['Cm']) coupling[i] = Fout2.mean() ax.plot(Fout2, '-', lw=2, color=COLORS[ii]) ii += 1 ax.set_title('cell' + str(i_nrn)) set_plot(ax, xticks=[]) fig.savefig('data/' + str(i_nrn) + '.svg') plt.close() return coupling
def get_cross_correlation_functions(args): NEURONS, PROTOCOLS = list(args.NEURONS), args.PROTOCOLS COLORS, SEEDS = args.COLORS, args.SEEDS print(args.NEURONS) t = np.arange(int(args.tstop * args.time_increase_factor / args.dt) - 1) * args.dt # time array # now for cross correlation analysis steps = int(args.window_for_cross_correl / (t[1] - t[0])) # number of steps to sum on t_shift = np.arange(steps + 1) * (t[1] - t[0]) fig, AX = plt.subplots(len(NEURONS), 1, figsize=(4, 3 * len(NEURONS))) plt.subplots_adjust(left=.2) fig.suptitle('coupling with\n presynaptic population \n (stPR)') [FEG, FIG, FEI, FII, MUV, SV, TVN, MUGN] = [np.zeros((len(PROTOCOLS), 2, len(t))) for i in range(8)] FOUT = np.zeros((len(NEURONS), len(PROTOCOLS), 2, len(t))) for i_nrn in range(len(NEURONS)): print('cell', i_nrn) for ip in range(len(PROTOCOLS)): print('-- protocol: ', PROTOCOLS[ip]) feG, _, feI, _, _, _, _, _, Fout = \ run_single_experiment(t, i_nrn, args, exp_type=PROTOCOLS[ip]) X, Y = 1. / 2. * (feG + feI), Fout * (t[1] - t[0]) CC = CC_func(X, Y, steps) AX[i_nrn].plot(t_shift, CC, color=COLORS[ip], lw=2) AX[i_nrn].plot(-t_shift, CC, color=COLORS[ip], lw=2) if i_nrn == len(NEURONS) - 1: set_plot(AX[i_nrn], ylabel='Hz', xlabel='time shift (s)') else: set_plot(AX[i_nrn], ylabel='Hz') return fig
ax.plot(F, x.mean(axis=0), color=COLORS[i], lw=5) if sys.argv[-2]=='with_variations': ax.fill_between(F, x.mean(axis=0)-x.std(axis=0),\ x.mean(axis=0)+x.std(axis=0), alpha=.2, color=COLORS[i]) else: for i in range(len(PROTOCOLS)): feG, fiG, feI, fiI, synch, muV, sV, TvN, muGn = get_fluct_var(i_nrn,\ exp_type=PROTOCOLS[i], len_f=len_f, precision=precision) for ax, x in zip(AX, [1e3*muV, 1e3*sV, 1e2*TvN, muGn]): ax.plot(F, x, lw=4, color=COLORS[i], label=PROTOCOLS[i]) for ax, x in zip(AX2, [feG, fiG, feI, fiI, synch]): ax.plot(F, x, lw=4, color=COLORS[i], label=PROTOCOLS[i]) for ax, ylabel in zip(AX[:-1], LABELS[:-1]): set_plot(ax, ['left'], ylabel=ylabel, xticks=[], num_yticks=4) for ax, ylabel in zip(AX2[:-1], LABELS2[:-1]): set_plot(ax, ['left'], ylabel=ylabel, xticks=[], num_yticks=4) set_plot(AX[-2], ['left'], ylabel=LABELS[-2], xticks=[], num_yticks=4) set_plot(AX[-1], ['bottom','left'],\ ylabel=LABELS[-1], xticks=[], xlabel='increasing \n presynaptic quantity') set_plot(AX2[-2], ['left'], ylabel=LABELS2[-2], xticks=[], num_yticks=4)#, yticks=[0,1,2]) set_plot(AX2[1], ['left'], ylabel=LABELS2[1], xticks=[], num_yticks=4)#, yticks=[0,2,4]) set_plot(AX2[0], ['left'], ylabel=LABELS2[0], xticks=[], num_yticks=4)#, yticks=[0,0.3,0.6]) set_plot(AX2[2], ['left'], ylabel=LABELS2[2], xticks=[], num_yticks=4)#, yticks=[0,0.15,0.3]) set_plot(AX2[-1], ['bottom','left'],\ ylabel=LABELS2[-1], xticks=[], xlabel='increasing \n presynaptic quantity', num_yticks=4) # if sys.argv[-1]!='all': # AX[0].legend(prop={'size':'xx-small'}, bbox_to_anchor=(1., 2.))
muV_th, sV_th, Tv_th, muG_th = get_the_fluct_prop_at_soma( SHTN_INPUT, params, soma, stick) for ax, x, y, yticks, ylim in zip(AX[:,ii], [1e3*muV_th, 1e3*sV_th, 1e3*Tm0*Tv_th],\ [EXP['muV_exp'], EXP['sV_exp'], EXP['Tv_exp']],\ YTICKS, YLIM): ax.errorbar(np.linspace(-.2,.2,len(y)), np.array(y).mean(axis=1),\ yerr=np.array(y).std(axis=1), marker='D', color='k') ax.plot(np.linspace(-.2, .2, len(x)), x, '-', color='lightgray', lw=3) if (ax == AX[-1, 0]): set_plot(ax, xticks=np.linspace(-.2,.2,len(x)), xlim=[-.3,.3],\ xlabel=EXP['label'], yticks=yticks, ylim=ylim, xticks_labels=[str(round(EXP['xticks'][i],2)) for i in range(N_POINTS)]) elif (ax == AX[-1, ii]): set_plot(ax, xticks=np.linspace(-.2,.2,len(x)), yticks_labels=[], xlim=[-.3,.3],\ xlabel=EXP['label'], yticks=yticks, ylim=ylim, xticks_labels=[str(round(EXP['xticks'][i],2)) for i in range(N_POINTS)]) elif ax in AX[:, 0]: set_plot(ax, xticks=np.linspace(-.2,.2,len(x)),\ xticks_labels=[], xlim=[-.3,.3], yticks=yticks, ylim=ylim) else: set_plot(ax, xticks=np.linspace(-.2,.2,len(x)), yticks_labels=[],\ xlim=[-.3,.3], xticks_labels=[], yticks=yticks, ylim=ylim) for ax, ylabel in zip( AX[:, 0], ['$\mu_V$ (mV)', '$\sigma_V$ (mV)', '$\\tau_V$ (ms)']): ax.set_ylabel(ylabel)
######## baseline activity ###################################################################### ## mean response -- HISTOGRAM y = np.log(NU) / np.log(10) ys = np.log(NUs) / np.log(10) yy = np.log(COUPLINGS[0, :][(1e-2 < COUPLINGS[0, :]) & (COUPLINGS[0, :] < 1e3)]) / np.log(10) AX[0, 0].hist(yy, bins=np.linspace(-2.5, 1.05, 9), color='lightgray', edgecolor='k', lw=2) AX[0, 0].plot([1.5], [0], 'wD', alpha=0, ms=0.01) set_plot(AX[0,0], ['left', 'bottom'], ylabel='cell #',\ xlabel='baseline activity \n'+r'$ \nu_\mathrm{bsl}$ (Hz)',\ xticks=[-1,0,1], yticks=[0,3,6], xlim=[-2.7,1.5],\ xticks_labels=['0.1', '1 ', '10']) ## -- CORRELATION WITH VTHRE cc, pp = pearsonr(VTHRE, y) lin_fit = np.polyfit(np.array(VTHRE, dtype='f8'), np.array(y, dtype='f8'), 1) plot_all(AX[0,1], VTHRE, y, lin_fit, VTHREs, ys,\ cc, pp, invert_axis=True) set_plot(AX[0,1], ['left', 'bottom'],\ ylabel=r'$ \nu_\mathrm{bsl}$ (Hz)',yticks=[-1,0,1],\ yticks_labels=['0.1', '1 ', '10'], xticks=[-40, -50, -60],\ xticks_labels=[]) ## -- CORRELATION WITH THE REST for X, Xs, ax, label in zip([DMUV, DTSV, DTV], [DMUVs, DTSVs, DTVs], AX[0, 2:], E_LABELS[1:]): cc, pp = pearsonr(X, y)
data['muGn'], data['Gl'], data['Cm'], data['El'], print_things=True) E = get_mean_encoding_power(P, data['El'], data['Gl'], data['Cm']) CELLS.append({'Gl':data['Gl'], 'Cm':data['Cm'],\ 'Tm':data['Cm']/data['Gl'], 'P':P, 'E':E}) OUTPUT[:4, i - 1] = P OUTPUT[4:, i - 1] = E print(data['Gl'], data['Cm']) np.save('reduced_data.npy', CELLS) return OUTPUT if __name__ == '__main__': import matplotlib.pylab as plt sys.path.append('../code') import my_graph as graph OUTPUT = produce_reduced_data() fig, AX = plt.subplots(1, 8, figsize=(15, 3)) # plt.subplots_adjust(bottom=.3) for i in range(8): AX[i].hist(OUTPUT[i, :]) graph.set_plot(AX[i], ylabel='cell #') if not sys.argv[-1] == 'noshow': plt.show()
def models(name, n=10, get_interpretation=False, get_legend=False,\ get_input_space=False, get_input_space2=False, get_title=False): if name=='typical_models': return ['LIF', 'EIF', 'sfaLIF', 'sbtaLIF', 'iLIF', 'iAdExp'] if name=='LIF_Vthre_models': # varying thresholds for LIF : params = get_model_params('LIF', {}) vthre = np.linspace(59, 35, n) if get_interpretation: return 'higher threshold' elif get_title: return r'LIF varying $V_\mathrm{thre}$' elif get_legend: return r'$V_\mathrm{thre}$ (mV)' elif get_input_space: return -vthre else: return ['LIF-Vthre-'+str(round(vv,2)) for vv in vthre] elif name=='LIF_Tref_models': # varying refractory period for LIF : tref = np.linspace(1e-4, 10, n) if get_interpretation: return 'longer refractory period' elif get_title: return r'LIF varying $\tau_\mathrm{ref}$' elif get_legend: return r'$\tau_\mathrm{ref}$ (ms)' else: return ['LIF-Tref-'+str(round(tt,1)) for tt in tref] elif name=='EIF_ka_models': # varying sharpness for EIF : dv = np.linspace(0., 3.5, n) if get_interpretation: return 'smoother Na activation' elif get_title: return r'EIF varying $k_\mathrm{a}$' elif get_legend: return r'$k_\mathrm{a}$ (mV)' elif get_input_space: return dv else: return ['EIF-ka-'+str(round(vv,1)) for vv in dv] elif name=='aEIF_Xa_models': # varying sharpness for EIF : XA = np.arange(1,n+1)*10 if get_interpretation: return 'further initiation' else: return ['aEIF-Xa-'+str(round(vv,1)) for vv in XA] elif name=='sfaLIF_b_models': # varying spike frequency adaptation for AdExp : B = np.linspace(0., 35., n) if get_interpretation: return 'stronger spike freq. adaptation' elif get_title: return r'sfaLIF varying $b$' elif get_input_space: return B elif get_legend: return r'$b$ (pA)' else: return ['sfaLIF-b-'+str(round(vv,1)) for vv in B] elif name=='iLIF_Ai_models': # varying the strength of spike frequency adaptation for AdExp : ai = np.linspace(0., 0.58, n) # actually ki / ka if get_interpretation: return 'stronger inactivation' elif get_title: return r'iLIF varying $a_i$' elif get_input_space: return ai elif get_legend: return r'$a_\mathrm{i}$' else: return ['iLIF-Ai-'+str(round(vv,1)) for vv in ai] elif name=='sbtaLIF_a_models': # varying spike frequency adaptation for AdExp : A = np.linspace(0., 7., n) if get_interpretation: return 'stronger subthresh. adaptation' elif get_legend: return r'$a$ (nS)' else: return ['sbtaLIF-a-'+str(round(vv,1)) for vv in A] elif name=='iAdExp_PC1_models': params = get_model_params('iAdExp', {}) Vthre = np.concatenate([[59.], np.linspace(59., 47., n-1)]) Ka = np.linspace(0., 3.5, n) Ai = np.linspace(.58, 0., n) # actually ki / ka B = np.linspace(0, 25., n) if get_interpretation: import matplotlib.pylab as plt import sys sys.path.append('/home/yann/work/python_library/') from my_graph import set_plot fig, AXX = plt.subplots(4, figsize=(5,5)) for axx, X, ylabel in zip(AXX, [-Vthre, Ka, Ai, B],\ [r'$V_\mathrm{thre}$(mV)', r'$k_a$(mV)',\ r'$a_i$', r'$b$(pA)']): axx.plot(range(len(X)), X, 'kD-', ms=5) axx.plot([len(X)-1], X[-1], 'bD', [0], X[0], 'rD', ms=6) set_plot(axx, ylabel=ylabel, xticks=[], num_yticks=3,\ xlim_enhancment=7, ylim_enhancment=7) return fig elif get_legend: return 'params comodulation' elif get_title: return r'iAdExp' elif get_input_space: return np.linspace(0, 1, n) elif get_input_space2: return -Vthre, Ka, Ai, B else: return ['iAdExp-Vthre-'+str(round(Vthre[i],2))+\ '-Ka-'+str(round(Ka[i],2))+'-Ai-'+str(round(Ai[i],2))+\ '-B-'+str(round(B[i],2)) for i in range(len(Vthre))] elif name=='iAdExp_5D_models': params = get_model_params('iAdExp', {}) n = 7 # more is impossible !! Vthre = np.linspace(-2,12,n)-1e3*params['vthresh'] Ka = np.linspace(0., 3.7, n) Ai = np.linspace(0., 0.7, n) # actually ki / ka B = np.linspace(0., 40., n) A = np.linspace(0., 7., n) Vthre, Ka, Ai, B, A = np.meshgrid(Vthre, Ka, Ai, B, A) Vthre, Ka, Ai, B, A = Vthre.flatten(), Ka.flatten(), Ai.flatten(), B.flatten(), A.flatten() if get_input_space: return Vthre, Ka, Ai, B, A else: return ['iAdExp-Vthre-'+str(Vthre[i])+\ '-Ka-'+str(Ka[i])+'-Ai-'+str(Ai[i])+\ '-B-'+str(B[i])+\ '-A-'+str(A[i]) for i in range(len(Vthre))] elif name=='iAdExp_4D_models': params = get_model_params('iAdExp', {}) n = 7 # more is impossible !! Vthre = np.linspace(-2,12,n)-1e3*params['vthresh'] Ka = np.linspace(0., 3., n) Ai = np.linspace(0., 3., n) # actually ki / ka B = np.linspace(0., 40., n) Vthre, Ka, Ai, B = np.meshgrid(Vthre, Ka, Ai, B) Vthre, Ka, Ai, B = Vthre.flatten(), Ka.flatten(), Ai.flatten(), B.flatten() if get_input_space: return Vthre, Ka, Ai, B else: return ['iAdExp-Vthre-'+str(Vthre[i])+\ '-Ka-'+str(Ka[i])+'-Ai-'+str(Ai[i])+\ '-B-'+str(B[i]) for i in range(len(Vthre))] elif name=='all_models': return all_models else: return None
def make_fig(args): NEURONS, PROTOCOLS = list(args.NEURONS), args.PROTOCOLS COLORS, SEEDS = args.COLORS, args.SEEDS t = np.arange(int(args.tstop / args.dt) - 1) * args.dt # time array fig1, AX1 = plt.subplots(4, len(PROTOCOLS), figsize=(4. * len(PROTOCOLS), 10)) fig2, AX2 = plt.subplots(4, len(PROTOCOLS), figsize=(4. * len(PROTOCOLS), 10)) fig3, AX3 = plt.subplots(len(NEURONS), len(PROTOCOLS), figsize=(4. * len(PROTOCOLS), 3 * len(NEURONS))) [FEG, FIG, FEI, FII, MUV, SV, TVN, MUGN] = [np.zeros((len(PROTOCOLS), 2, len(t))) for i in range(8)] FOUT = np.zeros((len(NEURONS), len(PROTOCOLS), 2, len(t))) for ip in range(len(PROTOCOLS)): for i_nrn in range(len(NEURONS)): FEG[ip, 0, :], FIG[ip, 0, :], FEI[ip, 0, :], FII[ip, 0, :],\ MUV[ip, 0, :], SV[ip, 0, :], TVN[ip, 0, :], MUGN[ip, 0, :],\ FOUT[i_nrn, ip, 0, :] = \ run_single_experiment(t, int(NEURONS[i_nrn]),\ args, exp_type='non specific activity', seed=SEEDS[ip]) FEG[ip, 1, :], FIG[ip, 1, :], FEI[ip, 1, :], FII[ip, 1, :],\ MUV[ip, 1, :], SV[ip, 1, :], TVN[ip, 1, :], MUGN[ip, 1, :],\ FOUT[i_nrn, ip, 1, :] = \ run_single_experiment(t, int(NEURONS[i_nrn]),\ args, exp_type=PROTOCOLS[ip], seed=SEEDS[ip]) ### PLOTTING ALL for ip, color in zip(list(range(len(PROTOCOLS))), COLORS): # membrane potential quantities for j, x in zip(list(range(4)), [1e3*MUV[ip,1,:], 1e3*SV[ip,1,:],\ 1e2*TVN[ip,1,:], MUGN[ip,1,:]]): AX1[j, ip].plot(t, x, color=color, lw=3, label=PROTOCOLS[ip]) for j, x in zip(list(range(4)), [1e3*MUV[ip,0,:], 1e3*SV[ip,0,:],\ 1e2*TVN[ip,0,:], MUGN[ip,0,:]]): AX1[j, ip].plot(t, x, 'k-', lw=1, label='non specific activity') # presynaptic activity for j, x in zip( list(range(4)), [FEG[ip, 1, :], FIG[ip, 1, :], FEI[ip, 1, :], FII[ip, 1, :]]): AX2[j, ip].plot(t, x, color=color, lw=3, label=PROTOCOLS[ip]) for j, x in zip( list(range(4)), [FEG[ip, 0, :], FIG[ip, 0, :], FEI[ip, 0, :], FII[ip, 0, :]]): AX2[j, ip].plot(t, x, 'k-', lw=1, label='non specific activity') # then output firing for i_nrn in range(len(NEURONS)): AX3[i_nrn, ip].plot(t, FOUT[i_nrn, ip, 0, :], 'k-', lw=1, label='non specific activity') AX3[i_nrn, ip].plot(t, FOUT[i_nrn, ip, 1, :], color=color, lw=3, label=PROTOCOLS[ip]) # THEN LIMITS for ip in range(len(PROTOCOLS)): for j, x in zip(list(range(4)), [FEG, FIG, FEI, FII]): AX2[j, ip].plot([0, 0], [x.min(), x.max()], color='w', alpha=0) for j, x in zip(list(range(4)), [1e3*MUV, 1e3*SV,\ 1e2*TVN, MUGN]): AX1[j, ip].plot([0, 0], [x.min(), x.max()], color='w', alpha=0) # then labels YLABELS1 = [ '$\mu_V$ (mV)', '$\sigma$ (mV)', '$\\tau_V / \\tau_m^0$ (%)', '$\mu_G / g_L$' ] YLABELS2 = [r'$\nu_e^\mathrm{prox}$ (Hz)', r'$\nu_i^\mathrm{prox}$ (Hz)',\ r'$\nu_e^\mathrm{dist}$ (Hz)', r'$\nu_i^\mathrm{dist}$ (Hz)'] for AX, YLABELS in zip([AX1, AX2], [YLABELS1, YLABELS2]): for i in range(AX.shape[0]): for j in range(AX.shape[1]): if i == 0: AX[i, j].legend(bbox_to_anchor=(.8, 1.4), prop={'size': 'small'}) if j == 0 and i == AX.shape[1] - 1: set_plot(AX[i, j], ylabel=YLABELS[i], xlabel='time (s)') elif j == 0: set_plot(AX[i, j], ylabel=YLABELS[i], xlabel='time (s)') elif i == AX.shape[0] - 1: set_plot(AX[i, j], xlabel='time (s)') else: set_plot(AX[i, j]) NEURONS[:4] = ['cell1', 'cell2', 'cell3', 'cell4'] # renaming cells ! for i in range(AX3.shape[0]): for j in range(AX3.shape[1]): if i == 0: AX3[i, j].legend(bbox_to_anchor=(.8, 1.4), prop={'size': 'small'}) if j == 0 and i == AX3.shape[1] - 1: set_plot(AX3[i, j], ylabel=r'$\nu_\mathrm{out}$ (Hz)', xlabel='time (s)') AX3[i, j].annotate(NEURONS[i], (-.4, .5), xycoords='axes fraction') elif j == 0: set_plot(AX3[i, j], ylabel=r'$\nu_\mathrm{out}$ (Hz)') AX3[i, j].annotate(NEURONS[i], (-.4, .5), xycoords='axes fraction') elif i == AX3.shape[0] - 1: set_plot(AX3[i, j], xlabel='time (s)') else: set_plot(AX3[i, j]) return fig1, fig2, fig3
psd = np.abs( get_the_input_impedance_at_soma(f, EqCylinder1, soma1, stick1, params1))**2 Tm_model[i] = .5 * psd[0] / ( 2. * np.trapz(np.abs(psd), f) ) # 2 times the integral to have from -infty to +infty (and methods gives [0,+infty]) Tm_data[i] = CELLS[i]['Cm'] / CELLS[i]['Gl'] print('---------------------------------------------------') print('Comparison between model and data for Tm') print('DATA, mean = ', 1e3 * Tm_data.mean(), 'ms +/-', 1e3 * Tm_data.std()) print('MODEL, mean = ', 1e3 * Tm_model.mean(), 'ms +/-', 1e3 * Tm_model.std()) print('---------------------------------------------------') fig, [ax, ax2] = plt.subplots(1, 2, figsize=(8, 3)) plt.subplots_adjust(bottom=.3, wspace=.4) # histogram ax.hist(1e3 * Tm_data, color='r', label='data') ax.hist(1e3 * Tm_model, color='b', label='model') ax.legend(frameon=False, prop={'size': 'x-small'}, loc='best') set_plot(ax, xlabel='membrane time constant (ms)', ylabel='cell #') # correl Rm-Tm ax2.plot(Rm_data, 1e3 * Tm_data, 'or', label='data') ax2.plot(Rm_data, 1e3 * Tm_model, 'ob', label='model') ax2.legend(prop={'size': 'xx-small'}, loc='best') set_plot(ax2, xlabel='membrane resistance (M$\Omega$)', ylabel='membrane time \n constant (ms)') plt.show()
[STD_MUV_EXP, STD_SV_EXP, STD_TV_EXP],\ [ALL_MUV_EXP, ALL_SV_EXP, ALL_TV_EXP]): for i in range(len(X)-1): if len(ALL[i])>1: Y[i] = np.mean(ALL[i]) sY[i] = np.std(ALL[i]) ax.errorbar(.5*(X[1:]+X[:-1])[Y!=0], Y[Y!=0], sY[Y!=0], color='k', lw=3, label='in vitro \n data') AX[0].plot([-70, -40], [-70, -40], '--', lw=1, color='k') AX[1].plot([0.5, 8], [0.5, 8], '--', lw=1, color='k') AX[2].plot([10, 100], [10, 100], '--', lw=1, color='k', label='desired') for ax, label, lim in zip(AX[:2], ['$\mu_V$', '$\sigma_V$'],\ [[-72,-38], [0.,9.]]): set_plot(ax, xlim=lim, ylim=lim,\ xlabel=label+' desired (mV)', ylabel=label+' observed (mV)') AX[2].legend(loc='best', frameon=False, prop={'size':'small'}) set_plot(AX[2], ylim=[0.,120.],\ xlabel='$\\tau_V^N$ desired (%)', ylabel='$\\tau_V^N$ observed (%)') #### Then theoretical models #### muV = np.linspace(-70, -50, n_bins) sV = np.linspace(0.5, 8, n_bins) TvN = np.linspace(10, 110, n_bins) for ii, model, color, label in zip(range(3),\ ['SUBTHRE', 'LIF', 'iAdExp'],\
sys.path.append('/home/yann/work/python_library/') import my_graph as graph data = np.loadtxt('sample.txt', unpack=True) t = data[0] - data[0][0] vm, I = data[1], data[3] fig, ax = plt.subplots(2, figsize=(4, 2)) plt.subplots_adjust(left=.22) ax[0].plot(t, I, 'k-') ax[0].plot([0, 1], [0, 0], 'k-', lw=4) ax[0].annotate('1s', (.1, .8), xycoords='axes fraction') graph.set_plot(ax[0], ['left'], ylabel='$I$ (pA)', xticks=[]) ax[1].plot(t, vm, 'k-') graph.set_plot(ax[1], ['left'], ylabel='$V_m$ (mV)', xticks=[]) from scipy.optimize import curve_fit # first episode t0 = t[t < 3.4] f1 = 0.584 sin1 = lambda t, phi, A, El: A * np.sin(2. * np.pi * f1 * t + phi) + El y = sin1(t0, 0., 4., -60) popt, pcov = curve_fit(sin1, t0, vm[:len(t0)]) ax[1].plot(t0, sin1(t0, *popt), 'r-') cond = (t > 4.8)
def demo_plot(P, dt=0.1e-3, tstop=1000e-3, I0=150e-12, fe=10., fi=10., vpeak=-30): t = np.arange(int(tstop / dt)) * dt fig = plt.figure(figsize=(10, 10)) ax11 = plt.subplot2grid((6, 2), (0, 0), rowspan=3) ax21 = plt.subplot2grid((6, 2), (3, 0)) ax31 = plt.subplot2grid((6, 2), (4, 0)) ax41 = plt.subplot2grid((6, 2), (5, 0)) ax12 = plt.subplot2grid((6, 2), (0, 1), rowspan=3) ax22 = plt.subplot2grid((6, 2), (3, 1)) ax32 = plt.subplot2grid((6, 2), (4, 1)) ax42 = plt.subplot2grid((6, 2), (5, 1)) I = np.array([I0 if ((tt > 200e-3) and (tt < 900e-3)) else 0 for tt in t]) v, spikes = sims.adexp_sim(t, I, 0. * I, 0. * I, *sims.pseq_adexp(P)) ax11.plot(1e3 * t, 1e3 * v, 'k-') for s in spikes: ax11.plot([1e3 * s, 1e3 * s], [1e3 * P['Vthre'], vpeak], 'k:') ax21.plot(1e3 * t, 1e12 * I, 'g-') ax31.plot(1e3 * t, 0 * I, 'r-') ax41.plot(1e3 * t, 0 * I, 'b-') fe, fi = 10, 10 Ge = sims.generate_conductance_shotnoise(fe, t, P['Ntot'] * (1 - P['gei']) * P['pconnec'], P['Qe'], P['Te'], g0=0, seed=0) Gi = sims.generate_conductance_shotnoise(fi, t, P['Ntot'] * P['gei'] * P['pconnec'], P['Qi'], P['Ti'], g0=0, seed=1) v, spikes = sims.adexp_sim(t, 0. * I, Ge, Gi, *sims.pseq_adexp(P)) ax12.plot(1e3 * t, 1e3 * v, 'k-') for s in spikes: ax12.plot([1e3 * s, 1e3 * s], [1e3 * P['Vthre'], vpeak], 'k:') ax22.plot(1e3 * t, 0 * I, 'g-') ax32.plot(1e3 * t, 1e9 * Ge, 'r-') ax42.plot(1e3 * t, 1e9 * Gi, 'b-') set_plot(ax12, ylabel='V (mV)', xticks_labels=[]) set_plot(ax22, ylabel='I (pA)', xticks_labels=[]) set_plot(ax32, ylabel='Ge (nS)', xticks_labels=[]) set_plot(ax42, ylabel='Gi (nS)', xlabel='time (ms)') set_plot(ax11, ylabel='V (mV)', xticks_labels=[]) set_plot(ax21, ylabel='I (pA)', xticks_labels=[]) set_plot(ax31, ylabel='Ge (nS)', xticks_labels=[]) set_plot(ax41, ylabel='Gi (nS)', xlabel='time (ms)') return fig
def draw_phase_space(args, T=5e-3): TF1, TF2 = load_transfer_functions(args.NRN1, args.NRN2, args.NTWK) ## now we compute the dynamical system ## X = [nu_e,nu_i] # T*d(nu_e)/dt = TF1(nu_e,nu_i) - n_e # T*d(nu_i)/dt = TF2(nu_e,nu_i) - n_i def dX_dt_scalar(X, t=0): return build_up_differential_operator_first_order(TF1, TF2, T=5e-3)( X, exc_aff=args.ext_drive) def dX_dt_mesh(IN, t=0): [x, y] = IN DFx = 0 * x DFy = 0 * y for inh in range(x.shape[0]): for exc in range(x.shape[1]): fe = x[inh][exc] fi = y[inh][exc] DFx[inh, exc] = (TF1(fe + args.ext_drive, fi) - fe) / T DFy[inh, exc] = (TF2(fe + args.ext_drive, fi) - fi) / T return DFx, DFy t = np.linspace(0, .04, 1e5) # time # values = np.array([[3,9],[4,9.5],[7.5,7],[5.5,4],[4,4]]) values = np.array([[2, 14], [6, 12], [1, 1], [5.5, 4], [10, 3]]) vcolors = plt.cm.gist_heat(np.linspace( 0, .8, len(values))) # colors for each trajectory ff1 = plt.figure(figsize=(5, 4)) f1 = plt.subplot(111) ff2 = plt.figure(figsize=(5, 4)) f2 = plt.subplot(111) # X_f0 = np.array([4.,4.]) # X_f1 = np.array([10.,10.]) # fixed points values #------------------------------------------------------- # plot trajectories for v, col in zip(range(len(values)), vcolors): X0 = values[v] # starting point X = integrate.odeint(dX_dt_scalar, X0, t) # we don't need infodict here l1 = f1.plot(1e3 * t, X[:, 0], '--', lw=2, color=col, label='excitation') l2 = f1.plot(1e3 * t, X[:, 1], '-', lw=2, color=col) f2.plot(X[:, 0], X[:, 1], lw=2, color=col, label='X0=(%.f, %.f)' % (X0[0], X0[1])) f1.legend(('exc. pop.', 'inh. pop.'), prop={'size': 'x-small'}) set_plot(f1, xlabel="time (ms)", ylabel="frequency (Hz)") ###### ============ VECTOR FIELD ============= ####### #------------------------------------------------------- # define a grid and compute direction at each point ymax = args.max_Fi ymin = 0 xmax = args.max_Fe xmin = 0 nb_points = 20 x = np.linspace(xmin, xmax, nb_points) y = np.linspace(ymin, ymax, nb_points) X1, Y1 = np.meshgrid(x, y) # create a grid DX1, DY1 = dX_dt_mesh([X1, Y1]) # compute growth rate on the gridt M = (np.hypot(DX1, DY1)) # Norm of the growth rate M[M == 0] = 1. # Avoid zero division errors M /= 1e3 # TO BE CHECKED -> Hz/ms DX1 /= M # Normalize each arrows DY1 /= M #------------------------------------------------------- # Drow direction fields, using matplotlib 's quiver function # I choose to plot normalized arrows and to use colors to give information on # the growth speed Q = plt.quiver(X1, Y1, DX1, DY1, M, pivot='mid', cmap=plt.cm.jet) cb = plt.colorbar(Q, cmap=plt.cm.jet, shrink=.5) cb.set_label('absolute speed (Hz/ms)') cb.set_ticks([0, 10, 20]) #cb.set_ticklabels([0,int(M.max()/2000),int(M.max()/1000)]) plt.plot([X[-1, 0]], [X[-1, 1]], 'ko', ms=10) plt.plot([X[-1, 0], X[-1, 0]], [0, X[-1, 1]], 'k--', lw=4, alpha=.4) plt.plot([0, X[-1, 0]], [X[-1, 1], X[-1, 1]], 'k--', lw=4, alpha=.4) set_plot(f2, xlabel='exc. pop. freq. (Hz)', ylabel='inh. pop. freq. (Hz)',\ xlim=[xmin, xmax], ylim=[ymin, ymax]) # plt.legend(loc='best') # plt.grid() # now fixed point print 'Fe=', X[-1, 0] print 'Fi=', X[-1, 1] plt.tight_layout() # ff2.savefig('figures/phase_space_with_fs.pdf', format='pdf') # ff1.savefig('figures/traject_with_fs.pdf', format='pdf') # ff2.savefig('figures/phase_space.pdf', format='pdf') # ff1.savefig('figures/traject.pdf', format='pdf') plt.show()
'b--', lw=2, label='signal B') AX[1, i].legend(frameon=False, loc='best', prop={'size': 'xx-small'}) iA = find_positive_phase_crossing(t, get_signal_phase(s_obs_A)) iB = find_positive_phase_crossing(t, get_signal_phase(s_lin_A)) AX[1, i].plot([t[iA], t[iA]], [0, get_signal_phase(s_obs_A)[iA]], 'r-', lw=1) AX[1, i].plot([t[iB], t[iB]], [0, get_signal_phase(s_lin_A)[iB]], 'b--', lw=1) AX[0, i].plot([t[iA], t[iA]], [0, s_obs_A[iA]], 'r-', lw=1) AX[0, i].plot([t[iB], t[iB]], [0, s_lin_A[iB]], 'b--', lw=1) AX[0, 0].set_title('zoom') AX[0, 0].set_xlim(zoom) AX[0, 1].set_title('full signal') if yann_computer: set_plot(AX[0, 1], xlabel='time (ms)', ylabel='VSD signal') set_plot(AX[1,1], xlabel='time (ms)', ylabel='phase $\phi(t)$ (Rd)',\ yticks=[-np.pi/2., 0, np.pi/2.],\ yticks_labels=['$-\pi$/2','0','$\pi$/2']) set_plot(AX[0, 0], xlabel='time (ms)', ylabel='VSD signal', xlim=zoom) set_plot(AX[1,0], xlabel='time (ms)', ylabel='phase $\phi(t)$ (Rd)',xlim=zoom,\ yticks=[-np.pi/2., 0, np.pi/2.],\ yticks_labels=['$-\pi$/2','0','$\pi$/2']) plt.show()
ax.fill_between(F, x.mean(axis=0)-x.std(axis=0),\ x.mean(axis=0)+x.std(axis=0), alpha=.2, color=COLORS[i]) else: for i in range(len(PROTOCOLS)): feG, fiG, feI, fiI, synch, muV, sV, TvN, muGn = get_fluct_var(i_nrn,\ exp_type=PROTOCOLS[i], len_f=len_f) for ax, x in zip(AX, [1e3 * muV, 1e3 * sV, 1e2 * TvN, muGn]): ax.plot(F, x, lw=3, color=COLORS[i], label=PROTOCOLS[i]) for ax, x in zip(AX2, [feG, fiG, feI, fiI, synch]): ax.plot(F, x, lw=3, color=COLORS[i], label=PROTOCOLS[i]) LABELS = ['$\mu_V$ (mV)', '$\sigma_V$ (mV)',\ '$\\tau_V / \\tau_m^0$ (%)', '$g_{tot}^{soma} / g_L$'] LABELS2 = ['$\\nu_e^{prox}$ (Hz)', '$\\nu_i^{prox}$ (Hz)',\ '$\\nu_e^{dist}$ (Hz)', '$\\nu_i^{dist}$ (Hz)', 'synchrony'] if sys.argv[-1] != 'all': AX[0].legend(prop={'size': 'xx-small'}, bbox_to_anchor=(1., 2.)) for ax, ylabel in zip(AX[:-1], LABELS[:-1]): set_plot(ax, ['left'], ylabel=ylabel, xticks=[]) for ax, ylabel in zip(AX2[:-1], LABELS2[:-1]): set_plot(ax, ['left'], ylabel=ylabel, xticks=[]) set_plot(AX[-1], ['bottom','left'],\ ylabel=LABELS[-1], xticks=[], xlabel='increasing \n presynaptic quantity') set_plot(AX2[-1], ['bottom','left'],\ ylabel=LABELS2[-1], xticks=[], xlabel='increasing \n presynaptic quantity') plt.show()
def plot_ntwk_sim_output(time_array, rate_array, rate_exc, rate_inh,\ Raster_exc, Raster_inh,\ Vm_exc, Vm_inh, Ge_exc, Ge_inh, Gi_exc, Gi_inh,\ zoom_conditions=None, bar_ms=40,\ raster_number=10000, vpeak=-10, BIN=5): if zoom_conditions is not None: z = zoom_conditions else: z = [time_array[0], time_array[-1]] cond_t = (time_array > z[0]) & (time_array < z[1]) Ne = Raster_inh[1].min() FIGS = [] # plotting FIGS.append(plt.figure(figsize=(4, 2))) cond = (Raster_exc[0] > z[0]) & (Raster_exc[0] < z[1]) & ( Raster_exc[1] > Ne - raster_number) plt.plot(Raster_exc[0][cond], Raster_exc[1][cond], '.g', ms=2) cond = (Raster_inh[0] > z[0]) & (Raster_inh[0] < z[1]) & ( Raster_inh[1] < Ne + .2 * raster_number) plt.plot(Raster_inh[0][cond], Raster_inh[1][cond], '.r', ms=2) plt.plot([z[0], z[0] + bar_ms], [Ne, Ne], 'k-', lw=5) plt.annotate(str(bar_ms) + 'ms', (z[0] + bar_ms, Ne)) set_plot(plt.gca(), ['left'], ylabel='Neuron index', xticks=[], yticks=[7700, 8000]) FIGS[-1].savefig('/Users/yzerlaut/Desktop/1.svg') FIGS.append(plt.figure(figsize=(4, 3))) ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2) ax2 = plt.subplot2grid((3, 1), (2, 0)) for i in range(len(Vm_exc)): ax1.plot(time_array[cond_t], Vm_exc[i][cond_t] - 5. * i, 'g-', lw=1) spk = np.where((Vm_exc[i][cond_t][:-1] > -50) & (Vm_exc[i][cond_t][1:] < -55))[0] for ispk in spk: ax1.plot(time_array[cond_t][ispk] * np.ones(2), [Vm_exc[i][cond_t][ispk] - 5. * i, vpeak - 5. * i], 'g--', lw=1) ax2.plot(time_array[cond_t], Ge_exc[i][cond_t], 'g-', lw=.5) ax2.plot(time_array[cond_t], Gi_exc[i][cond_t], 'r-', lw=.5) ax1.plot(time_array[cond_t][0] * np.ones(2), [-65, -55], lw=4, color='k') ax1.annotate('10mV', (time_array[cond_t][0], -65)) set_plot(ax1, [], xticks=[], yticks=[]) set_plot(ax2, ['left'], ylabel='$G$ (nS)', xticks=[], num_yticks=3) FIGS.append(plt.figure(figsize=(4, 3))) ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2) ax2 = plt.subplot2grid((3, 1), (2, 0)) for i in range(len(Vm_inh)): ax1.plot(time_array[cond_t], Vm_inh[i][cond_t] - 5. * i, 'r-', lw=1) spk = np.where((Vm_inh[i][cond_t][:-1] > -51) & (Vm_inh[i][cond_t][1:] < -55))[0] for ispk in spk: ax1.plot(time_array[cond_t][ispk] * np.ones(2), [Vm_inh[i][cond_t][ispk] - 5. * i, vpeak - 5. * i], 'r--', lw=1) ax2.plot(time_array[cond_t], Ge_inh[i][cond_t], 'g-', lw=.5) ax2.plot(time_array[cond_t], Gi_inh[i][cond_t], 'r-', lw=.5) ax1.plot(time_array[cond_t][0] * np.ones(2), [-65, -55], lw=4, color='k') ax1.annotate('10mV', (time_array[cond_t][0], -65)) set_plot(ax1, [], xticks=[], yticks=[]) set_plot(ax2, ['left'], ylabel='$G$ (nS)', xticks=[], num_yticks=3) fig, AX = plt.subplots(figsize=(4, 2)) # we bin the population rate rate_exc = bin_array(rate_exc[cond_t], BIN, time_array[cond_t]) rate_inh = bin_array(rate_inh[cond_t], BIN, time_array[cond_t]) rate_array = bin_array(rate_array[cond_t], BIN, time_array[cond_t]) time_array = bin_array(time_array[cond_t], BIN, time_array[cond_t]) AX.plot(time_array, rate_exc, 'g-', lw=1, label='$\\nu_e(t)$') AX.plot(time_array, rate_inh, 'r-', lw=1, label='$\\nu_i(t)$') AX.plot(time_array, .8 * rate_exc + .2 * rate_inh, 'k-', lw=1, label='$\\nu(t)$') AX.plot(time_array, rate_array, 'k--', lw=1, label='$\\nu_e^{aff}(t)$ \n $\\nu_e^{drive}$') AX.legend(prop={'size': 'xx-small'}) set_plot(AX, ['left'], ylabel='$\\nu$ (Hz)', xticks=[], num_yticks=3) FIGS.append(fig) # print('excitatory rate: ', rate_exc[len(rate_exc)/2:].mean(), 'Hz') # print('inhibitory rate: ', rate_inh[len(rate_exc)/2:].mean(), 'Hz') return AX, FIGS
ii = 1 for i_nrn in CHOOSED_CELLS: fig, ax = plt.subplots(figsize=(4, 3)) plt.subplots_adjust(left=.3, bottom=.3, wspace=.2, hspace=.2) print('cell : ', i_nrn + 1) ax.set_title('cell' + str(i_nrn + 1)) for protocol, c in zip(PROTOCOLS, COLORS[:5]): Fout = single_experiment(i_nrn, exp_type=protocol, len_f=len_f, precision=1e3) ax.plot(.5 * (F[1:] + F[:-1]), .5 * (Fout[1:] + Fout[:-1]), lw=4, color=c, label=protocol) if i_nrn == 0: ax.legend(frameon=False, prop={'size': 'xx-small'}) set_plot(ax, xlabel='increasing \n presynaptic quantity', ylabel='$\\nu_{out}$ (Hz)', xticks=[]) fig.savefig('data/cell' + str(i_nrn + 1) + '.svg') if len(CHOOSED_CELLS) < len(ALL_CELLS): FIG_LIST.append(fig) else: plt.clf() ii += 1 if sys.argv[-1] != 'all': put_list_of_figs_to_svg_fig(FIG_LIST)
def models(name, n=10, get_interpretation=False, get_legend=False,\ get_input_space=False, get_input_space2=False, get_title=False): if name == 'typical_models': return ['LIF', 'EIF', 'sfaLIF', 'sbtaLIF', 'iLIF', 'iAdExp'] if name == 'LIF_Vthre_models': # varying thresholds for LIF : params = get_model_params('LIF', {}) vthre = np.linspace(59, 35, n) if get_interpretation: return 'higher threshold' elif get_title: return r'LIF varying $V_\mathrm{thre}$' elif get_legend: return r'$V_\mathrm{thre}$ (mV)' elif get_input_space: return -vthre else: return ['LIF-Vthre-' + str(round(vv, 2)) for vv in vthre] elif name == 'LIF_Tref_models': # varying refractory period for LIF : tref = np.linspace(1e-4, 10, n) if get_interpretation: return 'longer refractory period' elif get_title: return r'LIF varying $\tau_\mathrm{ref}$' elif get_legend: return r'$\tau_\mathrm{ref}$ (ms)' else: return ['LIF-Tref-' + str(round(tt, 1)) for tt in tref] elif name == 'EIF_ka_models': # varying sharpness for EIF : dv = np.linspace(0., 3.5, n) if get_interpretation: return 'smoother Na activation' elif get_title: return r'EIF varying $k_\mathrm{a}$' elif get_legend: return r'$k_\mathrm{a}$ (mV)' elif get_input_space: return dv else: return ['EIF-ka-' + str(round(vv, 1)) for vv in dv] elif name == 'aEIF_Xa_models': # varying sharpness for EIF : XA = np.arange(1, n + 1) * 10 if get_interpretation: return 'further initiation' else: return ['aEIF-Xa-' + str(round(vv, 1)) for vv in XA] elif name == 'sfaLIF_b_models': # varying spike frequency adaptation for AdExp : B = np.linspace(0., 35., n) if get_interpretation: return 'stronger spike freq. adaptation' elif get_title: return r'sfaLIF varying $b$' elif get_input_space: return B elif get_legend: return r'$b$ (pA)' else: return ['sfaLIF-b-' + str(round(vv, 1)) for vv in B] elif name == 'iLIF_Ai_models': # varying the strength of spike frequency adaptation for AdExp : ai = np.linspace(0., 0.58, n) # actually ki / ka if get_interpretation: return 'stronger inactivation' elif get_title: return r'iLIF varying $a_i$' elif get_input_space: return ai elif get_legend: return r'$a_\mathrm{i}$' else: return ['iLIF-Ai-' + str(round(vv, 1)) for vv in ai] elif name == 'sbtaLIF_a_models': # varying spike frequency adaptation for AdExp : A = np.linspace(0., 7., n) if get_interpretation: return 'stronger subthresh. adaptation' elif get_legend: return r'$a$ (nS)' else: return ['sbtaLIF-a-' + str(round(vv, 1)) for vv in A] elif name == 'iAdExp_PC1_models': params = get_model_params('iAdExp', {}) Vthre = np.concatenate([[59.], np.linspace(59., 47., n - 1)]) Ka = np.linspace(0., 3.5, n) Ai = np.linspace(.58, 0., n) # actually ki / ka B = np.linspace(0, 25., n) if get_interpretation: import matplotlib.pylab as plt import sys sys.path.append('/home/yann/work/python_library/') from my_graph import set_plot fig, AXX = plt.subplots(4, figsize=(5, 5)) for axx, X, ylabel in zip(AXX, [-Vthre, Ka, Ai, B],\ [r'$V_\mathrm{thre}$(mV)', r'$k_a$(mV)',\ r'$a_i$', r'$b$(pA)']): axx.plot(list(range(len(X))), X, 'kD-', ms=5) axx.plot([len(X) - 1], X[-1], 'bD', [0], X[0], 'rD', ms=6) set_plot(axx, ylabel=ylabel, xticks=[], num_yticks=3,\ xlim_enhancment=7, ylim_enhancment=7) return fig elif get_legend: return 'params comodulation' elif get_title: return r'iAdExp' elif get_input_space: return np.linspace(0, 1, n) elif get_input_space2: return -Vthre, Ka, Ai, B else: return ['iAdExp-Vthre-'+str(round(Vthre[i],2))+\ '-Ka-'+str(round(Ka[i],2))+'-Ai-'+str(round(Ai[i],2))+\ '-B-'+str(round(B[i],2)) for i in range(len(Vthre))] elif name == 'iAdExp_5D_models': params = get_model_params('iAdExp', {}) n = 7 # more is impossible !! Vthre = np.linspace(-2, 12, n) - 1e3 * params['vthresh'] Ka = np.linspace(0., 3.7, n) Ai = np.linspace(0., 0.7, n) # actually ki / ka B = np.linspace(0., 40., n) A = np.linspace(0., 7., n) Vthre, Ka, Ai, B, A = np.meshgrid(Vthre, Ka, Ai, B, A) Vthre, Ka, Ai, B, A = Vthre.flatten(), Ka.flatten(), Ai.flatten( ), B.flatten(), A.flatten() if get_input_space: return Vthre, Ka, Ai, B, A else: return ['iAdExp-Vthre-'+str(Vthre[i])+\ '-Ka-'+str(Ka[i])+'-Ai-'+str(Ai[i])+\ '-B-'+str(B[i])+\ '-A-'+str(A[i]) for i in range(len(Vthre))] elif name == 'iAdExp_4D_models': params = get_model_params('iAdExp', {}) n = 7 # more is impossible !! Vthre = np.linspace(-2, 12, n) - 1e3 * params['vthresh'] Ka = np.linspace(0., 3., n) Ai = np.linspace(0., 3., n) # actually ki / ka B = np.linspace(0., 40., n) Vthre, Ka, Ai, B = np.meshgrid(Vthre, Ka, Ai, B) Vthre, Ka, Ai, B = Vthre.flatten(), Ka.flatten(), Ai.flatten( ), B.flatten() if get_input_space: return Vthre, Ka, Ai, B else: return ['iAdExp-Vthre-'+str(Vthre[i])+\ '-Ka-'+str(Ka[i])+'-Ai-'+str(Ai[i])+\ '-B-'+str(B[i]) for i in range(len(Vthre))] elif name == 'all_models': return all_models else: return None
def func(t): return double_gaussian(t, t0, T1, T2, amp0) t, fe, fi, muV, sV, muG, Tv = run_mean_field('RS-cell', 'FS-cell', 'CONFIG1', func, T=5e-3,\ ext_drive_change=amp, afferent_exc_fraction=None, extended_output=True, tstop=tstop) max_f_amp[i] = np.max(.8 * fe + .2 * fi) - .8 * fe[0] - .2 * fi[0] max_fe_amp[i] = np.max(fe) - fe[0] max_fi_amp[i] = np.max(fi) - fi[0] max_vm_amp[i] = np.max(1e2 * np.abs((muV - muV[0]) / muV[0])) ax1.plot(amplitudes, max_f_amp, 'k-', lw=3) # ax1.fill_between(amplitudes, max_f_amp, max_f_amp[0]+0*max_f_amp, color='lightgray') ax1.plot([0], [0], 'wD', ms=0.1) set_plot(ax1, ['left'], ylabel='max. $\delta \\nu$ (Hz)', xticks=[]) ax2.plot(amplitudes, max_vm_amp, 'k-', lw=3) ax2.plot([0], [0], 'wD', ms=0.1) ax2.fill_between(amplitudes, max_vm_amp, max_vm_amp[0] + 0 * max_vm_amp, color='lightgray') set_plot(ax2, ylabel=r'max. $\| \delta V/V_0 \| $ %', xlabel='$\\nu_e^{drive}$ (Hz)') plt.show() else: fig1, [ax1, ax2, ax3] = plt.subplots(3, figsize=(5, 6)) plt.subplots_adjust(left=.25, bottom=.25)
from scipy.io import loadmat import numpy as np import matplotlib.pylab as plt import sys sys.path.append('../code/') from my_graph import set_plot fig, AX = plt.subplots(2, 2) f = loadmat('Amp_4yann.mat') AX[0, 0].plot(1e3 * f['amp1_time']) AX[0, 0].set_title('Stim 1') set_plot(AX[0, 0], ['left'], ylabel=r'amp. ($\perthousand$)', xticks=[]) AX[0, 1].plot(1e3 * f['amp2_time']) AX[0, 1].set_title('Stim 2') set_plot(AX[0, 1], ['left'], ylabel=r'amp. ($\perthousand$)', xticks=[], ylim=[0, 1.8]) f = loadmat('sigma_4yann.mat') AX[1, 0].plot(f['sigma1_time']) set_plot(AX[1, 0], ylabel='$\sigma$ (mm)', xlabel='time (frames)') AX[1, 1].plot(f['sigma2_time']) set_plot(AX[1, 1], ylabel='$\sigma$ (mm)', xlabel='time (frames)') plt.show()
from theory.analytical_calculus import * from data_firing_response.analyze_data import get_Rm_range from input_impedance_calibration.get_calib import adjust_model_prop soma, stick, params = np.load('../input_impedance_calibration/mean_model.npy') Ls, Ds, l, D, lp, Rm, Cm,\ El, Ee, Ei, rm, cm, ri = ball_and_stick_params(soma, stick, params) Rm = get_Rm_range() Ke, Ki = 0*Rm, 0*Rm for i in range(len(Rm)): soma1, stick1, params1 = adjust_model_prop(Rm[i], soma, stick) xtot1, cables1 = setup_model(soma1, stick1, params1) Ke[i], Ki[i] = cables1[0]['Ke_tot'], cables1[0]['Ki_tot'] print('-----------------------------------------------------------------') print(('mean number of synapses: ', np.mean(Ke+Ki), '+/-', np.std(Ke+Ki))) print(('max number of synapses: ', np.max(Ke+Ki))) print(('min number of synapses: ', np.min(Ke+Ki))) print(('excitatory/inhibitory : ', np.mean(Ke/Ki), '+/-', np.std(Ke/Ki))) fig, ax = plt.subplots(1, 3, figsize=(10,3)) plt.subplots_adjust(bottom=.3) ax[0].hist(Ke, color='g');set_plot(ax[0], xlabel='exc. synapses', ylabel='cell #') ax[1].hist(Ki, color='r');set_plot(ax[1], xlabel='inh. synapses') ax[2].hist(np.array(Ke)/np.array(Ki), color='k');set_plot(ax[2], xlabel='ratio \n exc/inh #') plt.show()
def plot_ntwk_sim_output_for_waveform(args,\ BIN=5, min_time=200, bar_ms=50, zoom_conditions=None, vpeak=-35,\ raster_number=400): time_array, rate_array, rate_exc, rate_inh,\ Raster_exc, Raster_inh,\ Vm_exc, Vm_inh, Ge_exc, Ge_inh, Gi_exc, Gi_inh = np.load(args.file) if zoom_conditions is not None: z = zoom_conditions else: z = [time_array[0], time_array[-1]] cond_t = (time_array > z[0]) & (time_array < z[1]) ###### =========================================== ###### ############# adding the theoretical eval ############### ###### =========================================== ###### t0 = args.t0 - 4 * args.T1 def rate_func(t): return double_gaussian(t, 1e-3 * args.t0, 1e-3 * args.T1, 1e-3 * args.T2, args.amp) t, fe, fi, sfe, sfei, sfi = run_mean_field_extended(args.CONFIG.split('--')[0],\ args.CONFIG.split('--')[1],args.CONFIG.split('--')[2],\ rate_func,dt=5e-4, tstop=args.tstop*1e-3) params = get_neuron_params('RS-cell', SI_units=True) M = get_connectivity_and_synapses_matrix('CONFIG1', SI_units=True) reformat_syn_parameters(params, M) # merging those parameters ext_drive = M[0, 0]['ext_drive'] afferent_exc_fraction = M[0, 0]['afferent_exc_fraction'] fe_e, fe_i = fe + ext_drive + rate_func(t), fe + ext_drive muV_e, sV_e, muGn_e, TvN_e = get_fluct_regime_vars(fe_e, fi, *pseq_params(params)) muV_i, sV_i, muGn_i, TvN_i = get_fluct_regime_vars(fe_i, fi, *pseq_params(params)) Ne = Raster_inh[1].min() FIGS = [] # plotting FIGS.append(plt.figure(figsize=(5, 4))) cond = (Raster_exc[0] > z[0]) & (Raster_exc[0] < z[1]) & ( Raster_exc[1] > Ne - raster_number) plt.plot(Raster_exc[0][cond], Raster_exc[1][cond], '.g') cond = (Raster_inh[0] > z[0]) & (Raster_inh[0] < z[1]) & ( Raster_inh[1] < Ne + .2 * raster_number) plt.plot(Raster_inh[0][cond], Raster_inh[1][cond], '.r') plt.plot([z[0], z[0] + bar_ms], [Ne, Ne], 'k-', lw=5) plt.annotate(str(bar_ms) + 'ms', (z[0] + bar_ms, Ne)) set_plot(plt.gca(), ['left'], ylabel='Neuron index', xticks=[]) FIGS.append(plt.figure(figsize=(5, 5))) ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2) ax2 = plt.subplot2grid((3, 1), (2, 0)) for i in range(len(Vm_exc)): ax1.plot(time_array[cond_t], Vm_exc[i][cond_t], 'g-', lw=.5) spk = np.where((Vm_exc[i][cond_t][:-1] > -50) & (Vm_exc[i][cond_t][1:] < -55))[0] for ispk in spk: ax1.plot(time_array[cond_t][ispk] * np.ones(2), [Vm_exc[i][cond_t][ispk], vpeak], 'g--') ax2.plot(time_array[cond_t], Ge_exc[i][cond_t], 'g-', lw=.5) ax2.plot(time_array[cond_t], Gi_exc[i][cond_t], 'r-', lw=.5) # vm ax1.plot(1e3 * t[1e3 * t > t0], 1e3 * muV_e[1e3 * t > t0], 'g-', lw=2) ax1.fill_between(1e3*t[1e3*t>t0], 1e3*(muV_e[1e3*t>t0]-sV_e[1e3*t>t0]),\ 1e3*(muV_e[1e3*t>t0]+sV_e[1e3*t>t0]), color='g', alpha=.4) # ge ge_th = 1e9 * fe_e[1e3 * t > t0] * params['Qe'] * params['Te'] * ( 1 - params['gei']) * params['pconnec'] * params['Ntot'] sge_th = 1e9 * params['Qe'] * np.sqrt( fe_e[1e3 * t > t0] * params['Te'] * (1 - params['gei']) * params['pconnec'] * params['Ntot']) ax2.plot(1e3 * t[1e3 * t > t0], ge_th, 'g-', lw=2) ax2.fill_between(1e3 * t[1e3 * t > t0], ge_th - sge_th, ge_th + sge_th, color='g', alpha=.4) gi_th = 1e9 * fi[1e3 * t > t0] * params['Qi'] * params['Ti'] * params[ 'gei'] * params['pconnec'] * params['Ntot'] sgi_th = 1e9 * params['Qi'] * np.sqrt( fi[1e3 * t > t0] * params['Ti'] * params['gei'] * params['pconnec'] * params['Ntot']) ax2.plot(1e3 * t[1e3 * t > t0], gi_th, 'r-', lw=2) ax2.fill_between(1e3 * t[1e3 * t > t0], gi_th - sgi_th, gi_th + sgi_th, color='r', alpha=.4) ax1.plot(time_array[cond_t][0] * np.ones(2), [-65, -55], lw=4, color='k') ax1.annotate('10mV', (time_array[cond_t][0], -65)) set_plot(ax1, [], xticks=[], yticks=[]) set_plot(ax2, ['left'], ylabel='$G$ (nS)', xticks=[]) FIGS.append(plt.figure(figsize=(5, 5))) ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2) ax2 = plt.subplot2grid((3, 1), (2, 0)) for i in range(len(Vm_inh)): ax1.plot(time_array[cond_t], Vm_inh[i][cond_t], 'r-', lw=.5) spk = np.where((Vm_inh[i][cond_t][:-1] > -51) & (Vm_inh[i][cond_t][1:] < -55))[0] for ispk in spk: ax1.plot(time_array[cond_t][ispk] * np.ones(2), [Vm_inh[i][cond_t][ispk], vpeak], 'r--') ax2.plot(time_array[cond_t], Ge_inh[i][cond_t], 'g-', lw=.5) ax2.plot(time_array[cond_t], Gi_inh[i][cond_t], 'r-', lw=.5) # vm ax1.plot(1e3 * t[1e3 * t > t0], 1e3 * muV_i[1e3 * t > t0], 'r-', lw=2) ax1.fill_between(1e3*t[1e3*t>t0], 1e3*(muV_i[1e3*t>t0]-sV_i[1e3*t>t0]),\ 1e3*(muV_i[1e3*t>t0]+sV_i[1e3*t>t0]), color='r', alpha=.4) ge_th = 1e9 * fe_i[1e3 * t > t0] * params['Qe'] * params['Te'] * ( 1 - params['gei']) * params['pconnec'] * params['Ntot'] sge_th = 1e9 * params['Qe'] * np.sqrt( fe_i[1e3 * t > t0] * params['Te'] * (1 - params['gei']) * params['pconnec'] * params['Ntot']) ax2.plot(1e3 * t[1e3 * t > t0], ge_th, 'g-', lw=2) ax2.fill_between(1e3 * t[1e3 * t > t0], ge_th - sge_th, ge_th + sge_th, color='g', alpha=.4) ax2.plot(1e3 * t[1e3 * t > t0], gi_th, 'r-', lw=2) ax2.fill_between(1e3 * t[1e3 * t > t0], gi_th - sgi_th, gi_th + sgi_th, color='r', alpha=.4) ax1.plot(time_array[cond_t][0] * np.ones(2), [-65, -55], lw=4, color='k') ax1.annotate('10mV', (time_array[cond_t][0], -65)) set_plot(ax1, [], xticks=[], yticks=[]) set_plot(ax2, ['left'], ylabel='$G$ (nS)', xticks=[]) fig, AX = plt.subplots(figsize=(5, 3)) # we bin the population rate rate_exc = bin_array(rate_exc[cond_t], BIN, time_array[cond_t]) rate_inh = bin_array(rate_inh[cond_t], BIN, time_array[cond_t]) rate_array = bin_array(rate_array[cond_t], BIN, time_array[cond_t]) time_array = bin_array(time_array[cond_t], BIN, time_array[cond_t]) AX.plot(time_array, rate_exc, 'g-', lw=2, label='$\\nu_e(t)$') AX.plot(time_array, rate_inh, 'r-', lw=2, label='$\\nu_i(t)$') AX.plot(time_array, .8 * rate_exc + .2 * rate_inh, 'k-', lw=2, label='$\\nu(t)$') AX.plot(1e3*t[1e3*t>t0], rate_func(t[1e3*t>t0]), 'k:',\ lw=2, label='$\\nu_e^{aff}(t)$ \n $\\nu_e^{drive}$') AX.plot(1e3 * t[1e3 * t > t0], fe[1e3 * t > t0], 'g-', label='mean field \n pred.') AX.fill_between(1e3*t[1e3*t>t0], fe[1e3*t>t0]-sfe[1e3*t>t0], fe[1e3*t>t0]+sfe[1e3*t>t0],\ color='g', alpha=.3, label='mean field \n pred.') AX.plot(1e3 * t[1e3 * t > t0], fi[1e3 * t > t0], 'r-', label='num. sim.') AX.fill_between(1e3*t[1e3*t>t0], fi[1e3*t>t0]-sfi[1e3*t>t0], fi[1e3*t>t0]+sfi[1e3*t>t0],\ color='r', alpha=.3) # AX.plot(1e3*t[1e3*t>t0], .8*fe[1e3*t>t0]+.2*fi[1e3*t>t0], 'k-', label='..') AX.legend(prop={'size': 'xx-small'}) set_plot(AX, ['left'], ylabel='$\\nu$ (Hz)', xticks=[], num_yticks=3) FIGS.append(fig) print('excitatory rate: ', rate_exc[len(rate_exc) / 2:].mean(), 'Hz') print('inhibitory rate: ', rate_inh[len(rate_exc) / 2:].mean(), 'Hz') print(sfe[0], sfe[-1]) return FIGS
lw=3, label='$\\nu(t)$') ax1.plot(amplitudes - amplitudes[0], max_f_amp_e, 'g-', label='$\\nu_e(t)$') ax1.plot(amplitudes - amplitudes[0], max_f_amp_i, 'r-', label='$\\nu_i(t)$') ax1.legend() # ax1.plot(amplitudes-amplitudes[0], max_f_amp2, 'r--', lw=3) # pol = np.polyfit(amplitudes[:3], max_f_amp[:3], 1) # ax1.plot(amplitudes[:int(2*N/3.)], np.polyval(pol, amplitudes[:int(2*N/3.)]), 'k--') set_plot(ax1, ['left'], ylabel='max. $\delta \\nu$ (Hz)', xticks=[], yticks=[0, 30, 60]) ax2.plot(amplitudes, max_vm_amp, 'k-', lw=3) pol = np.polyfit(amplitudes[:3], max_vm_amp[:3], 1) ax2.plot(amplitudes[:int(2 * N / 3.)], np.polyval(pol, amplitudes[:int(2 * N / 3.)]), 'k--') set_plot(ax2, ylabel=r'max. $\| \delta V/V_0 \| $ %', xlabel='$\\nu_{e, \, max}^{aff}$ (Hz)', yticks=[0, 15, 30]) plt.show() else: fig1, [ax1, ax2, ax3] = plt.subplots(3, figsize=(5, 6)) plt.subplots_adjust(left=.25, bottom=.25)
def correlating_electrophy_and_coupling(COUPLINGS, BIOPHYSICS, scale='lin'): """ plot of the correlation function""" ############################################################################### PROTOCOLS = [ 'unbalanced activity', 'proximal activity', 'distal activity', 'synchrony' ] YLABELS1 = [r"mean response level \\n $\langle \nu_\mathrm{out}\rangle$ (Hz)"]+\ ['change of gain (Hz$^{-1}$) \n for increasing \n '+p for p in PROTOCOLS] E_LABELS = [r"$\langle V_\mathrm{thre}^\mathrm{eff} \rangle_\mathcal{D}$ (mV)",\ r"$\langle \partial \nu / \partial \mu_V \rangle_\mathcal{D}$ (Hz/mV)",\ r"$\langle \partial \nu / \partial \sigma_V \rangle_\mathcal{D}$ (Hz/mV)",\ r"$\langle \partial \nu / \partial \tau_V^{N} \rangle_\mathcal{D}$ (Hz/%)"] X = [BIOPHYSICS[i, :] for i in range(BIOPHYSICS.shape[0])] Y = [COUPLINGS[i, :] for i in range(COUPLINGS.shape[0])] INDEXES, MARKER, SIZE = [21, 2, 27, 1], ['^', 'd', '*', 's'], [12, 11, 17, 10] fig, AX = plt.subplots(len(Y), len(X), figsize=(20, 30)) fig.subplots_adjust(wspace=.6, hspace=1.) for i in range(len(X)): for j in range(len(Y)): # for k in range(len(MARKER)): # if scale=='log' and (Y[j][INDEXES[k]])>0: # AX[j, i].plot([X[i][INDEXES[k]]], [np.log(Y[j][INDEXES[k]])/np.log(10)],\ # lw=0, color='lightgray', marker=MARKER[k], # label='cell '+str(k), ms=SIZE[k]) # else: # AX[j, i].plot([X[i][INDEXES[k]]], [Y[j][INDEXES[k]]],\ # lw=0, color='lightgray', marker=MARKER[k], # label='cell '+str(k), ms=SIZE[k]) cond = (Y[j] != 0) & (np.abs(Y[j]) < 1e4) & (np.abs(Y[j]) > 1e-2) xx, y = np.array(X[i][cond]), np.array(Y[j][cond]) if scale == 'log': y = np.log(y) / np.log(10) cc, pp = pearsonr(xx, y) x = np.linspace(xx.min(), xx.max()) yy = np.polyval( np.polyfit(np.array(xx, dtype='f8'), np.array(y, dtype='f8'), 1), x) else: cc, pp = pearsonr(xx, y) x = np.linspace(xx.min(), xx.max()) yy = np.polyval( np.polyfit(np.array(xx, dtype='f8'), np.array(y, dtype='f8'), 1), x) AX[j, i].plot(x, yy, 'k--', lw=.5) AX[j, i].plot(xx, y, 'ko') AX[j, i].annotate('c='+str(np.round(cc,1))+', p='+'%.1e' % pp,\ (0.15,1), xycoords='axes fraction') if i in [0, 3]: AX[j, i].invert_xaxis() if scale == 'log': set_plot(AX[j, i], ['left', 'bottom'],\ ylabel=YLABELS1[j],xlabel=E_LABELS[i],\ yticks=[-1,0,1,2],\ yticks_labels=['$10^{-1}$', '1', '$10^{1}$', '$10^{2}$']) else: set_plot(AX[j, i], ['left', 'bottom'], ylabel=YLABELS1[j], xlabel=E_LABELS[i]) return fig
print('------------- NEURON model :', model) print(eqs) # V value initialization neurons.V = -65.*mV trace = StateMonitor(neurons, 'V', record=0) spikes = SpikeMonitor(neurons) run(100 * ms) neurons.I0 = 200*pA run(400 * ms) neurons.I0 = 0*pA run(200 * ms) # We draw nicer spikes V = trace[0].V[:] for t in spikes.t: plt.plot(t/ms*np.ones(2), [V[int(t/defaultclock.dt)]/mV+2,-10], '--', color=c) ax.plot(trace.t / ms, V / mV, color=c) ax.set_title(model) set_plot(ax, []) ax.annotate('-65mV', (20,-70)) ax.plot([50], [-65], 'k>') ax.plot([100,150], [-50, -50], 'k-', lw=4) ax.plot([100,100], [-50, -40], 'k-', lw=4) ax.annotate('10mV', (200,-40)) ax.annotate('50ms', (200,-50)) show()
def make_experimental_fig(): fig, AX = plt.subplots(1, 2, figsize=(11, 4)) plt.subplots_adjust(bottom=.25) MICE, RATS = [], [] psd_boundaries = [200, 900] all_freq, all_psd, all_phase = [np.empty(0, dtype=float) for i in range(3)] HIGH_BOUND = 450 # higher nound for frequency for file in os.listdir("./intracellular_data/"): if file.endswith("_rat.txt"): _ = 0 elif file.endswith(".txt"): freq, psd, phase = np.loadtxt("./intracellular_data/" + file, unpack=True) MICE.append({ 'freq': freq[np.argsort(freq)], 'psd': psd[np.argsort(freq)], 'phase': (phase[np.argsort(freq)] % (2. * np.pi) + np.pi / 2.) % (2. * np.pi) - np.pi / 2. }) # print file, MICE[-1]['phase'].max() all_freq = np.concatenate([all_freq, MICE[-1]['freq']]) all_psd = np.concatenate([all_psd, MICE[-1]['psd']]) all_phase = np.concatenate([all_phase, MICE[-1]['phase']]) psd_boundaries[0] = min([psd_boundaries[0], psd.max()]) psd_boundaries[1] = max([psd_boundaries[1], psd.max()]) np.save('full_data.npy',\ [all_freq[all_freq<HIGH_BOUND], all_psd[all_freq<HIGH_BOUND], all_phase[all_freq<HIGH_BOUND]]) all_freq, all_psd, all_phase = np.load('full_data.npy') mymap = graph.get_linear_colormap() X = 300 + np.arange(3) * 300 for m in MICE: rm = m['psd'][:3].mean() r = (rm - psd_boundaries[0]) / (psd_boundaries[1] - psd_boundaries[0]) AX[0].loglog(m['freq'][m['freq'] < HIGH_BOUND], m['psd'][m['freq'] < HIGH_BOUND], 'D-', color=mymap(r, 1), ms=4) AX[1].semilogx(m['freq'][m['freq'] < HIGH_BOUND], m['phase'][m['freq'] < HIGH_BOUND], 'D-', color=mymap(r, 1), ms=4) AX[0].annotate('n=' + str(len(MICE)) + ' cells', (.2, .2), xycoords='axes fraction', fontsize=18) ax2 = fig.add_axes([0.59, 0.7, 0.015, 0.18]) cb = graph.build_bar_legend(X, ax2, mymap, scale='linear', color_discretization=100,\ bounds=psd_boundaries, label=r'$R_\mathrm{m}$ ($\mathrm{M}\Omega$)') graph.set_plot(AX[0], xlim=[.08,1000], ylim=[6., 1200],\ xticks=[1,10,100,1000], yticks=[10,100,1000],yticks_labels=['10','100','1000'],\ xlabel='frequency (Hz)',ylabel='input impedance ($\mathrm{M}\Omega$)') graph.set_plot(AX[1], xlim=[.08,1000], ylim=[-.2,2.3],\ xticks=[1,10,100,1000], yticks=[0,np.pi/4.,np.pi/2.],\ yticks_labels=[0,'$\pi/4$', '$\pi/2$'], xlabel='frequency (Hz)', ylabel='phase shift (Rd)')
print("===----", p['name'], "-----===========") print("==============================================") pprint.pprint(p) else: p = get_model_params(sys.argv[-1]) print("==============================================") print("===----", p['name'], "-----===========") print("==============================================") pprint.pprint(p) import matplotlib.pylab as plt sys.path.append('../code') from my_graph import set_plot fig, ax = plt.subplots(1) plt.subplots_adjust(left=.3, bottom=.3, top=.8) x = np.linspace(-p['X_extent'] / 2., p['X_extent'] / 2., 1e3) ax.plot(x, gaussian_connectivity(x, 0., p['inh_connect_extent']), 'r-', lw=3, label='inhibition') ax.plot(x, gaussian_connectivity(x, 0., p['exc_connect_extent']), 'b-', lw=3, label='excitation') ax.set_title('connectivity \n profile') ax.legend(frameon=False) set_plot(ax, ylabel='connectivity probability',\ xlabel='distance from center pixel (mm)') plt.show()
SIGMA.append(res.x[1]) return np.array(XX), np.array(T1), np.array(T2), np.array(TT), np.array( AMP), np.array(SIGMA) if __name__ == '__main__': args, t, X, Fe_aff, Fe, Fi, muVn = np.load('data/example_data.npy') XX, T1, T2, TT, AMP, SIGMA = \ get_mean_extent_and_temporal_quant(t, X, muVn) fig, AX = plt.subplots(2, 2) plt.subplots_adjust(bottom=.2, wspace=.4) AX[0, 0].set_title('Spatial profile in time \n') AX[0, 0].plot(1e3 * TT, 1e2 * AMP, 'k-', lw=2) set_plot(AX[0, 0], ['left'], ylabel=r'amp. %', xticks=[]) AX[1, 0].plot(1e3 * TT, SIGMA, 'k-', lw=2) set_plot(AX[1, 0], ylabel='$\sigma$ (mm)', xlabel='time (ms)') AX[0, 1].set_title('Temporal profile in space \n') AX[0, 1].plot(XX, 1e3 * T1, 'k-', lw=2) set_plot(AX[0, 1], ['left'], ylabel='$\\tau_1$ (ms)', xticks=[]) AX[1, 1].plot(XX, 1e3 * T2, 'k-', lw=2) set_plot(AX[1, 1], ylabel='$\\tau_2$ (ms)', xlabel='space (mm)') fig.savefig('fig.svg') plt.show()