Example #1
0
def plotStateSignal(ax,
                    t,
                    sig,
                    leftSpineOn=True,
                    labely="",
                    labelyPos=-0.2,
                    color='black',
                    scaleBar=None,
                    scaleX=0.75,
                    scaleY=0.05,
                    scaleText='ms',
                    scaleTextSize='small'):
    setSignalAxes(ax, leftSpineOn)

    if (sig is not None):
        ax.plot(t, sig, color=color)

    #ax.set_ylabel(labely)
    ax.text(labelyPos,
            0.5,
            labely,
            verticalalignment='center',
            horizontalalignment='right',
            transform=ax.transAxes,
            rotation=90)
    ax.set_xlim([t[0], t[-1]])

    if (scaleBar is not None):
        xScaleBar(scaleBar,
                  x=scaleX,
                  y=scaleY,
                  ax=ax,
                  size=scaleTextSize,
                  unitsText=scaleText)
Example #2
0
def plotGammaExample(ps, r, c, trialNum, tStart, tEnd, **kw):
    '''Plot examples of gamma activity.'''
    ax             = kw.pop('ax', plt.gca())
    noise_sigma    = kw.pop('noise_sigma', None)
    noise_sigma_xy = kw.pop('noise_sigma_xy', (0.95, 0.85))
    xscale_kw      = kw.pop('xscale_kw', None)
    yscale_kw      = kw.pop('yscale_kw', None)
    monIdx_e       = kw.pop('monIdx_e', 1)
    monIdx_i       = kw.pop('monIdx_i', 0)

    globalAxesSettings(ax)
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.spines['bottom'].set_visible(False)

    data = ps[r][c][trialNum].data
    monEList = data['stateMon_e']
    t, Isyn_e = extractSummedSignals(monEList, ['I_clamp_GABA_A'], tStart,
                                     tEnd, monIdx=monIdx_e)
    monIList = data['stateMon_i']
    t, Isyn_i = extractSummedSignals(monIList,
                                     ['I_clamp_AMPA', 'I_clamp_NMDA'],
                                     tStart, tEnd,
                                     monIdx=monIdx_i)
    Isyn_e *= 1e-3
    Isyn_i *= 1e-3
    plt.plot(t, Isyn_e, color='red')
    plt.plot(t, Isyn_i, color='blue')
    max = np.max(Isyn_e)
    min = np.min(Isyn_i)
    absmax = np.max([np.abs(max), np.abs(min)])

    ax.set_xlim([tStart, tEnd])
    ax.xaxis.set_ticks_position('none')
    ax.yaxis.set_ticks_position('none')
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_ylim([-absmax, absmax])

    if (noise_sigma is not None):
        txt = '$\sigma$ = {0} pA'.format(noise_sigma)
        ns_x, ns_y = noise_sigma_xy[0], noise_sigma_xy[1]
        ax.text(ns_x, ns_y, txt, transform=ax.transAxes, va='bottom', ha='right',
                size='x-small')

    # Scale bars
    if xscale_kw is not None:
        xscale_kw = dict(xscale_kw)
        xscale_kw.update(ax=ax)
        xScaleBar(**xscale_kw)

    if yscale_kw is not None:
        yscale_kw = dict(yscale_kw)
        yscale_kw.update(ax=ax)
        yScaleBar(**yscale_kw)
