コード例 #1
0
ファイル: figure_09.py プロジェクト: pablomc88/hybridLFPy
def fig_lfp_decomposition(fig,
                          axes,
                          params,
                          transient=200,
                          X=['L23E', 'L6E'],
                          show_xlabels=True):
    # ana_params.set_PLOS_2column_fig_style(ratio=0.5)
    # fig, axes = plt.subplots(1,5)
    # fig.subplots_adjust(left=0.06, right=0.96, wspace=0.4, hspace=0.2)

    if analysis_params.bw:
        # linestyles = ['-', '-', '--', '--', '-.', '-.', ':', ':']
        linestyles = ['-', '-', '-', '-', '-', '-', '-', '-']
        markerstyles = ['s', 's', 'v', 'v', 'o', 'o', '^', '^']
    else:
        if plt.matplotlib.__version__ == '1.5.x':
            linestyles = ['-', ':'] * (len(params.Y) / 2)
            print(
                'CSD variance semi log plots may fail with matplotlib.__version__ {}'
                .format(plt.matplotlib.__version__))
        else:
            linestyles = ['-',
                          (0, (1, 1))] * (len(params.Y) / 2)  #cercor version
        # markerstyles = ['s', 's', 'v', 'v', 'o', 'o', '^', '^']
        markerstyles = [None] * len(params.Y)
        linewidths = [1.25 for i in range(len(linestyles))]

    plt.delaxes(axes[0])

    #population plot
    axes[0] = fig.add_subplot(261)
    axes[0].xaxis.set_ticks([])
    axes[0].yaxis.set_ticks([])
    axes[0].set_frame_on(False)
    plot_population(axes[0],
                    params,
                    aspect='tight',
                    isometricangle=np.pi / 32,
                    plot_somas=False,
                    plot_morphos=True,
                    num_unitsE=1,
                    num_unitsI=1,
                    clip_dendrites=False,
                    main_pops=True,
                    rasterized=False)
    phlp.annotate_subplot(axes[0], ncols=5, nrows=1, letter='A')
    axes[0].set_aspect('auto')
    axes[0].set_ylim(-1550, 50)
    axis = axes[0].axis()

    phlp.remove_axis_junk(axes[1])
    plot_signal_sum(axes[1],
                    params,
                    fname=os.path.join(params.populations_path,
                                       X[0] + '_population_LFP.h5'),
                    unit='mV',
                    T=[800, 1000],
                    ylim=[axis[2], axis[3]],
                    rasterized=False)

    # CSD background colorplot
    im = plot_signal_sum_colorplot(
        axes[1],
        params,
        os.path.join(params.populations_path, X[0] + '_population_CSD.h5'),
        unit=r'$\mu$Amm$^{-3}$',
        T=[800, 1000],
        colorbar=False,
        ylim=[axis[2], axis[3]],
        fancy=False,
        cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap(
            'bwr_r', 21),
        rasterized=False)

    cb = phlp.colorbar(fig,
                       axes[1],
                       im,
                       width=0.05,
                       height=0.5,
                       hoffset=-0.05,
                       voffset=0.5)
    cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)

    axes[1].set_ylim(-1550, 50)
    axes[1].set_title('LFP and CSD ({})'.format(X[0]), va='baseline')
    phlp.annotate_subplot(axes[1], ncols=3, nrows=1, letter='B')

    #quickfix on first axes
    axes[0].set_ylim(-1550, 50)
    if show_xlabels:
        axes[1].set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        axes[1].set_xlabel('')

    phlp.remove_axis_junk(axes[2])
    plot_signal_sum(axes[2],
                    params,
                    fname=os.path.join(params.populations_path,
                                       X[1] + '_population_LFP.h5'),
                    ylabels=False,
                    unit='mV',
                    T=[800, 1000],
                    ylim=[axis[2], axis[3]],
                    rasterized=False)

    # CSD background colorplot
    im = plot_signal_sum_colorplot(
        axes[2],
        params,
        os.path.join(params.populations_path, X[1] + '_population_CSD.h5'),
        unit=r'$\mu$Amm$^{-3}$',
        T=[800, 1000],
        ylabels=False,
        colorbar=False,
        ylim=[axis[2], axis[3]],
        fancy=False,
        cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap(
            'bwr_r', 21),
        rasterized=False)

    cb = phlp.colorbar(fig,
                       axes[2],
                       im,
                       width=0.05,
                       height=0.5,
                       hoffset=-0.05,
                       voffset=0.5)
    cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)

    axes[2].set_ylim(-1550, 50)
    axes[2].set_title('LFP and CSD ({})'.format(X[1]), va='baseline')
    phlp.annotate_subplot(axes[2], ncols=1, nrows=1, letter='C')
    if show_xlabels:
        axes[2].set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        axes[2].set_xlabel('')

    plotPowers(axes[3],
               params,
               params.Y,
               'CSD',
               linestyles=linestyles,
               transient=transient,
               markerstyles=markerstyles,
               linewidths=linewidths)
    axes[3].axis(axes[3].axis('tight'))
    axes[3].set_ylim(-1550, 50)
    axes[3].set_yticks(-np.arange(16) * 100)
    if show_xlabels:
        axes[3].set_xlabel(r'$\sigma^2$ ($(\mu$Amm$^{-3})^2$)', va='center')
    axes[3].set_title('CSD variance', va='baseline')
    axes[3].set_xlim(left=1E-7)
    phlp.remove_axis_junk(axes[3])
    phlp.annotate_subplot(axes[3], ncols=1, nrows=1, letter='D')

    plotPowers(axes[4],
               params,
               params.Y,
               'LFP',
               linestyles=linestyles,
               transient=transient,
               markerstyles=markerstyles,
               linewidths=linewidths)
    axes[4].axis(axes[4].axis('tight'))
    axes[4].set_ylim(-1550, 50)
    axes[4].set_yticks(-np.arange(16) * 100)
    if show_xlabels:
        axes[4].set_xlabel(r'$\sigma^2$ (mV$^2$)', va='center')
    axes[4].set_title('LFP variance', va='baseline')
    axes[4].legend(bbox_to_anchor=(1.37, 1.0), frameon=False)
    axes[4].set_xlim(left=1E-7)
    phlp.remove_axis_junk(axes[4])
    phlp.annotate_subplot(axes[4], ncols=1, nrows=1, letter='E')

    return fig
