예제 #1
0
 def _showFSC(self, paramName=None):
     threshold = self.resolutionThreshold.get()
     nrefs = len(self._refsList)
     gridsize = self._getGridSize(nrefs)
     xmipp.activateMathExtensions()
     
     for ref3d in self._refsList:
         xplotter = XmippPlotter(*gridsize, windowTitle='Resolution FSC')
         legends = []
         show = False
         plot_title = 'Ref3D_%s' % ref3d
         a = xplotter.createSubPlot(plot_title, 'frequency(1/A)', 'FSC', yformat=False)
         legends = []
         for it in self._iterations:
             file_name = self.protocol._getFileName('resolutionXmdFile', iter=it, ref=ref3d)
             if exists(file_name):
                 show = True
                 legends.append('iter %d' % it)
                 self._plotFSC(a, file_name)
                 xplotter.showLegend(legends)
         if show:
             if threshold < self.maxFrc:
                 a.plot([self.minInv, self.maxInv],[threshold, threshold], color='black', linestyle='--')
             a.grid(True)
         else:
             raise Exception("Set a valid iteration to show its FSC")
         
         return [xplotter]
예제 #2
0
    def _showFSC(self, paramName=None):
        threshold = self.resolutionThreshold.get()
        nrefs = len(self._refsList)
        gridsize = self._getGridSize(nrefs)
        xmipp.activateMathExtensions()

        for ref3d in self._refsList:
            xplotter = XmippPlotter(*gridsize, windowTitle='Resolution FSC')
            legends = []
            show = False
            plot_title = 'Ref3D_%s' % ref3d
            a = xplotter.createSubPlot(plot_title,
                                       'frequency(1/A)',
                                       'FSC',
                                       yformat=False)
            legends = []
            for it in self._iterations:
                file_name = self.protocol._getFileName('resolutionXmdFile',
                                                       iter=it,
                                                       ref=ref3d)
                if exists(file_name):
                    show = True
                    legends.append('iter %d' % it)
                    self._plotFSC(a, file_name)
                    xplotter.showLegend(legends)
            if show:
                if threshold < self.maxFrc:
                    a.plot([self.minInv, self.maxInv], [threshold, threshold],
                           color='black',
                           linestyle='--')
                a.grid(True)
            else:
                raise Exception("Set a valid iteration to show its FSC")

            return [xplotter]
예제 #3
0
 def _plotDendrogram(self, e=None):
     from pyworkflow.em.packages.xmipp3.plotter import XmippPlotter
     xplotter = XmippPlotter()
     self.plt = xplotter.createSubPlot("Dendrogram", "", "")
     self.step = 0.25
     self.rightMost = 0.0 # Used to arrange leaf nodes at the bottom
     
     node = self.protocol.buildDendrogram()
     self.plotNode(node, self.minHeight.get())    
     self.plt.set_xlim(0., self.rightMost + self.step)
     self.plt.set_ylim(-10, 105)
     
     return [xplotter]
예제 #4
0
    def _plotDendrogram(self, e=None):
        from pyworkflow.em.packages.xmipp3.plotter import XmippPlotter
        xplotter = XmippPlotter()
        self.plt = xplotter.createSubPlot("Dendrogram", "", "")
        self.step = 0.25
        self.rightMost = 0.0  # Used to arrange leaf nodes at the bottom

        node = self.protocol.buildDendrogram()
        self.plotNode(node, self.minHeight.get())
        self.plt.set_xlim(0., self.rightMost + self.step)
        self.plt.set_ylim(-10, 105)

        return [xplotter]
예제 #5
0
 def _createAngDist2D(self, it):
     # Common variables to use
     nrefs = len(self._refsList)
     gridsize = self._getGridSize(nrefs)
     xplotter = XmippPlotter(*gridsize, mainTitle='Iteration %d' % it, windowTitle="Angular Distribution")
     for ref3d in self._refsList:
         classesFn = self.protocol._getFileName('outClassesXmd', iter=it, ref=ref3d)
         if exists(classesFn):
             md = xmipp.MetaData(classesFn)
             title = 'Ref3D_%d' % ref3d
             xplotter.plotMdAngularDistribution(title, md)
         else:
             print "File %s does not exist" % classesFn
             return None
     
     return xplotter