Example #3
0
    def plot(self, *args, **kwargs):
        for n_theta_cycles in range(1, 9):
            T = n_theta_cycles / self.theta_freq * 1e3
            l, b, r, top = self.myc['bbox']

            self.fig = self._get_final_fig(self.myc['fig_size'])
            self.ax_theta = self.fig.add_subplot(3, 1, 1)

            # Only theta
            t = np.arange(0, T+self.dt, self.dt)
            theta = self.const + .5 * (1. +
                    np.cos(2*np.pi*self.theta_freq*t*1e-3 - np.pi)) * (1 - self.const)
            signalPlot(
                    t, theta,
                    ax=self.ax_theta,
                    color=self.myc['theta_color'],
                    zeroLine=False)
            self.ax_theta.axis('off')
            self.ax_theta.set_xlim([t[0], t[-1]])
            self.ax_theta.set_ylim(-.2, 1.2)
            self.ax_theta.set_title('A', x=0, y=.95, size=14, weight='bold',
                                    ha='left', va='top')

            # PAC only gamma
            self.ax_pac = self.fig.add_subplot(3, 1, 2)
            gamma = np.cos(2*np.pi*self.gamma_freq*t*1e-3 - np.pi) * theta
            signalPlot(
                    t, gamma,
                    ax=self.ax_pac,
                    color=self.myc['gamma_color'],
                    zeroLine=False)

            self.ax_pac.axis('off')
            self.ax_pac.set_xlim([t[0], t[-1]])
            self.ax_pac.set_ylim(-1.02, 1.02)
            self.ax_pac.set_title('B', x=0, y=1, size=14, weight='bold',
                                  ha='left', va='top')

            # PAC Theta + gamma
            self.ax_pac_all = self.fig.add_subplot(3, 1, 3)
            self.ax_pac_all.hold('on')

            signalPlot(
                    t, theta,
                    ax=self.ax_pac_all,
                    color=self.myc['theta_color'],
                    zeroLine=False)

            gamma = .25 * np.cos(2*np.pi*self.gamma_freq*t*1e-3 - np.pi) * theta
            signalPlot(
                    t, theta + gamma,
                    ax=self.ax_pac_all,
                    color=self.myc['gamma_color'],
                    zeroLine=False)
            bar_x = 1 - 5. / 8 / n_theta_cycles
            xScaleBar(50, x=bar_x, y=.1, ax=self.ax_pac_all, size='small')

            self.ax_pac_all.axis('off')
            self.ax_pac_all.set_xlim([t[0], t[-1]])
            self.ax_pac_all.set_ylim(-.02, 1.5)
            self.ax_pac_all.set_title('C', x=0, y=1, size=14, weight='bold',
                                      ha='left', va='top')

            self.fig.subplots_adjust(left=l, bottom=b, right=r, top=top)

            fname = self.config['output_dir'] + "/pac_example_{0}.pdf"
            self.fig.savefig(fname.format(n_theta_cycles), dpi=300,
                             transparent=True)
            plt.close(self.fig)
Example #4
0
def plotEIRaster(ESpikes, ISpikes, tLimits, ylabel=None, **kw):
    '''Plot a raster plot E and I spikes.'''
    # kw arguments
    ax           = kw.pop('ax', plt.gca())
    yticks       = kw.pop('yticks', True)
    yticks_style = kw.pop('yticks_style', 'separate')
    ylabelPos    = kw.pop('ylabelPos', -0.22)
    EColor       = kw.pop('ecolor', 'red')
    IColor       = kw.pop('icolor', 'blue')
    title        = kw.pop('title', True)
    ann          = kw.pop('ann', False)
    ann_EI       = kw.pop('ann_EI', False)
    sigmaTitle   = kw.pop('sigmaTitle', True)
    noise_sigma  = kw.pop('noise_sigma', None)
    scaleBar     = kw.pop('scaleBar', None)
    scaleX       = kw.pop('scaleX', 0.75)
    scaleY       = kw.pop('scaleY', 0.05)
    scaleText    = kw.pop('scaleText', 'ms')
    scaleTextYOffset = kw.pop('scaleTextYOffset', .075)
    scaleHeight  = kw.pop('scaleHeight', .02)
    scaleTextSize= kw.pop('scaleTextSize', 'small')
    reshape_senders = kw.pop('reshape_senders', True)
    kw['markersize'] = kw.get('markersize', 1.0)

    if ylabel is None:
        ylabel = 'Neuron #'

    ESpikes = ESpikes.windowed(tLimits)
    ISpikes = ISpikes.windowed(tLimits)

    ESenders, ETimes = ESpikes.rasterData()
    ISenders, ITimes = ISpikes.rasterData()

    if reshape_senders:
        # TO REMOVE: this is to transform the neuron number from row-wise to
        # column wise indexes. A better solution has to be devised in the
        # future
        logger.warn('Nx, Ny are fixed in the code. Make sure the torus size '
                    'is the same as specified here.')
        Nx, Ny = 34, 30
        N = Nx * Ny
        if (N != ESpikes.N or N != ISpikes.N):
            raise ValueError("Fix the number of neurons in plotEIRaster")
        Ex = ESenders % Nx
        Ey = ESenders // Ny
        ESenders = Ey + Ex * Ny
        Ix = ISenders % Nx
        Iy = ISenders // Ny
        ISenders = Iy + Ix * Ny

    ISenders += ESpikes.N

    globalAxesSettings(ax)
    ax.minorticks_on()
    ax.xaxis.set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.yaxis.set_major_locator(ti.LinearLocator(2))
    ax.yaxis.set_minor_locator(ti.NullLocator())

    ax.plot(ETimes, ESenders+1, '.', color='red',  mec='none', **kw)
    ax.plot(ITimes, ISenders+1, '.', color='blue', mec='none', **kw)

    ax.set_xlim(tLimits)
    ax.set_ylim([1, ESpikes.N+ISpikes.N])
    if (yticks_style == 'separate'):
        ax.set_yticks([1, ESpikes.N, ESpikes.N+ISpikes.N])
    ax.invert_yaxis()
    ax.text(ylabelPos, 0.5, ylabel, va='center', ha='center',
            transform=ax.transAxes, rotation=90)
    if (not yticks):
        ax.yaxis.set_ticklabels([])

    # Annotations
    if (sigmaTitle):
        ax.set_title('$\sigma$ = {0} pA'.format(int(noise_sigma)), y=1.02,
                va='bottom', ha='center')
    if (ann):
        Y, X = aggr.computeYX(space, iterList, r=r, c=c)
        gE = Y[r, c]
        gI = X[r, c]
        txt = '$g_E$ = {0} nS\n$g_I$ = {1} nS'.format(gE, gI)
        ax.text(0.99, 1.02, txt, va='bottom', ha='right', size='small',
                transform=ax.transAxes)

    if (ann_EI):
        ax.text(-0.05, 0.75, 'E', va='center', ha='center', size='small',
                transform=ax.transAxes, color='red', weight='bold')
        ax.text(-0.05, 0.25, 'I', va='center', ha='center', size='small',
                transform=ax.transAxes, color='blue', weight='bold')

    if (scaleBar is not None):
        xScaleBar(scaleBar, x=scaleX, y=scaleY, ax=ax, size=scaleTextSize,
                unitsText=scaleText, textYOffset=scaleTextYOffset,
                height=scaleHeight)


    return ax