コード例 #2
0
def fig_exc_inh_contrib(fig, axes, params, savefolders, T=[800, 1000], transient=200,
                        panel_labels = 'FGHIJ', show_xlabels=True):
    '''
    plot time series LFPs and CSDs with signal variances as function of depth
    for the cases with all synapses intact, or knocking out excitatory
    input or inhibitory input to the postsynaptic target region
    
    args:
    ::
        fig : 
        axes :  
        savefolders : list of simulation output folders
        T : list of ints, first and last time sample
        transient : int, duration of transient period
        
    returns:
    ::
        
        matplotlib.figure.Figure object
    
    '''
    # params = multicompartment_params()
    # ana_params = analysis_params.params()

    
    #file name types
    file_names = ['CSDsum.h5', 'LFPsum.h5']
    
    #panel titles
    panel_titles = [
        'LFP&CSD\nexc. syn.',
        'LFP&CSD\ninh. syn.',
        'LFP&CSD\ncompound',
        'CSD variance',
        'LFP variance',]
    
    #labels
    labels = [
        'exc. syn.',
        'inh. syn.',
        'SUM']
    
    #some colors for traces
    if analysis_params.bw:
        colors = ['k', 'gray', 'k']
        # lws = [0.75, 0.75, 1.5]
        lws = [1.25, 1.25, 1.25]
    else:
        colors = [analysis_params.colorE, analysis_params.colorI, 'k']
        # colors = 'rbk'
        # lws = [0.75, 0.75, 1.5]
        lws = [1.25, 1.25, 1.25]

    
    #scalebar labels
    units = ['$\mu$A mm$^{-3}$', 'mV']
    
    #depth of each contact site
    depth = params.electrodeParams['z']


    # #set up figure
    # #figure aspect
    # ana_params.set_PLOS_2column_fig_style(ratio=0.5)
    # fig, axes = plt.subplots(1,5)
    # fig.subplots_adjust(left=0.06, right=0.96, wspace=0.4, hspace=0.2)
    
    #clean up
    for ax in axes.flatten():
        phlp.remove_axis_junk(ax)


    for i, file_name in enumerate(file_names):
        #get the global data scaling bar range for use in latter plots
        #TODO: find nicer solution without creating figure
        dum_fig, dum_ax = plt.subplots(1)
        vlim_LFP = 0
        vlim_CSD = 0
        for savefolder in savefolders:
            vlimround0 = plot_signal_sum(dum_ax, params,
                                         os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                                         rasterized=False)
            if vlimround0 > vlim_LFP:
                vlim_LFP = vlimround0
            im = plot_signal_sum_colorplot(dum_ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                                           cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                                           rasterized=False)
            if abs(im.get_array()).max() > vlim_CSD:
                vlim_CSD = abs(im.get_array()).max()
                                                  
        plt.close(dum_fig)


        for j, savefolder in enumerate(savefolders):
            ax = axes[j]
            if i == 1:
                plot_signal_sum(ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                            unit=units[i], T=T,
                            color='k',
                            # color='k' if analysis_params.bw else colors[j],
                            vlimround=vlim_LFP, rasterized=False)
            elif i == 0:
                im = plot_signal_sum_colorplot(ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                              unit=r'($\mu$Amm$^{-3}$)', T=T, ylabels=True,
                              colorbar=False,
                              fancy=False, cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                              absmax=vlim_CSD,
                              rasterized=False)
            
            
            ax.axis((T[0], T[1], -1550, 50))
            ax.set_title(panel_titles[j], va='baseline')
            
            if i == 0:
                phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[j])
            if j != 0:
                ax.set_yticklabels([])
            
            if i == 0:#and j == 2:
                cb = phlp.colorbar(fig, ax, im,
                                   width=0.05, height=0.5,
                                   hoffset=-0.05, voffset=0.5)
                cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)
            ax.xaxis.set_major_locator(plt.MaxNLocator(3))
            if show_xlabels:
                ax.set_xlabel(r'$t$ (ms)', labelpad=0.)
            else:
                ax.set_xlabel('')

            
    #power in CSD
    ax = axes[3]
    datas = []    
    for j, savefolder in enumerate(savefolders):
        f = h5py.File(os.path.join(os.path.split(params.savefolder)[0], savefolder, 'CSDsum.h5'))
        var = f['data'][()][:, transient:].var(axis=1)
        ax.semilogx(var, depth,
                    color=colors[j], label=labels[j], lw=lws[j], clip_on=False)
        datas.append(f['data'][()][:, transient:])
        f.close()
    #control variances
    vardiff = datas[0].var(axis=1) + datas[1].var(axis=1) + np.array([2*np.cov(x,y)[0,1] for (x,y) in zip(datas[0], datas[1])]) - datas[2].var(axis=1)
    #ax.semilogx(abs(vardiff), depth, color='gray', lw=1, label='control')
    ax.axis(ax.axis('tight'))
    ax.set_ylim(-1550, 50)
    ax.set_yticks(-np.arange(16)*100)
    if show_xlabels:
        ax.set_xlabel(r'$\sigma^2$ ($(\mu$Amm$^{-3})^2$)', labelpad=0.)
    ax.set_title(panel_titles[3], va='baseline')
    phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[3])
    ax.set_yticklabels([])


    #power in LFP
    ax = axes[4]

    datas = []
    for j, savefolder in enumerate(savefolders):
        f = h5py.File(os.path.join(os.path.split(params.savefolder)[0], savefolder, 'LFPsum.h5'))
        var = f['data'][()][:, transient:].var(axis=1)
        ax.semilogx(var, depth,
                    color=colors[j], label=labels[j], lw=lws[j], clip_on=False)
        datas.append(f['data'][()][:, transient:])
        f.close()
    #control variances
    vardiff = datas[0].var(axis=1) + datas[1].var(axis=1) + np.array([2*np.cov(x,y)[0,1] for (x,y) in zip(datas[0], datas[1])]) - datas[2].var(axis=1)
    ax.axis(ax.axis('tight'))
    ax.set_ylim(-1550, 50)
    ax.set_yticks(-np.arange(16)*100)
    if show_xlabels:
        ax.set_xlabel(r'$\sigma^2$ (mV$^2$)', labelpad=0.)
    ax.set_title(panel_titles[4], va='baseline')
    phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[4])

    ax.legend(bbox_to_anchor=(1.3, 1.0), frameon=False)
    ax.set_yticklabels([])