예제 #6
0
    def createSubPlot(self, title, xlabel, ylabel):

        if self.useLastPlot and self.last_subplot:
            ax = self.last_subplot
            ax.cla()
            ax.set_title(title)
        else:
            ax = XmippPlotter.createSubPlot(self, title, xlabel, ylabel)
            
        return ax
예제 #7
0
    def _createAngDist2D(self, it):
        # Common variables to use
        nrefs = len(self._refsList)
        gridsize = self._getGridSize(nrefs)
        xplotter = XmippPlotter(*gridsize,
                                mainTitle='Iteration %d' % it,
                                windowTitle="Angular Distribution")
        for ref3d in self._refsList:
            classesFn = self.protocol._getFileName('outClassesXmd',
                                                   iter=it,
                                                   ref=ref3d)
            if exists(classesFn):
                md = xmipp.MetaData(classesFn)
                title = 'Ref3D_%d' % ref3d
                xplotter.plotMdAngularDistribution(title, md)
            else:
                print "File %s does not exist" % classesFn
                return None

        return xplotter
예제 #8
0
def createPlots(protML, selectedPlots):
    ''' Launch some plot for an ML2D protocol run '''
    from pyworkflow.em.packages.xmipp3.plotter import XmippPlotter
    import xmipp
    
    protML._plot_count = 0
    lastIter = protML._lastIteration()
    if lastIter == 0:
        return
    refs = protML._getIterClasses(it=lastIter, block='classes')
#    if not exists(refs):
#        return 
#    blocks = getBlocksInMetaDataFile(refs)
#    lastBlock = blocks[-1]
    
    def doPlot(plotName):
        return plotName in selectedPlots

    # Remove 'mirror' from list if DoMirror is false
    if doPlot('doShowMirror') and not protML.doMirror:
        selectedPlots.remove('doShowMirror')
        
    n = len(selectedPlots)
    if n == 0:
        #showWarning("ML2D plots", "Nothing to plot", protML.master)
        print "No plots"
        return 
    elif n == 1:
        gridsize = [1, 1]
    elif n == 2:
        gridsize = [2, 1]
    else:
        gridsize = [2, 2]
        
    xplotter = XmippPlotter(x=gridsize[0], y=gridsize[1])
        
    # Create data to plot
    iters = range(1, lastIter+1)
    ll = []
    pmax = []
    for iter in iters:
        logs = protML._getIterClasses(it=iter, block='info')
        md = xmipp.MetaData(logs)
        id = md.firstObject()
        ll.append(md.getValue(xmipp.MDL_LL, id))
        pmax.append(md.getValue(xmipp.MDL_PMAX, id))
            
    if doPlot('doShowLL'):
        a = xplotter.createSubPlot('Log-likelihood (should increase)', 'iterations', 'LL', yformat=True)
        a.plot(iters, ll)

    #Create plot of mirror for last iteration
    if doPlot('doShowMirror'):
        from numpy import arange
        from matplotlib.ticker import FormatStrFormatter
        md = xmipp.MetaData(refs)
        mirrors = [md.getValue(xmipp.MDL_MIRRORFRAC, id) for id in md]
        nrefs = len(mirrors)
        ind = arange(1, nrefs + 1)
        width = 0.85
        a = xplotter.createSubPlot('Mirror fractions on last iteration', 'classes', 'mirror fraction')
        a.set_xticks(ind + 0.45)
        a.xaxis.set_major_formatter(FormatStrFormatter('%1.0f'))
        a.bar(ind, mirrors, width, color='b')
        a.set_ylim([0, 1.])
        a.set_xlim([0.8, nrefs + 1])
        
    if doPlot('doShowPmax'):
        a = xplotter.createSubPlot('Probabilities distribution', 'iterations', 'Pmax/Psum') 
        a.plot(iters, pmax, color='green')
    
    if doPlot('doShowSignalChange'):
        md = xmipp.MetaData()
        for iter in iters:
            fn = protML._getIterClasses(it=iter, block='classes')
            md2 = xmipp.MetaData(fn)
            md2.fillConstant(xmipp.MDL_ITER, str(iter))
            md.unionAll(md2)
        # 'iter(.*[1-9].*)@2D/ML2D/run_004/ml2d_iter_refs.xmd')
        #a = plt.subplot(gs[1, 1])
        #print "md:", md
        md2 = xmipp.MetaData()    
        md2.aggregate(md, xmipp.AGGR_MAX, xmipp.MDL_ITER, xmipp.MDL_SIGNALCHANGE, xmipp.MDL_MAX)
        signal_change = [md2.getValue(xmipp.MDL_MAX, id) for id in md2]
        xplotter.createSubPlot('Maximum signal change', 'iterations', 'signal change')
        xplotter.plot(iters, signal_change, color='green')
    
    return [xplotter]
    
