Пример #1
0
def plotBumpSnapshots(FR, FRt, tstep, **kw):
    '''Snapshots of bumps in time.'''
    fig             = kw.pop('fig')
    timeTitles      = kw.pop('timeTitles', True)
    axesCoords      = kw.pop('axesCoords', (0.12, 0.01, 0.92, 0.7))
    axesDiv         = kw.pop('axesDiv', .01)
    bumpQuality     = kw.pop('bumpQuality', False)
    bumpQualityText = kw.pop('bumpQualityText', '')
    bumpQualityX    = kw.pop('bumpQualityX', -.9)
    maxRateColor    = kw.pop('maxRateColor', 'w')

    left, bottom, right, top = axesCoords
    width  = right - left
    height = top - bottom

    indexes = range(0, FRt.shape[0], tstep)
    oneWidth = float(width) / len(indexes)
    l = left
    bot = bottom
    max = np.max(FR[:, :, indexes])
    lastIndex = len(indexes) - 1
    idx = 0
    for it in indexes:
        print(it)
        t = bot + height
        r = l + oneWidth - axesDiv
        print(l, bot, r, top)

        ax = fig.add_axes(Bbox.from_extents(l, bot, r, top))
        plotBump(ax, FR[:, :, it], vmin=0, vmax=max, rasterized=True, **kw)
        if idx == lastIndex:
            rateText = "%.0f Hz" % max
            ax.text(1.05, .95, rateText, ha='left', va='top',
                    color=maxRateColor, transform=ax.transAxes, size='small',
                    weight='bold', clip_on=False)

        if bumpQuality and it == 0:
            txt = '{0:.2f}'.format(bumpQuality)
            ax.text(bumpQualityX, .5, txt, va='center', ha='center',
                    transform=ax.transAxes)

        if timeTitles:
            yTitle = 1.02
            ax.text(.5, yTitle, "{0}".format(FRt[it]*1e-3), size='medium',
                    transform=ax.transAxes, va='bottom', ha='center')
            if it == 0:
                ax.text(.5, yTitle + .3, "t(s)", ha='center', va='bottom',
                        transform=ax.transAxes)
                ax.text(bumpQualityX, yTitle, bumpQualityText, ha='center',
                        va='bottom', transform=ax.transAxes)

        l += oneWidth
        idx += 1

    return max  # Hack, but hopefully ok for now
Пример #2
0
def drawBumpExamples(dataSpace, spaceRect, iterList, gsCoords, types, **kw):
    '''
    TODO: code duplication
    '''
    # kw processing
    trialNum = kw.pop('trialNum', 0)
    exIdx = kw.pop('exIdx', (0, 0))
    xlabel = kw.pop('xlabel', True)
    ylabel = kw.pop('ylabel', True)
    xlabelPos = kw.pop('xlabelPos', -0.2)
    ylabelPos = kw.pop('ylabelPos', -0.2)
    xlabel2 = kw.pop('xlabel2', True)
    ylabel2 = kw.pop('ylabel2', True)
    xlabel2Pos = kw.pop('xlabel2os', -0.6)
    ylabel2Pos = kw.pop('ylabel2os', -0.6)
    fontSize = kw.pop('fontSize', 'medium')
    fig = kw.pop('fig', plt.gcf())
    # + plotBump() kwargs
    kw['rasterized'] = kw.pop('rasterized', True)
    kw['vmin'] = kw.get('vmin', 0)

    left = spaceRect[0]
    bottom = spaceRect[1]
    right = spaceRect[2]
    top = spaceRect[3]
    exRow, exCol = exIdx

    bumps, wi, we = aggr.aggregateType(dataSpace,
                                       iterList,
                                       types,
                                       trialNum + 1,
                                       ignoreNaNs=False,
                                       normalizeTicks=False)

    scaleBar = None
    exRows = top - bottom + 1
    exCols = right - left + 1
    gs = GridSpec(exRows, exCols)
    gsLeft = gsCoords[0]
    gsBottom = gsCoords[1]
    gsRight = gsCoords[2]
    gsTop = gsCoords[3]
    gs.update(left=gsLeft, bottom=gsBottom, right=gsRight, top=gsTop)

    ax = None
    for r in range(bottom, top + 1):
        for c in range(left, right + 1):
            print(r, c)
            bump = bumps[r][c][trialNum]
            if (not isinstance(bump, np.ndarray)):
                continue

            gsRow = top - r
            gsCol = c - left
            ax = fig.add_subplot(gs[gsRow, gsCol])
            plotBump(ax, bump, **kw)

            if (ylabel and gsCol == 0):
                label = "{0:.2f}".format(we[r][c])
                ax.text(ylabelPos,
                        0.5,
                        label,
                        rotation=90,
                        transform=ax.transAxes,
                        va='center',
                        ha='right',
                        fontsize=fontSize)
            if (xlabel and gsRow == exRows - 1):
                label = "{0:.2f}".format(wi[r][c])
                ax.text(0.5,
                        xlabelPos,
                        label,
                        transform=ax.transAxes,
                        va='top',
                        ha='center',
                        fontsize=fontSize)
            # Second Y label
            if (ylabel2 and r - bottom == 0 and c - left == 0):
                trans = transforms.blended_transform_factory(
                    ax.transAxes,
                    plt.gcf().transFigure)
                weTxt_y = gsBottom + (gsTop - gsBottom) / 2.0
                ax.text(ylabel2Pos,
                        weTxt_y,
                        ylabelText,
                        transform=trans,
                        va='center',
                        ha='right',
                        rotation=90,
                        fontsize=fontSize)

        # Second X label
        if (xlabel2 and r - bottom == 0):
            trans = transforms.blended_transform_factory(
                plt.gcf().transFigure, ax.transAxes)
            wiTxt_x = gsLeft + (gsRight - gsLeft) / 2.0
            ax.text(wiTxt_x,
                    xlabel2Pos,
                    xlabelText,
                    transform=trans,
                    va='top',
                    ha='center',
                    fontsize=fontSize)

    return gs