コード例 #3
0
ファイル: figure_10.py プロジェクト: INM-6/hybridLFPy
def fig_exc_inh_contrib(fig, axes, params, savefolders, T=[800, 1000], transient=200,
                        panel_labels = 'FGHIJ', show_xlabels=True):
    '''
    plot time series LFPs and CSDs with signal variances as function of depth
    for the cases with all synapses intact, or knocking out excitatory
    input or inhibitory input to the postsynaptic target region
    
    args:
    ::
        fig : 
        axes :  
        savefolders : list of simulation output folders
        T : list of ints, first and last time sample
        transient : int, duration of transient period
        
    returns:
    ::
        
        matplotlib.figure.Figure object
    
    '''
    # params = multicompartment_params()
    # ana_params = analysis_params.params()

    
    #file name types
    file_names = ['CSDsum.h5', 'LFPsum.h5']
    
    #panel titles
    panel_titles = [
        'LFP&CSD\nexc. syn.',
        'LFP&CSD\ninh. syn.',
        'LFP&CSD\ncompound',
        'CSD variance',
        'LFP variance',]
    
    #labels
    labels = [
        'exc. syn.',
        'inh. syn.',
        'SUM']
    
    #some colors for traces
    if analysis_params.bw:
        colors = ['k', 'gray', 'k']
        # lws = [0.75, 0.75, 1.5]
        lws = [1.25, 1.25, 1.25]
    else:
        colors = [analysis_params.colorE, analysis_params.colorI, 'k']
        # colors = 'rbk'
        # lws = [0.75, 0.75, 1.5]
        lws = [1.25, 1.25, 1.25]

    
    #scalebar labels
    units = ['$\mu$A mm$^{-3}$', 'mV']
    
    #depth of each contact site
    depth = params.electrodeParams['z']


    # #set up figure
    # #figure aspect
    # ana_params.set_PLOS_2column_fig_style(ratio=0.5)
    # fig, axes = plt.subplots(1,5)
    # fig.subplots_adjust(left=0.06, right=0.96, wspace=0.4, hspace=0.2)
    
    #clean up
    for ax in axes.flatten():
        phlp.remove_axis_junk(ax)


    for i, file_name in enumerate(file_names):
        #get the global data scaling bar range for use in latter plots
        #TODO: find nicer solution without creating figure
        dum_fig, dum_ax = plt.subplots(1)
        vlim_LFP = 0
        vlim_CSD = 0
        for savefolder in savefolders:
            vlimround0 = plot_signal_sum(dum_ax, params,
                                         os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                                         rasterized=False)
            if vlimround0 > vlim_LFP:
                vlim_LFP = vlimround0
            im = plot_signal_sum_colorplot(dum_ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                                           cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                                           rasterized=False)
            if abs(im.get_array()).max() > vlim_CSD:
                vlim_CSD = abs(im.get_array()).max()
                                                  
        plt.close(dum_fig)


        for j, savefolder in enumerate(savefolders):
            ax = axes[j]
            if i == 1:
                plot_signal_sum(ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                            unit=units[i], T=T,
                            color='k',
                            # color='k' if analysis_params.bw else colors[j],
                            vlimround=vlim_LFP, rasterized=False)
            elif i == 0:
                im = plot_signal_sum_colorplot(ax, params, os.path.join(os.path.split(params.savefolder)[0], savefolder, file_name),
                              unit=r'($\mu$Amm$^{-3}$)', T=T, ylabels=True,
                              colorbar=False,
                              fancy=False, cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                              absmax=vlim_CSD,
                              rasterized=False)
            
            
            ax.axis((T[0], T[1], -1550, 50))
            ax.set_title(panel_titles[j], va='baseline')
            
            if i == 0:
                phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[j])
            if j != 0:
                ax.set_yticklabels([])
            
            if i == 0:#and j == 2:
                cb = phlp.colorbar(fig, ax, im,
                                   width=0.05, height=0.5,
                                   hoffset=-0.05, voffset=0.5)
                cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)
            ax.xaxis.set_major_locator(plt.MaxNLocator(3))
            if show_xlabels:
                ax.set_xlabel(r'$t$ (ms)', labelpad=0.)
            else:
                ax.set_xlabel('')

            
    #power in CSD
    ax = axes[3]
    datas = []    
    for j, savefolder in enumerate(savefolders):
        f = h5py.File(os.path.join(os.path.split(params.savefolder)[0], savefolder, 'CSDsum.h5'))
        var = f['data'].value[:, transient:].var(axis=1)
        ax.semilogx(var, depth,
                    color=colors[j], label=labels[j], lw=lws[j], clip_on=False)
        datas.append(f['data'].value[:, transient:])
        f.close()
    #control variances
    vardiff = datas[0].var(axis=1) + datas[1].var(axis=1) + np.array([2*np.cov(x,y)[0,1] for (x,y) in zip(datas[0], datas[1])]) - datas[2].var(axis=1)
    #ax.semilogx(abs(vardiff), depth, color='gray', lw=1, label='control')
    ax.axis(ax.axis('tight'))
    ax.set_ylim(-1550, 50)
    ax.set_yticks(-np.arange(16)*100)
    if show_xlabels:
        ax.set_xlabel(r'$\sigma^2$ ($(\mu$Amm$^{-3})^2$)', labelpad=0.)
    ax.set_title(panel_titles[3], va='baseline')
    phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[3])
    ax.set_yticklabels([])


    #power in LFP
    ax = axes[4]

    datas = []
    for j, savefolder in enumerate(savefolders):
        f = h5py.File(os.path.join(os.path.split(params.savefolder)[0], savefolder, 'LFPsum.h5'))
        var = f['data'].value[:, transient:].var(axis=1)
        ax.semilogx(var, depth,
                    color=colors[j], label=labels[j], lw=lws[j], clip_on=False)
        datas.append(f['data'].value[:, transient:])
        f.close()
    #control variances
    vardiff = datas[0].var(axis=1) + datas[1].var(axis=1) + np.array([2*np.cov(x,y)[0,1] for (x,y) in zip(datas[0], datas[1])]) - datas[2].var(axis=1)
    ax.axis(ax.axis('tight'))
    ax.set_ylim(-1550, 50)
    ax.set_yticks(-np.arange(16)*100)
    if show_xlabels:
        ax.set_xlabel(r'$\sigma^2$ (mV$^2$)', labelpad=0.)
    ax.set_title(panel_titles[4], va='baseline')
    phlp.annotate_subplot(ax, ncols=1, nrows=1, letter=panel_labels[4])

    ax.legend(bbox_to_anchor=(1.3, 1.0), frameon=False)
    ax.set_yticklabels([])
