def createAlignmentPlot(meanX, meanY):
    """ Create a plotter with the cumulative shift per frame. """
    figureSize = (8, 6)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()

    ax = figure.add_subplot(111)
    ax.grid()
    ax.axis('equal')
    ax.set_title('Cartesian representation')
    ax.set_xlabel('Drift x (pixels)')
    ax.set_ylabel('Drift y (pixels)')

    # Max range of the plot of the two coordinates
    plotRange = max(max(meanX) - min(meanX), max(meanY) - min(meanY))
    i = 1
    skipLabels = ceil(len(meanX) / 10.0)
    for x, y in izip(meanX, meanY):
        if i % skipLabels == 0:
            ax.text(x - 0.02 * plotRange, y + 0.02 * plotRange, str(i))
        i += 1

    ax.plot(meanX, meanY, color='b')
    ax.plot(meanX, meanY, 'yo')

    # setting the plot windows to properly see the data
    ax.axis([min(meanX) - 0.1 * plotRange, max(meanX) + 0.1 * plotRange,
             min(meanY) - 0.1 * plotRange, max(meanY) + 0.1 * plotRange])

    plotter.tightLayout()

    return plotter
    def _showBFactorPlot(self, key):
        if key == 'guinier':
            label = 'rlnFittedInterceptGuinierPlot'
            title = "Polishing scale-factors"
        else:  # bfactor
            label = 'rlnBfactorUsedForSharpening'
            title = "Polishing B-factors"

        modelStar = self.protocol._getFileName('bfactors')
        if os.path.exists(modelStar):
            table = Table(fileName=modelStar, tableName='perframe_bfactors')
            frame = table.getColumnValues('rlnMovieFrameNumber')
            bfactor = map(float, table.getColumnValues(label))

            plotter = Plotter()
            figure = plotter.getFigure()
            a = figure.add_subplot(111)
            a.grid(True)
            a.set_xlabel('Movie frame number')
            a.set_ylabel(label)
            a.invert_yaxis()
            a.plot(frame, list(bfactor))
            a.set_title(title)
            plotter.tightLayout()

            return [plotter]
def movieCreatePlot(mic, saveFig):

    import xmipp
    meanX = []
    meanY = []
    figureSize = (8, 6)

    #alignedMovie = mic.alignMetaData
    md = xmipp.MetaData(mic.alignMetaData)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()

    preX = 0.0
    preY = 0.0
    meanX.append(0.0)
    meanY.append(0.0)
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Cartesian representation')
    ax.set_xlabel('Drift x (pixels)')
    ax.set_ylabel('Drift y (pixels)')
    ax.plot(0, 0, 'yo-')
    for objId in md:
        preX += md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId)
        preY += md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId)
        meanX.append(preX)
        meanY.append(preY)
        ax.plot(preX, preY, 'yo-')
        ax.text(preX - 0.02, preY + 0.01, str(objId + 1))
    ax.plot(np.asarray(meanX), np.asarray(meanY))
    if saveFig:
        plotter.savefig(mic.plotCart)
    return plotter
    def createPlot2D(self, volPrefix, md):

        import xmipp

        figurePath = self._getExtraPath(volPrefix +
                                        'softAlignmentValidation2D.png')
        figureSize = (8, 6)

        #alignedMovie = mic.alignMetaData
        plotter = Plotter(*figureSize)
        figure = plotter.getFigure()

        ax = figure.add_subplot(111)
        ax.grid()
        ax.set_title('Soft alignment validation map')
        ax.set_xlabel('Angular Precision')
        ax.set_ylabel('Angular Accuracy')

        for objId in md:
            x = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, objId)
            y = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, objId)
            ax.plot(x, y, 'r.', markersize=1)

        ax.grid(True, which='both')
        ax.autoscale_view(True, True, True)

        plotter.savefig(figurePath)
        plotter.show()
        return plotter