예제 #9
0
 def __init__(self, **kwargs):
     """ Create the plotter, 'data' should be passed in **kwargs.
     """
     self._data = kwargs.get('data')
     XmippPlotter.__init__(self, **kwargs)
     self.useLastPlot = False
예제 #10
0
    def _plotHistogramAngularMovement(self, paramName=None):
        from numpy import arange
        from matplotlib.ticker import FormatStrFormatter
        
        plots = []
        colors = ['g', 'b', 'r', 'y', 'c', 'm', 'k']
        lenColors=len(colors)
        
        numberOfBins = self.numberOfBins.get()
        md = xmipp.MetaData()
        for it in self._iterations:
            mdFn = self.protocol._mdDevitationsFn(it)
            if xmipp.existsBlockInMetaDataFile(mdFn):
                md.read(mdFn)
                if not self.usePsi:
                    md.fillConstant(xmipp.MDL_ANGLE_PSI,0.)

                nrefs = len(self._refsList)
                gridsize = self._getGridSize(nrefs)
                xplotterShift = XmippPlotter(*gridsize, mainTitle='Iteration_%d\n' % it, windowTitle="ShiftDistribution")
                xplotter = XmippPlotter(*gridsize, mainTitle='Iteration_%d' % it, windowTitle="AngularDistribution")

                for ref3d in self._refsList:
                    mDoutRef3D = xmipp.MetaData()
                    mDoutRef3D.importObjects(md, xmipp.MDValueEQ(xmipp.MDL_REF3D, ref3d))
                    _frequency = "Frequency (%d)" % mDoutRef3D.size()

                    xplotterShift.createSubPlot("%s_ref3D_%d"%(xmipp.label2Str(xmipp.MDL_SHIFT_DIFF),ref3d), "pixels", _frequency)
                    xplotter.createSubPlot("%s_ref3D_%d"%(xmipp.label2Str(xmipp.MDL_ANGLE_DIFF),ref3d), "degrees", _frequency)
                    #mDoutRef3D.write("*****@*****.**",MD_APPEND)
                    xplotter.plotMd(mDoutRef3D,
                                    xmipp.MDL_ANGLE_DIFF,
                                    xmipp.MDL_ANGLE_DIFF,
                                    color=colors[ref3d%lenColors],
                                    #nbins=50
                                    nbins=int(numberOfBins)
                    )#if nbins is present do an histogram
                    xplotterShift.plotMd(mDoutRef3D,
                                         xmipp.MDL_SHIFT_DIFF,
                                         xmipp.MDL_SHIFT_DIFF,
                                         color=colors[ref3d%lenColors],
                                         nbins=int(numberOfBins)
                    )#if nbins is present do an histogram

                    if self.angleSort:
                        mDoutRef3D.sort(xmipp.MDL_ANGLE_DIFF)
                        fn = xmipp.FileName()
                        baseFileName   = self.protocol._getTmpPath("angle_sort.xmd")
                        fn = self.protocol._getRefBlockFileName("angle_iter", it, "ref3D", ref3d, baseFileName)
                        mDoutRef3D.write(fn, xmipp.MD_APPEND)
                        print "File with sorted angles saved in:", fn

                    if self.shiftSort:
                        mDoutRef3D.sort(xmipp.MDL_SHIFT_DIFF)
                        fn = xmipp.FileName()
                        baseFileName   = self.protocol._getTmpPath("angle_sort.xmd")
                        fn = self.protocol._getRefBlockFileName("shift_iter", it, "ref3D", ref3d, baseFileName)
                        mDoutRef3D.write(fn, xmipp.MD_APPEND)
                        print "File with sorted shifts saved in:", fn

                    plots.append(xplotterShift)
                    plots.append(xplotter)
            else:
                print "File %s does not exist" % mdFn
        return plots