コード例 #4
0
                    unit='$\mu$A mm$^{-3}$',
                    T=T,
                    ylim=[-1550, 50],
                    rasterized=False)
    ax5.set_title('CSD')
    a = ax5.axis()
    ax5.vlines(x['TC'][0], a[2], a[3], 'k', lw=0.25)

    #show traces superimposed on color image
    if show_images:
        im = plot_signal_sum_colorplot(
            ax5,
            params,
            os.path.join(params.savefolder, 'CSDsum.h5'),
            unit=r'$\mu$Amm$^{-3}$',
            T=T,
            ylim=[-1550, 50],
            fancy=False,
            colorbar=False,
            cmap=plt.get_cmap('gray', 21)
            if analysis_params.bw else plt.get_cmap('bwr_r', 21),
            rasterized=False)

        cb = phlp.colorbar(fig,
                           ax5,
                           im,
                           width=0.05,
                           height=0.5,
                           hoffset=-0.05,
                           voffset=0.5)
        cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.1)
コード例 #5
0
ファイル: figure_08.py プロジェクト: lionelkusch/hybridLFPy
def fig_network_input_structure(fig,
                                params,
                                bottom=0.1,
                                top=0.9,
                                transient=200,
                                T=[800, 1000],
                                Df=0.,
                                mlab=True,
                                NFFT=256,
                                srate=1000,
                                window=plt.mlab.window_hanning,
                                noverlap=256 * 3 / 4,
                                letters='abcde',
                                flim=(4, 400),
                                show_titles=True,
                                show_xlabels=True,
                                show_CSD=False):
    '''
    This figure is the top part for plotting a comparison between the PD-model
    and the modified-PD model
    
    '''
    #load spike as database
    networkSim = CachedNetwork(**params.networkSimParams)
    if analysis_params.bw:
        networkSim.colors = phlp.get_colors(len(networkSim.X))

    # ana_params.set_PLOS_2column_fig_style(ratio=ratio)
    # fig = plt.figure()
    # fig.subplots_adjust(left=0.06, right=0.94, bottom=0.09, top=0.92, wspace=0.5, hspace=0.2)

    #use gridspec to get nicely aligned subplots througout panel
    gs1 = gridspec.GridSpec(5, 5, bottom=bottom, top=top)

    ############################################################################
    # A part, full dot display
    ############################################################################

    ax0 = fig.add_subplot(gs1[:, 0])
    phlp.remove_axis_junk(ax0)
    phlp.annotate_subplot(ax0,
                          ncols=5,
                          nrows=1,
                          letter=letters[0],
                          linear_offset=0.065)

    x, y = networkSim.get_xy(T, fraction=1)
    networkSim.plot_raster(ax0,
                           T,
                           x,
                           y,
                           markersize=0.2,
                           marker='_',
                           alpha=1.,
                           legend=False,
                           pop_names=True,
                           rasterized=False)
    ax0.set_ylabel('population', labelpad=0.)
    ax0.set_xticks([800, 900, 1000])

    if show_titles:
        ax0.set_title('spiking activity', va='center')
    if show_xlabels:
        ax0.set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        ax0.set_xlabel('')

    ############################################################################
    # B part, firing rate spectra
    ############################################################################

    # Get the firing rate from Potjan Diesmann et al network activity
    #collect the spikes x is the times, y is the id of the cell.
    T_all = [transient, networkSim.simtime]
    bins = np.arange(transient, networkSim.simtime + 1)

    x, y = networkSim.get_xy(T_all, fraction=1)

    # create invisible axes to position labels correctly
    ax_ = fig.add_subplot(gs1[:, 1])
    phlp.annotate_subplot(ax_,
                          ncols=5,
                          nrows=1,
                          letter=letters[1],
                          linear_offset=0.065)
    if show_titles:
        ax_.set_title('firing rate PSD', va='center')

    ax_.axis('off')

    colors = phlp.get_colors(len(params.Y)) + ['k']

    COUNTER = 0
    label_set = False

    t**s = ['L23E/I', 'L4E/I', 'L5E/I', 'L6E/I', 'TC']

    if x['TC'].size > 0:
        TC = True
    else:
        TC = False

    BAxes = []
    for i, X in enumerate(networkSim.X):

        if i % 2 == 0:
            ax1 = fig.add_subplot(gs1[COUNTER, 1])
            phlp.remove_axis_junk(ax1)

            if x[X].size > 0:
                ax1.text(0.05,
                         0.85,
                         t**s[COUNTER],
                         horizontalalignment='left',
                         verticalalignment='bottom',
                         transform=ax1.transAxes)
            BAxes.append(ax1)

        #firing rate histogram
        hist = np.histogram(x[X], bins=bins)[0].astype(float)
        hist -= hist.mean()

        if mlab:
            Pxx, freqs = plt.mlab.psd(hist,
                                      NFFT=NFFT,
                                      Fs=srate,
                                      noverlap=noverlap,
                                      window=window)
        else:
            [freqs, Pxx] = hlp.powerspec([hist],
                                         tbin=1.,
                                         Df=Df,
                                         pointProcess=False)
            mask = np.where(freqs >= 0.)
            freqs = freqs[mask]
            Pxx = Pxx.flatten()
            Pxx = Pxx[mask]
            Pxx = Pxx / (T_all[1] - T_all[0])**2

        if x[X].size > 0:
            ax1.loglog(freqs[1:],
                       Pxx[1:],
                       label=X,
                       color=colors[i],
                       clip_on=True)
            ax1.axis(ax1.axis('tight'))
            ax1.set_ylim([5E-4, 5E2])
            ax1.set_yticks([1E-3, 1E-1, 1E1])
            if label_set == False:
                ax1.set_ylabel(r'(s$^{-2}$/Hz)', labelpad=0.)
                label_set = True
            if i > 1:
                ax1.set_yticklabels([])
            if i >= 6 and not TC and show_xlabels or X == 'TC' and TC and show_xlabels:
                ax1.set_xlabel('$f$ (Hz)', labelpad=0.)
            if TC and i < 8 or not TC and i < 6:
                ax1.set_xticklabels([])

        else:
            ax1.axis('off')

        ax1.set_xlim(flim)

        if i % 2 == 0:
            COUNTER += 1

        ax1.yaxis.set_minor_locator(plt.NullLocator())

    ############################################################################
    # c part, LFP traces and CSD color plots
    ############################################################################

    ax2 = fig.add_subplot(gs1[:, 2])

    phlp.annotate_subplot(ax2,
                          ncols=5,
                          nrows=1,
                          letter=letters[2],
                          linear_offset=0.065)

    phlp.remove_axis_junk(ax2)
    plot_signal_sum(ax2,
                    params,
                    fname=os.path.join(params.savefolder, 'LFPsum.h5'),
                    unit='mV',
                    T=T,
                    ylim=[-1600, 40],
                    rasterized=False)

    # CSD background colorplot
    if show_CSD:
        im = plot_signal_sum_colorplot(ax2,
                                       params,
                                       os.path.join(params.savefolder,
                                                    'CSDsum.h5'),
                                       unit=r'($\mu$Amm$^{-3}$)',
                                       T=[800, 1000],
                                       colorbar=False,
                                       ylim=[-1600, 40],
                                       fancy=False,
                                       cmap=plt.cm.get_cmap('bwr_r', 21),
                                       rasterized=False)
        cb = phlp.colorbar(fig,
                           ax2,
                           im,
                           width=0.05,
                           height=0.4,
                           hoffset=-0.05,
                           voffset=0.3)
        cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.1)

    ax2.set_xticks([800, 900, 1000])
    ax2.axis(ax2.axis('tight'))

    if show_titles:
        if show_CSD:
            ax2.set_title('LFP & CSD', va='center')
        else:
            ax2.set_title('LFP', va='center')
    if show_xlabels:
        ax2.set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        ax2.set_xlabel('')

    ############################################################################
    # d part, LFP power trace for each layer
    ############################################################################

    freqs, PSD = calc_signal_power(params,
                                   fname=os.path.join(params.savefolder,
                                                      'LFPsum.h5'),
                                   transient=transient,
                                   Df=Df,
                                   mlab=mlab,
                                   NFFT=NFFT,
                                   noverlap=noverlap,
                                   window=window)

    channels = [0, 3, 7, 11, 13]

    # create invisible axes to position labels correctly
    ax_ = fig.add_subplot(gs1[:, 3])
    phlp.annotate_subplot(ax_,
                          ncols=5,
                          nrows=1,
                          letter=letters[3],
                          linear_offset=0.065)

    if show_titles:
        ax_.set_title('LFP PSD', va='center')

    ax_.axis('off')

    for i, ch in enumerate(channels):

        ax = fig.add_subplot(gs1[i, 3])
        phlp.remove_axis_junk(ax)

        if i == 0:
            ax.set_ylabel('(mV$^2$/Hz)', labelpad=0)

        ax.loglog(freqs[1:], PSD[ch][1:], color='k')
        ax.xaxis.set_ticks_position('bottom')
        ax.yaxis.set_ticks_position('left')
        if i < 4:
            ax.set_xticklabels([])
        ax.text(0.75,
                0.85,
                'ch. %i' % (channels[i] + 1),
                horizontalalignment='left',
                verticalalignment='bottom',
                fontsize=6,
                transform=ax.transAxes)
        ax.tick_params(axis='y', which='minor', bottom='off')
        ax.axis(ax.axis('tight'))
        ax.yaxis.set_minor_locator(plt.NullLocator())

        ax.set_xlim(flim)
        ax.set_ylim(1E-7, 2E-4)
        if i != 0:
            ax.set_yticklabels([])

    if show_xlabels:
        ax.set_xlabel('$f$ (Hz)', labelpad=0.)

    ############################################################################
    # e part signal power
    ############################################################################

    ax4 = fig.add_subplot(gs1[:, 4])

    phlp.annotate_subplot(ax4,
                          ncols=5,
                          nrows=1,
                          letter=letters[4],
                          linear_offset=0.065)

    fname = os.path.join(params.savefolder, 'LFPsum.h5')
    im = plot_signal_power_colorplot(ax4,
                                     params,
                                     fname=fname,
                                     transient=transient,
                                     Df=Df,
                                     mlab=mlab,
                                     NFFT=NFFT,
                                     window=window,
                                     cmap=plt.cm.get_cmap('gray_r', 12),
                                     vmin=1E-7,
                                     vmax=1E-4)
    phlp.remove_axis_junk(ax4)

    ax4.set_xlim(flim)

    cb = phlp.colorbar(fig,
                       ax4,
                       im,
                       width=0.05,
                       height=0.5,
                       hoffset=-0.05,
                       voffset=0.5)
    cb.set_label('(mV$^2$/Hz)', labelpad=0.1)

    if show_titles:
        ax4.set_title('LFP PSD', va='center')
    if show_xlabels:
        ax4.set_xlabel(r'$f$ (Hz)', labelpad=0.)
    else:
        ax4.set_xlabel('')

    return fig