Example #5
0
def plotEIRaster(ESpikes, ISpikes, tLimits, ylabel=None, **kw):
    '''Plot a raster plot E and I spikes.'''
    # kw arguments
    ax = kw.pop('ax', plt.gca())
    yticks = kw.pop('yticks', True)
    yticks_style = kw.pop('yticks_style', 'separate')
    ylabelPos = kw.pop('ylabelPos', -0.22)
    EColor = kw.pop('ecolor', 'red')
    IColor = kw.pop('icolor', 'blue')
    title = kw.pop('title', True)
    ann = kw.pop('ann', False)
    ann_EI = kw.pop('ann_EI', False)
    sigmaTitle = kw.pop('sigmaTitle', True)
    noise_sigma = kw.pop('noise_sigma', None)
    scaleBar = kw.pop('scaleBar', None)
    scaleX = kw.pop('scaleX', 0.75)
    scaleY = kw.pop('scaleY', 0.05)
    scaleText = kw.pop('scaleText', 'ms')
    scaleTextYOffset = kw.pop('scaleTextYOffset', .075)
    scaleHeight = kw.pop('scaleHeight', .02)
    scaleTextSize = kw.pop('scaleTextSize', 'small')
    reshape_senders = kw.pop('reshape_senders', True)
    kw['markersize'] = kw.get('markersize', 1.0)

    if ylabel is None:
        ylabel = 'Neuron #'

    ESpikes = ESpikes.windowed(tLimits)
    ISpikes = ISpikes.windowed(tLimits)

    ESenders, ETimes = ESpikes.rasterData()
    ISenders, ITimes = ISpikes.rasterData()

    if reshape_senders:
        # TO REMOVE: this is to transform the neuron number from row-wise to
        # column wise indexes. A better solution has to be devised in the
        # future
        logger.warn('Nx, Ny are fixed in the code. Make sure the torus size '
                    'is the same as specified here.')
        Nx, Ny = 34, 30
        N = Nx * Ny
        if (N != ESpikes.N or N != ISpikes.N):
            raise ValueError("Fix the number of neurons in plotEIRaster")
        Ex = ESenders % Nx
        Ey = ESenders // Ny
        ESenders = Ey + Ex * Ny
        Ix = ISenders % Nx
        Iy = ISenders // Ny
        ISenders = Iy + Ix * Ny

    ISenders += ESpikes.N

    globalAxesSettings(ax)
    ax.minorticks_on()
    ax.xaxis.set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.yaxis.set_major_locator(ti.LinearLocator(2))
    ax.yaxis.set_minor_locator(ti.NullLocator())

    ax.plot(ETimes, ESenders + 1, '.', color='red', mec='none', **kw)
    ax.plot(ITimes, ISenders + 1, '.', color='blue', mec='none', **kw)

    ax.set_xlim(tLimits)
    ax.set_ylim([1, ESpikes.N + ISpikes.N])
    if (yticks_style == 'separate'):
        ax.set_yticks([1, ESpikes.N, ESpikes.N + ISpikes.N])
    ax.invert_yaxis()
    ax.text(ylabelPos,
            0.5,
            ylabel,
            va='center',
            ha='center',
            transform=ax.transAxes,
            rotation=90)
    if (not yticks):
        ax.yaxis.set_ticklabels([])

    # Annotations
    if (sigmaTitle):
        ax.set_title('$\sigma$ = {0} pA'.format(int(noise_sigma)),
                     y=1.02,
                     va='bottom',
                     ha='center')
    if (ann):
        Y, X = aggr.computeYX(space, iterList, r=r, c=c)
        gE = Y[r, c]
        gI = X[r, c]
        txt = '$g_E$ = {0} nS\n$g_I$ = {1} nS'.format(gE, gI)
        ax.text(0.99,
                1.02,
                txt,
                va='bottom',
                ha='right',
                size='small',
                transform=ax.transAxes)

    if (ann_EI):
        ax.text(-0.05,
                0.75,
                'E',
                va='center',
                ha='center',
                size='small',
                transform=ax.transAxes,
                color='red',
                weight='bold')
        ax.text(-0.05,
                0.25,
                'I',
                va='center',
                ha='center',
                size='small',
                transform=ax.transAxes,
                color='blue',
                weight='bold')

    if (scaleBar is not None):
        xScaleBar(scaleBar,
                  x=scaleX,
                  y=scaleY,
                  ax=ax,
                  size=scaleTextSize,
                  unitsText=scaleText,
                  textYOffset=scaleTextYOffset,
                  height=scaleHeight)

    return ax