예제 #11
0
    def _plotHistogramAngularMovement(self, paramName=None):
        from numpy import arange
        from matplotlib.ticker import FormatStrFormatter

        plots = []
        colors = ['g', 'b', 'r', 'y', 'c', 'm', 'k']
        lenColors = len(colors)

        numberOfBins = self.numberOfBins.get()
        md = xmipp.MetaData()
        for it in self._iterations:
            mdFn = self.protocol._mdDevitationsFn(it)
            if xmipp.existsBlockInMetaDataFile(mdFn):
                md.read(mdFn)
                if not self.usePsi:
                    md.fillConstant(xmipp.MDL_ANGLE_PSI, 0.)

                nrefs = len(self._refsList)
                gridsize = self._getGridSize(nrefs)
                xplotterShift = XmippPlotter(*gridsize,
                                             mainTitle='Iteration_%d\n' % it,
                                             windowTitle="ShiftDistribution")
                xplotter = XmippPlotter(*gridsize,
                                        mainTitle='Iteration_%d' % it,
                                        windowTitle="AngularDistribution")

                for ref3d in self._refsList:
                    mDoutRef3D = xmipp.MetaData()
                    mDoutRef3D.importObjects(
                        md, xmipp.MDValueEQ(xmipp.MDL_REF3D, ref3d))
                    _frequency = "Frequency (%d)" % mDoutRef3D.size()

                    xplotterShift.createSubPlot(
                        "%s_ref3D_%d" %
                        (xmipp.label2Str(xmipp.MDL_SHIFT_DIFF), ref3d),
                        "pixels", _frequency)
                    xplotter.createSubPlot(
                        "%s_ref3D_%d" %
                        (xmipp.label2Str(xmipp.MDL_ANGLE_DIFF), ref3d),
                        "degrees", _frequency)
                    #mDoutRef3D.write("*****@*****.**",MD_APPEND)
                    xplotter.plotMd(
                        mDoutRef3D,
                        xmipp.MDL_ANGLE_DIFF,
                        xmipp.MDL_ANGLE_DIFF,
                        color=colors[ref3d % lenColors],
                        #nbins=50
                        nbins=int(numberOfBins)
                    )  #if nbins is present do an histogram
                    xplotterShift.plotMd(
                        mDoutRef3D,
                        xmipp.MDL_SHIFT_DIFF,
                        xmipp.MDL_SHIFT_DIFF,
                        color=colors[ref3d % lenColors],
                        nbins=int(numberOfBins
                                  ))  #if nbins is present do an histogram

                    if self.angleSort:
                        mDoutRef3D.sort(xmipp.MDL_ANGLE_DIFF)
                        fn = xmipp.FileName()
                        baseFileName = self.protocol._getTmpPath(
                            "angle_sort.xmd")
                        fn = self.protocol._getRefBlockFileName(
                            "angle_iter", it, "ref3D", ref3d, baseFileName)
                        mDoutRef3D.write(fn, xmipp.MD_APPEND)
                        print "File with sorted angles saved in:", fn

                    if self.shiftSort:
                        mDoutRef3D.sort(xmipp.MDL_SHIFT_DIFF)
                        fn = xmipp.FileName()
                        baseFileName = self.protocol._getTmpPath(
                            "angle_sort.xmd")
                        fn = self.protocol._getRefBlockFileName(
                            "shift_iter", it, "ref3D", ref3d, baseFileName)
                        mDoutRef3D.write(fn, xmipp.MD_APPEND)
                        print "File with sorted shifts saved in:", fn

                    plots.append(xplotterShift)
                    plots.append(xplotter)
            else:
                print "File %s does not exist" % mdFn
        return plots