コード例 #6
0
ファイル: figure_08.py プロジェクト: INM-6/hybridLFPy
def fig_network_input_structure(fig, params, bottom=0.1, top=0.9, transient=200, T=[800, 1000], Df= 0., mlab= True, NFFT=256, srate=1000,
             window=plt.mlab.window_hanning, noverlap=256*3/4, letters='abcde', flim=(4, 400),
             show_titles=True, show_xlabels=True, show_CSD=False):
    '''
    This figure is the top part for plotting a comparison between the PD-model
    and the modified-PD model
    
    '''
    #load spike as database
    networkSim = CachedNetwork(**params.networkSimParams)
    if analysis_params.bw:
        networkSim.colors = phlp.get_colors(len(networkSim.X))


    # ana_params.set_PLOS_2column_fig_style(ratio=ratio)
    # fig = plt.figure()
    # fig.subplots_adjust(left=0.06, right=0.94, bottom=0.09, top=0.92, wspace=0.5, hspace=0.2)
    
    #use gridspec to get nicely aligned subplots througout panel
    gs1 = gridspec.GridSpec(5, 5, bottom=bottom, top=top)
    
    
    ############################################################################ 
    # A part, full dot display
    ############################################################################
    
    ax0 = fig.add_subplot(gs1[:, 0])
    phlp.remove_axis_junk(ax0)
    phlp.annotate_subplot(ax0, ncols=5, nrows=1, letter=letters[0],
                     linear_offset=0.065)
   
    x, y = networkSim.get_xy(T, fraction=1)
    networkSim.plot_raster(ax0, T, x, y,
                           markersize=0.2, marker='_',
                           alpha=1.,
                           legend=False, pop_names=True,
                           rasterized=False)
    ax0.set_ylabel('population', labelpad=0.)
    ax0.set_xticks([800,900,1000])
   
    if show_titles:
        ax0.set_title('spiking activity',va='center')
    if show_xlabels:
        ax0.set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        ax0.set_xlabel('')
      
    ############################################################################
    # B part, firing rate spectra
    ############################################################################

  
    # Get the firing rate from Potjan Diesmann et al network activity
    #collect the spikes x is the times, y is the id of the cell.
    T_all=[transient, networkSim.simtime]
    bins = np.arange(transient, networkSim.simtime+1)
        
    x, y = networkSim.get_xy(T_all, fraction=1)

    # create invisible axes to position labels correctly
    ax_ = fig.add_subplot(gs1[:, 1])
    phlp.annotate_subplot(ax_, ncols=5, nrows=1, letter=letters[1],
                                 linear_offset=0.065)
    if show_titles:
        ax_.set_title('firing rate PSD', va='center')
    
    ax_.axis('off')

    colors = phlp.get_colors(len(params.Y))+['k']
    
    COUNTER = 0
    label_set = False
    
    t**s = ['L23E/I', 'L4E/I', 'L5E/I', 'L6E/I', 'TC']

    if x['TC'].size > 0:
        TC = True
    else:
        TC = False

    BAxes = []
    for i, X in enumerate(networkSim.X):

        if i % 2 == 0:
            ax1 = fig.add_subplot(gs1[COUNTER, 1])
            phlp.remove_axis_junk(ax1)

            if x[X].size > 0:
                ax1.text(0.05, 0.85, t**s[COUNTER],
                    horizontalalignment='left',
                    verticalalignment='bottom',
                    transform=ax1.transAxes)
            BAxes.append(ax1)


        #firing rate histogram
        hist = np.histogram(x[X], bins=bins)[0].astype(float)
        hist -= hist.mean()
        
        if mlab:
            Pxx, freqs=plt.mlab.psd(hist, NFFT=NFFT,
                                    Fs=srate, noverlap=noverlap, window=window)
        else:
            [freqs, Pxx] = hlp.powerspec([hist], tbin= 1.,
                                        Df=Df, pointProcess=False)
            mask = np.where(freqs >= 0.)
            freqs = freqs[mask]
            Pxx = Pxx.flatten()
            Pxx = Pxx[mask]
            Pxx = Pxx/(T_all[1]-T_all[0])**2
        
        if x[X].size > 0:
            ax1.loglog(freqs[1:], Pxx[1:],
                       label=X, color=colors[i],
                       clip_on=True)
            ax1.axis(ax1.axis('tight'))
            ax1.set_ylim([5E-4,5E2])
            ax1.set_yticks([1E-3,1E-1,1E1])
            if label_set == False:
                ax1.set_ylabel(r'(s$^{-2}$/Hz)', labelpad=0.)
                label_set = True
            if i > 1:
                ax1.set_yticklabels([])
            if i >= 6 and not TC and show_xlabels or X == 'TC' and TC and show_xlabels:
                ax1.set_xlabel('$f$ (Hz)', labelpad=0.)
            if TC and i < 8 or not TC and i < 6:
                ax1.set_xticklabels([])    

        else:
            ax1.axis('off')
                       
        ax1.set_xlim(flim)
           
        
        if i % 2 == 0:
            COUNTER += 1
        
        ax1.yaxis.set_minor_locator(plt.NullLocator())
        



    ############################################################################
    # c part, LFP traces and CSD color plots
    ############################################################################
   
    ax2 = fig.add_subplot(gs1[:, 2])
    
    phlp.annotate_subplot(ax2, ncols=5, nrows=1, letter=letters[2],
                     linear_offset=0.065)


    phlp.remove_axis_junk(ax2)
    plot_signal_sum(ax2, params,
                    fname=os.path.join(params.savefolder, 'LFPsum.h5'),
                    unit='mV', T=T, ylim=[-1600, 40],
                    rasterized=False)
    
    # CSD background colorplot
    if show_CSD:
        im = plot_signal_sum_colorplot(ax2, params, os.path.join(params.savefolder, 'CSDsum.h5'),
                                  unit=r'($\mu$Amm$^{-3}$)', T=[800, 1000],
                                  colorbar=False,
                                  ylim=[-1600, 40], fancy=False, cmap=plt.cm.get_cmap('bwr_r', 21),
                                  rasterized=False)
        cb = phlp.colorbar(fig, ax2, im,
                           width=0.05, height=0.4,
                           hoffset=-0.05, voffset=0.3)
        cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.1)

    ax2.set_xticks([800,900,1000])
    ax2.axis(ax2.axis('tight'))
     
    if show_titles:
        if show_CSD:
            ax2.set_title('LFP & CSD', va='center')
        else:
            ax2.set_title('LFP', va='center')
    if show_xlabels:
        ax2.set_xlabel(r'$t$ (ms)', labelpad=0.)
    else:
        ax2.set_xlabel('')
  
 
    ############################################################################
    # d part, LFP power trace for each layer
    ############################################################################

    freqs, PSD = calc_signal_power(params, fname=os.path.join(params.savefolder,
                                                           'LFPsum.h5'),
                                        transient=transient, Df=Df, mlab=mlab,
                                        NFFT=NFFT, noverlap=noverlap,
                                        window=window)

    channels = [0, 3, 7, 11, 13]
  
    # create invisible axes to position labels correctly
    ax_ = fig.add_subplot(gs1[:, 3])
    phlp.annotate_subplot(ax_, ncols=5, nrows=1, letter=letters[3],
                                 linear_offset=0.065)

    if show_titles:
        ax_.set_title('LFP PSD',va='center')
    
    ax_.axis('off')

    for i, ch in enumerate(channels):

        ax = fig.add_subplot(gs1[i, 3])
        phlp.remove_axis_junk(ax)

        if i == 0:
            ax.set_ylabel('(mV$^2$/Hz)', labelpad=0)

        ax.loglog(freqs[1:],PSD[ch][1:], color='k')
        ax.xaxis.set_ticks_position('bottom')
        ax.yaxis.set_ticks_position('left')
        if i < 4:
            ax.set_xticklabels([])
        ax.text(0.75, 0.85,'ch. %i' %(channels[i]+1),
                horizontalalignment='left',
                verticalalignment='bottom',
                fontsize=6,
                transform=ax.transAxes)
        ax.tick_params(axis='y', which='minor', bottom='off')
        ax.axis(ax.axis('tight'))
        ax.yaxis.set_minor_locator(plt.NullLocator())

        ax.set_xlim(flim)
        ax.set_ylim(1E-7,2E-4)
        if i != 0 :
            ax.set_yticklabels([])


    if show_xlabels:
        ax.set_xlabel('$f$ (Hz)', labelpad=0.)
    
    ############################################################################
    # e part signal power
    ############################################################################
    
    ax4 = fig.add_subplot(gs1[:, 4])

    phlp.annotate_subplot(ax4, ncols=5, nrows=1, letter=letters[4],
                     linear_offset=0.065)
  
    fname=os.path.join(params.savefolder, 'LFPsum.h5')
    im = plot_signal_power_colorplot(ax4, params, fname=fname, transient=transient, Df=Df,
                                mlab=mlab, NFFT=NFFT, window=window,
                                cmap=plt.cm.get_cmap('gray_r', 12),
                                vmin=1E-7, vmax=1E-4)
    phlp.remove_axis_junk(ax4)

    ax4.set_xlim(flim)

    cb = phlp.colorbar(fig, ax4, im,
                       width=0.05, height=0.5,
                       hoffset=-0.05, voffset=0.5)
    cb.set_label('(mV$^2$/Hz)', labelpad=0.1)


    if show_titles:
        ax4.set_title('LFP PSD', va='center')
    if show_xlabels:
        ax4.set_xlabel(r'$f$ (Hz)', labelpad=0.)
    else:
        ax4.set_xlabel('')
       
    return fig 