Example #6
0
    def plot(self, *args, **kwargs):
        for n_theta_cycles in range(1, 9):
            T = n_theta_cycles / self.theta_freq * 1e3
            l, b, r, top = self.myc['bbox']

            self.fig = self._get_final_fig(self.myc['fig_size'])
            self.ax_theta = self.fig.add_subplot(3, 1, 1)

            # Only theta
            t = np.arange(0, T + self.dt, self.dt)
            theta = self.const + .5 * (
                1. + np.cos(2 * np.pi * self.theta_freq * t * 1e-3 -
                            np.pi)) * (1 - self.const)
            signalPlot(t,
                       theta,
                       ax=self.ax_theta,
                       color=self.myc['theta_color'],
                       zeroLine=False)
            self.ax_theta.axis('off')
            self.ax_theta.set_xlim([t[0], t[-1]])
            self.ax_theta.set_ylim(-.2, 1.2)
            self.ax_theta.set_title('A',
                                    x=0,
                                    y=.95,
                                    size=14,
                                    weight='bold',
                                    ha='left',
                                    va='top')

            # PAC only gamma
            self.ax_pac = self.fig.add_subplot(3, 1, 2)
            gamma = np.cos(2 * np.pi * self.gamma_freq * t * 1e-3 -
                           np.pi) * theta
            signalPlot(t,
                       gamma,
                       ax=self.ax_pac,
                       color=self.myc['gamma_color'],
                       zeroLine=False)

            self.ax_pac.axis('off')
            self.ax_pac.set_xlim([t[0], t[-1]])
            self.ax_pac.set_ylim(-1.02, 1.02)
            self.ax_pac.set_title('B',
                                  x=0,
                                  y=1,
                                  size=14,
                                  weight='bold',
                                  ha='left',
                                  va='top')

            # PAC Theta + gamma
            self.ax_pac_all = self.fig.add_subplot(3, 1, 3)
            self.ax_pac_all.hold('on')

            signalPlot(t,
                       theta,
                       ax=self.ax_pac_all,
                       color=self.myc['theta_color'],
                       zeroLine=False)

            gamma = .25 * np.cos(2 * np.pi * self.gamma_freq * t * 1e-3 -
                                 np.pi) * theta
            signalPlot(t,
                       theta + gamma,
                       ax=self.ax_pac_all,
                       color=self.myc['gamma_color'],
                       zeroLine=False)
            bar_x = 1 - 5. / 8 / n_theta_cycles
            xScaleBar(50, x=bar_x, y=.1, ax=self.ax_pac_all, size='small')

            self.ax_pac_all.axis('off')
            self.ax_pac_all.set_xlim([t[0], t[-1]])
            self.ax_pac_all.set_ylim(-.02, 1.5)
            self.ax_pac_all.set_title('C',
                                      x=0,
                                      y=1,
                                      size=14,
                                      weight='bold',
                                      ha='left',
                                      va='top')

            self.fig.subplots_adjust(left=l, bottom=b, right=r, top=top)

            fname = self.config['output_dir'] + "/pac_example_{0}.pdf"
            self.fig.savefig(fname.format(n_theta_cycles),
                             dpi=300,
                             transparent=True)
            plt.close(self.fig)