示例#5
0
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the cumulative shift per frame. """
    sumMeanX = []
    sumMeanY = []
    preX = 0.0
    preY = 0.0

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Global frame shift (cumulative)')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')
    if meanX[0] != 0 or meanY[0] != 0:
        raise Exception("First frame shift must be (0,0)!")

    i = first
    for x, y in izip(meanX, meanY):
        preX += x
        preY += y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        ax.text(preX - 0.02, preY + 0.02, str(i))
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
示例#6
0
def createAlignmentPlot(meanX, meanY):
    """ Create a plotter with the cumulative shift per frame. """
    sumMeanX = []
    sumMeanY = []
    figureSize = (8, 6)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()

    preX = 0.0
    preY = 0.0
    sumMeanX.append(0.0)
    sumMeanY.append(0.0)
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Cartesian representation')
    ax.set_xlabel('Drift x (pixels)')
    ax.set_ylabel('Drift y (pixels)')
    ax.plot(0, 0, 'yo-')
    i = 1
    for x, y in izip(meanX, meanY):
        preX += x
        preY += y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        #ax.plot(preX, preY, 'yo-')
        ax.text(preX-0.02, preY+0.02, str(i))
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
    def createPlot2D(self,volPrefix,md):
        
        import xmipp
        
        figurePath = self._getExtraPath(volPrefix + 'softAlignmentValidation2D.png')
        figureSize = (8, 6)
    
        #alignedMovie = mic.alignMetaData
        plotter = Plotter(*figureSize)
        figure = plotter.getFigure()
    
        ax = figure.add_subplot(111)
        ax.grid()
        ax.set_title('Soft alignment validation map')
        ax.set_xlabel('Angular Precision')
        ax.set_ylabel('Angular Accuracy')

        for objId in md:
            x = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, objId)
            y = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, objId)
            ax.plot(x, y, 'r.',markersize=1)

        ax.grid(True, which='both')
        ax.autoscale_view(True,True,True)
                
        plotter.savefig(figurePath)
        plotter.show()
        return plotter    
def movieCreatePlot(mic, saveFig):

    import xmipp
    meanX = []
    meanY = []
    figureSize = (8, 6)

    #alignedMovie = mic.alignMetaData
    md = xmipp.MetaData(mic.alignMetaData)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()

    preX = 0.0
    preY = 0.0
    meanX.append(0.0)
    meanY.append(0.0)
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Cartesian representation')
    ax.set_xlabel('Drift x (pixels)')
    ax.set_ylabel('Drift y (pixels)')
    ax.plot(0, 0, 'yo-')
    for objId in md:
        preX += md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId)
        preY += md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId)
        meanX.append(preX)
        meanY.append(preY)
        ax.plot(preX, preY, 'yo-')
        ax.text(preX-0.02, preY+0.01, str(objId+1))
    ax.plot(np.asarray(meanX), np.asarray(meanY))
    if saveFig:
        plotter.savefig(mic.plotCart)
    return plotter
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the shift per frame. """
    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Global shift')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')

    i = first
    skipLabels = ceil(len(meanX) / 10.0)
    labelTick = 1

    for x, y in izip(meanX, meanY):
        if labelTick == 1:
            ax.text(x - 0.02, y + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    ax.plot(meanX, meanY, color='b')
    ax.plot(meanX, meanY, 'yo')

    plotter.tightLayout()

    return plotter
示例#10
0
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []

    def px_to_ang(px):
        y1, y2 = px.get_ylim()
        x1, x2 = px.get_xlim()
        ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize)
        ax_ang.set_xlim(x1 * pixSize, x2 * pixSize)
        ax_ang.figure.canvas.draw()
        ax_ang2.figure.canvas.draw()

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax_px = figure.add_subplot(111)
    ax_px.grid()
    ax_px.set_xlabel('Shift x (px)')
    ax_px.set_ylabel('Shift y (px)')

    ax_ang = ax_px.twiny()
    ax_ang.set_xlabel('Shift x (A)')
    ax_ang2 = ax_px.twinx()
    ax_ang2.set_ylabel('Shift y (A)')

    i = first
    # The output and log files list the shifts relative to the first frame.
    # ROB unit seems to be pixels since sampling rate is only asked
    # by the program if dose filtering is required
    skipLabels = ceil(len(meanX) / 10.0)
    labelTick = 1

    for x, y in zip(meanX, meanY):
        sumMeanX.append(x)
        sumMeanY.append(y)
        if labelTick == 1:
            ax_px.text(x - 0.02, y + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    # automatically update lim of ax_ang when lim of ax_px changes.
    ax_px.callbacks.connect("ylim_changed", px_to_ang)
    ax_px.callbacks.connect("xlim_changed", px_to_ang)

    ax_px.plot(sumMeanX, sumMeanY, color='b')
    ax_px.plot(sumMeanX, sumMeanY, 'yo')
    ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5)
    ax_px.set_title('Global frame alignment')

    plotter.tightLayout()

    return plotter
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []

    def px_to_ang(ax_px):
        y1, y2 = ax_px.get_ylim()
        x1, x2 = ax_px.get_xlim()
        ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize)
        ax_ang.set_xlim(x1 * pixSize, x2 * pixSize)
        ax_ang.figure.canvas.draw()
        ax_ang2.figure.canvas.draw()

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax_px = figure.add_subplot(111)
    ax_px.grid()
    ax_px.set_xlabel('Shift x (px)')
    ax_px.set_ylabel('Shift y (px)')

    ax_ang = ax_px.twiny()
    ax_ang.set_xlabel('Shift x (A)')
    ax_ang2 = ax_px.twinx()
    ax_ang2.set_ylabel('Shift y (A)')

    i = first
    # The output _rlnMicrographShiftX/Y shifts relative to the first frame.
    # Unit is pixels of the original (unbinned) movies (Takanori, 2018)
    skipLabels = ceil(len(meanX) / 10.0)
    labelTick = 1

    for x, y in zip(meanX, meanY):
        sumMeanX.append(x)
        sumMeanY.append(y)
        if labelTick == 1:
            ax_px.text(x - 0.02, y + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    # automatically update lim of ax_ang when lim of ax_px changes.
    ax_px.callbacks.connect("ylim_changed", px_to_ang)
    ax_px.callbacks.connect("xlim_changed", px_to_ang)

    ax_px.plot(sumMeanX, sumMeanY, color='b')
    ax_px.plot(sumMeanX, sumMeanY, 'yo')
    ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5)
    ax_px.set_title('Global frame alignment')

    plotter.tightLayout()

    return plotter