コード例 #7
0
ファイル: figure_07.py プロジェクト: INM-6/hybridLFPy
    plot_signal_sum(ax5, params,
                    fname=os.path.join(params.savefolder, 'CSDsum.h5'),
                    unit='$\mu$A mm$^{-3}$',
                    T=T,
                    ylim=[-1550, 50],
                    rasterized=False)
    ax5.set_title('CSD')
    a = ax5.axis()
    ax5.vlines(x['TC'][0], a[2], a[3], 'k', lw=0.25)
    

    #show traces superimposed on color image
    if show_images:
        im = plot_signal_sum_colorplot(ax5, params, os.path.join(params.savefolder, 'CSDsum.h5'),
                                  unit=r'$\mu$Amm$^{-3}$', T=T,
                                  ylim=[-1550, 50],
                                  fancy=False, colorbar=False,
                                  cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                                  rasterized=False)

        cb = phlp.colorbar(fig, ax5, im,
                           width=0.05, height=0.5,
                           hoffset=-0.05, voffset=0.5)
        cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.1)



    ############################################################################
    # D part, LFP 
    ############################################################################
    ax7 = fig.add_subplot(gs[:, 3])
    plt.locator_params(nbins=4)
コード例 #8
0
ファイル: figure_09.py プロジェクト: INM-6/hybridLFPy
def fig_lfp_decomposition(fig, axes, params, transient=200, X=['L23E', 'L6E'], show_xlabels=True):
    # ana_params.set_PLOS_2column_fig_style(ratio=0.5)
    # fig, axes = plt.subplots(1,5)
    # fig.subplots_adjust(left=0.06, right=0.96, wspace=0.4, hspace=0.2)
    
    if analysis_params.bw:
        # linestyles = ['-', '-', '--', '--', '-.', '-.', ':', ':']
        linestyles = ['-', '-', '-', '-', '-', '-', '-', '-']
        markerstyles = ['s', 's', 'v', 'v', 'o', 'o', '^', '^']
    else:
        if plt.matplotlib.__version__ == '1.5.x':
            linestyles = ['-', ':']*(len(params.Y) / 2)
            print('CSD variance semi log plots may fail with matplotlib.__version__ {}'.format(plt.matplotlib.__version__))
        else:
            linestyles = ['-', (0, (1,1))]*(len(params.Y) / 2) #cercor version
        # markerstyles = ['s', 's', 'v', 'v', 'o', 'o', '^', '^']
        markerstyles = [None]*len(params.Y)
        linewidths = [1.25 for i in range(len(linestyles))]
    
    plt.delaxes(axes[0])
    
    #population plot
    axes[0] = fig.add_subplot(261)
    axes[0].xaxis.set_ticks([])
    axes[0].yaxis.set_ticks([])
    axes[0].set_frame_on(False)
    plot_population(axes[0], params, aspect='tight', isometricangle=np.pi/32,
                           plot_somas = False, plot_morphos = True,
                           num_unitsE = 1, num_unitsI=1,
                           clip_dendrites=False, main_pops=True,
                           rasterized=False)
    phlp.annotate_subplot(axes[0], ncols=5, nrows=1, letter='A')
    axes[0].set_aspect('auto')
    axes[0].set_ylim(-1550, 50)
    axis = axes[0].axis()
    
    
    
    phlp.remove_axis_junk(axes[1])
    plot_signal_sum(axes[1], params,
                    fname=os.path.join(params.populations_path, X[0] + '_population_LFP.h5'),
                    unit='mV', T=[800,1000], ylim=[axis[2], axis[3]],
                    rasterized=False)
    
    # CSD background colorplot
    im = plot_signal_sum_colorplot(axes[1], params, os.path.join(params.populations_path,  X[0] + '_population_CSD.h5'),
                              unit=r'$\mu$Amm$^{-3}$', T=[800,1000],
                              colorbar=False,
                              ylim=[axis[2], axis[3]], fancy=False,
                              cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                              rasterized=False)

    cb = phlp.colorbar(fig, axes[1], im,
                       width=0.05, height=0.5,
                       hoffset=-0.05, voffset=0.5)
    cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)

    axes[1].set_ylim(-1550, 50)
    axes[1].set_title('LFP and CSD ({})'.format(X[0]), va='baseline')
    phlp.annotate_subplot(axes[1], ncols=3, nrows=1, letter='B')
     
    #quickfix on first axes
    axes[0].set_ylim(-1550, 50)
    if show_xlabels:
        axes[1].set_xlabel(r'$t$ (ms)',labelpad=0.)
    else:
        axes[1].set_xlabel('')
    


    phlp.remove_axis_junk(axes[2])
    plot_signal_sum(axes[2], params,
                    fname=os.path.join(params.populations_path, X[1] + '_population_LFP.h5'), ylabels=False,
                    unit='mV', T=[800,1000], ylim=[axis[2], axis[3]],
                    rasterized=False)
    
    # CSD background colorplot
    im = plot_signal_sum_colorplot(axes[2], params, os.path.join(params.populations_path, X[1] + '_population_CSD.h5'),
                              unit=r'$\mu$Amm$^{-3}$', T=[800,1000], ylabels=False,
                              colorbar=False,
                              ylim=[axis[2], axis[3]], fancy=False, 
                              cmap=plt.get_cmap('gray', 21) if analysis_params.bw else plt.get_cmap('bwr_r', 21),
                              rasterized=False)

    cb = phlp.colorbar(fig, axes[2], im,
                       width=0.05, height=0.5,
                       hoffset=-0.05, voffset=0.5)
    cb.set_label('($\mu$Amm$^{-3}$)', labelpad=0.)

    axes[2].set_ylim(-1550, 50)
    axes[2].set_title('LFP and CSD ({})'.format(X[1]), va='baseline')
    phlp.annotate_subplot(axes[2], ncols=1, nrows=1, letter='C')
    if show_xlabels:
        axes[2].set_xlabel(r'$t$ (ms)',labelpad=0.)
    else:
        axes[2].set_xlabel('')
    

    plotPowers(axes[3], params, params.Y, 'CSD', linestyles=linestyles, transient=transient, markerstyles=markerstyles, linewidths=linewidths)
    axes[3].axis(axes[3].axis('tight'))
    axes[3].set_ylim(-1550, 50)
    axes[3].set_yticks(-np.arange(16)*100)
    if show_xlabels:
        axes[3].set_xlabel(r'$\sigma^2$ ($(\mu$Amm$^{-3})^2$)', va='center')
    axes[3].set_title('CSD variance', va='baseline')
    axes[3].set_xlim(left=1E-7)
    phlp.remove_axis_junk(axes[3])
    phlp.annotate_subplot(axes[3], ncols=1, nrows=1, letter='D')
    
    
    plotPowers(axes[4], params, params.Y, 'LFP', linestyles=linestyles, transient=transient, markerstyles=markerstyles, linewidths=linewidths)
    axes[4].axis(axes[4].axis('tight'))
    axes[4].set_ylim(-1550, 50)
    axes[4].set_yticks(-np.arange(16)*100)
    if show_xlabels:
        axes[4].set_xlabel(r'$\sigma^2$ (mV$^2$)', va='center')
    axes[4].set_title('LFP variance', va='baseline')
    axes[4].legend(bbox_to_anchor=(1.37, 1.0), frameon=False)
    axes[4].set_xlim(left=1E-7)
    phlp.remove_axis_junk(axes[4])
    phlp.annotate_subplot(axes[4], ncols=1, nrows=1, letter='E')
    
    
    
    
    return fig