Пример #3
0
def drawBumpExamples(dataSpace, spaceRect, iterList, gsCoords, types, **kw):
    '''Draw a grid-like plot of bump attractor (network activity) examples.

    .. todo::
        code duplication
    '''
    # kw processing
    trialNum   = kw.pop('trialNum', 0)
    exIdx      = kw.pop('exIdx', (0, 0))
    xlabel     = kw.pop('xlabel', True)
    ylabel     = kw.pop('ylabel', True)
    xlabelPos  = kw.pop('xlabelPos', -0.2)
    ylabelPos  = kw.pop('ylabelPos', -0.2)
    xlabel2    = kw.pop('xlabel2', True)
    ylabel2    = kw.pop('ylabel2', True)
    xlabel2Pos = kw.pop('xlabel2os', -0.6)
    ylabel2Pos = kw.pop('ylabel2os', -0.6)
    fontSize   = kw.pop('fontSize', 'medium')
    fig        = kw.pop('fig', plt.gcf())
    # + plotBump() kwargs
    kw['rasterized'] = kw.pop('rasterized', True)
    kw['vmin']       = kw.get('vmin', 0)


    left   = spaceRect[0]
    bottom = spaceRect[1]
    right  = spaceRect[2]
    top    = spaceRect[3]
    exRow, exCol = exIdx

    bumps, wi, we = aggr.aggregateType(dataSpace, iterList, types, trialNum+1,
            ignoreNaNs=False, normalizeTicks=False)

    scaleBar = None
    exRows = top - bottom + 1
    exCols = right - left + 1
    gs = GridSpec(exRows, exCols)
    gsLeft   = gsCoords[0]
    gsBottom = gsCoords[1]
    gsRight  = gsCoords[2]
    gsTop    = gsCoords[3]
    gs.update(left=gsLeft, bottom=gsBottom, right=gsRight, top=gsTop)

    ax = None
    for r in range(bottom, top+1):
        for c in range(left, right+1):
            print(r, c)
            bump = bumps[r][c][trialNum]
            if (not isinstance(bump, np.ndarray)):
                continue

            gsRow = top - r
            gsCol = c - left
            ax = fig.add_subplot(gs[gsRow, gsCol])
            plotBump(ax, bump, **kw)

            if (ylabel and gsCol == 0):
                label = "{0:.2f}".format(we[r][c])
                ax.text(ylabelPos, 0.5, label, rotation=90,
                        transform=ax.transAxes, va='center', ha='right',
                        fontsize=fontSize)
            if (xlabel and gsRow == exRows - 1):
                label = "{0:.2f}".format(wi[r][c])
                ax.text(0.5, xlabelPos, label, transform=ax.transAxes,
                        va='top', ha='center', fontsize=fontSize)
            # Second Y label
            if (ylabel2 and r-bottom == 0 and c-left == 0):
                trans = transforms.blended_transform_factory(ax.transAxes,
                        plt.gcf().transFigure)
                weTxt_y = gsBottom + (gsTop - gsBottom)/2.0
                ax.text(ylabel2Pos, weTxt_y, ylabelText, transform=trans,
                        va='center', ha='right', rotation=90,
                        fontsize=fontSize)


        # Second X label
        if (xlabel2 and r - bottom == 0):
            trans = transforms.blended_transform_factory(plt.gcf().transFigure,
                    ax.transAxes)
            wiTxt_x = gsLeft + (gsRight - gsLeft)/2.0
            ax.text(wiTxt_x, xlabel2Pos, xlabelText, transform=trans, va='top',
                    ha='center', fontsize=fontSize)

    return gs