示例#12
0
def _runPreWhiteningWeb(protocol, results):

    newAng = protocol.prewhitenAng.get()
    newRamp = protocol.prewhitenRamp.get()

    figsize = (18, 9)
    gridsize = [0, 0]
    plotter = Plotter(*gridsize, figsize=figsize, windowTitle="ResMap")

    myCreatePrewhiteningFigure(results, plotter.getFigure(), newAng, newRamp)

    return plotter
示例#13
0
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []
    preX = 0.0
    preY = 0.0

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Alignment based upon full frames')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')
    # morioncor2 (1.0.2) values refer to the middle frame, so first frame is no longer 0,0
    #if meanX[0] != 0 or meanY[0] != 0:
    #    raise Exception("First frame shift must be (0,0)!")

    i = first

    # ROB no accumulation is needed
    # see Motioncor2 user manual: "The output and log files list the shifts relative to the first frame."
    # or middle frame for motioncor2 1.0.2

    # ROB unit seems to be pixels since samplingrate is only asked by the program if
    # dose filtering is required
    skipLabels = ceil(len(meanX) / 10.0)
    labelTick = 1

    for x, y in izip(meanX, meanY):
        #preX += x
        #preY += y
        preX = x
        preY = y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        if labelTick == 1:
            ax.text(preX - 0.02, preY + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
示例#14
0
def _runPreWhiteningWeb(protocol, results):
    
    newAng = protocol.prewhitenAng.get()
    newRamp = protocol.prewhitenRamp.get()
    
    figsize = (18, 9)
    gridsize = [0, 0]
    plotter = Plotter(*gridsize, figsize=figsize, windowTitle="ResMap")
    
    myCreatePrewhiteningFigure(results, plotter.getFigure(),
                             newAng, newRamp
                            )
    
    return plotter
示例#15
0
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []
    preX = 0.0
    preY = 0.0

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Alignment based upon full frames')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')
    # motioncor2 (1.0.2) values refer to the middle frame, so first frame is no longer 0,0
    #if meanX[0] != 0 or meanY[0] != 0:
    #    raise Exception("First frame shift must be (0,0)!")
    i = first

    # ROB no accumulation is needed
    # see Motioncor2 user manual: "The output and log files list the shifts relative to the first frame."
    # or middle frame for motioncor2 1.0.2

    # ROB unit seems to be pixels since samplingrate is only asked by the program if
    # dose filtering is required
    skipLabels = ceil(len(meanX)/10.0)
    labelTick = 1

    for x, y in izip(meanX, meanY):
        #preX += x
        #preY += y
        preX = x
        preY = y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        if labelTick == 1:
            ax.text(preX - 0.02, preY + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []
    preX = 0.0
    preY = 0.0

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Alignment based upon full frames')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')
    
    i = first
    skipLabels = ceil(len(meanX)/10.0)
    labelTick = 1

    for x, y in izip(meanX, meanY):
        preX = x
        preY = y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        if labelTick == 1:
            ax.text(preX - 0.02, preY + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
示例#17
0
def createGlobalAlignmentPlot(meanX, meanY, first):
    """ Create a plotter with the shift per frame. """
    sumMeanX = []
    sumMeanY = []
    preX = 0.0
    preY = 0.0

    figureSize = (6, 4)
    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()
    ax = figure.add_subplot(111)
    ax.grid()
    ax.set_title('Alignment based upon full frames')
    ax.set_xlabel('Shift x (pixels)')
    ax.set_ylabel('Shift y (pixels)')
    
    i = first
    skipLabels = ceil(len(meanX)/10.0)
    labelTick = 1

    for x, y in izip(meanX, meanY):
        preX = x
        preY = y
        sumMeanX.append(preX)
        sumMeanY.append(preY)
        if labelTick == 1:
            ax.text(preX - 0.02, preY + 0.02, str(i))
            labelTick = skipLabels
        else:
            labelTick -= 1
        i += 1

    ax.plot(sumMeanX, sumMeanY, color='b')
    ax.plot(sumMeanX, sumMeanY, 'yo')

    plotter.tightLayout()

    return plotter
def movieCreatePlot(plotType, movie, saveFig):

    import xmipp

    meanX = []
    meanY = []
    stdX = []
    stdY = []
    colors = []
    gr = 255.0

    # if movie is None:
    #     return [self.errorMessage("Invalid movie id *%d*" % movieId,
    #                               title="Invalid input")]

    alignedMovie = movie.alignMetaData
    md = xmipp.MetaData(alignedMovie)
    colorDist = 255 / md.size()

    cartPosition = None
    polarPosition = None
    colorBarPosition = 122
    figureSize = (8, 6)

    if plotType == PLOT_CART:
        cartPosition = 121
    elif plotType == PLOT_POLAR:
        polarPosition = 121
    elif plotType == PLOT_POLARCART:
        cartPosition = 132
        polarPosition = 131
        colorBarPosition = 133

    plotter = Plotter(*figureSize)
    figure = plotter.getFigure()

    # Plot the color bar
    ax = figure.add_subplot(colorBarPosition, aspect="equal", xlim=[0, 6])
    ax.set_xticklabels([])
    ax.set_yticklabels([])
    colorBarX = np.array([1, 1])
    colorBarY = np.array([2, 4])

    # Read the shifts information from the Metadata
    for objId in md:
        meanX.append(md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId))
        meanY.append(md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId))
        stdX.append(md.getValue(xmipp.MDL_OPTICALFLOW_STDY, objId))
        stdY.append(md.getValue(xmipp.MDL_OPTICALFLOW_STDY, objId))
        colors.append((1, gr / 255.0, 0))
        ax.plot(colorBarX, colorBarY, c=(1, gr / 255.0, 0), linewidth=10)
        ax.text(2, np.mean(colorBarY), str(objId) + "-" + str(objId + 1))
        colorBarY += 2
        gr -= colorDist
    area = (np.sqrt(np.power(np.asarray(stdX), 2) + np.power(np.asarray(stdY), 2))) * 700
    # Plot in polar if needed
    if polarPosition:
        r = np.sqrt(np.power(np.asarray(meanX), 2) + np.power(np.asarray(meanY), 2))
        theta = np.arctan2(meanY, meanX) * 180 / np.pi
        ax = figure.add_subplot(polarPosition, projection="polar")
        ax.set_title("Polar representation")
        c = ax.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
        c.set_alpha(0.75)
        ax.plot(theta, r, "-^")
        if saveFig:
            plotter.savefig(movie.plotPolar)
    # Plot in cartesian if needed
    if cartPosition:
        ax = figure.add_subplot(cartPosition)
        ax.grid()
        ax.grid()
        ax.set_title("Cartesian representation")
        c = ax.scatter(np.asarray(meanX), np.asarray(meanY), c=colors, s=area, cmap=plt.cm.hsv)
        c.set_alpha(0.75)
        ax.plot(np.asarray(meanX), np.asarray(meanY), "-^")
        if saveFig:
            plotter.savefig(movie.plotCart)
    return plotter