Exemplo n.º 1
0
    def _showSSNR(self, paramName=None):
        nrefs = len(self._refsList)
        gridsize = self._getGridSize(nrefs)
        xplotter = EmPlotter(x=gridsize[0], y=gridsize[1])

        for ref3d in self._refsList:
            plot_title = 'Resolution SSNR, for Class %s' % ref3d
            a = xplotter.createSubPlot(plot_title,
                                       'Angstroms^-1',
                                       'sqrt(SSNR)',
                                       yformat=False)
            legendName = []
            for it in self._iterations:
                if self.protocol.IS_REFINE:
                    fn = self.protocol._getFileName('output_vol_par', iter=it)
                else:
                    fn = self.protocol._getFileName('output_vol_par_class',
                                                    iter=it,
                                                    ref=ref3d)
                if exists(fn):
                    self._plotSSNR(a, fn)
                legendName.append('iter %d' % it)
            xplotter.showLegend(legendName)
            a.grid(True)

        return [xplotter]
Exemplo n.º 2
0
    def _plotHistogram(self, param=None):
        """ First we parse the MSA plt:
        first column: cumulative percent.
        second column: iteration number.
        """

        iters = []
        cumPercents = []
        fn = self.protocol.getOutputPlt()
        with open(fn) as f:
            lines_after_2 = f.readlines()[2:]
            for line in lines_after_2:
                values = line.split()
                cumPercents.append(float(values[0]))
                iters.append(int(float(values[1])))
        f.close()

        width = 0.85
        xplotter = EmPlotter()
        a = xplotter.createSubPlot(
            'Behaviour of sum of eigenvalues during analysis',
            'Iteration number', '%')
        a.bar(iters, cumPercents, width, color='b')

        return [xplotter]
 def _showGuinier(self, volume):
     nrefs = len(self._refsList)
     gridsize = self._getGridSize(nrefs)
     guinierFn = volume + ".guinier"
     
     d2 = self._getGuinierValue(guinierFn, 0)
     
     legends = ["lnFweighted ln(F)", "corrected ln(F)", "model"]
     xplotter = EmPlotter(*gridsize, windowTitle='Guinier Plots')
     subPlot = xplotter.createSubPlot(basename(volume), 'd^-2(A^-2)', 'ln(F)', yformat=False)
     for i, legend in enumerate(legends):
         y = self._getGuinierValue(guinierFn, i+2)
         subPlot.plot(d2, y)
         xplotter.showLegend(legends)
     subPlot.grid(True)
     return xplotter
Exemplo n.º 4
0
 def _createAngDist2D(self, it):
     fnDir = self.protocol._getExtraPath("Iter%03d" % it)
     fnAngles = join(fnDir, "angles.xmd")
     view = None
     if exists(fnAngles):
         fnAnglesSqLite = join(fnDir, "angles.sqlite")
         from pyworkflow.em.viewers import EmPlotter
         if not exists(fnAnglesSqLite):
             from pyworkflow.em.metadata.utils import getSize
             self.createAngDistributionSqlite(
                 fnAnglesSqLite,
                 getSize(fnAngles),
                 itemDataIterator=self._iterAngles(fnAngles))
         view = EmPlotter(x=1,
                          y=1,
                          mainTitle="Iteration %d" % it,
                          windowTitle="Angular distribution")
         view.plotAngularDistributionFromMd(fnAnglesSqLite, 'iter %d' % it)
     return view
Exemplo n.º 5
0
    def _createScatterPlot(self, rmax, colorzaxis=False):
        gridsize = self._getGridSize(1)
        xplotter = EmPlotter(x=gridsize[0],
                             y=gridsize[1],
                             windowTitle='Tilt geometry plot')
        plot_title = 'Tilt pair parameter plot'
        a = xplotter.createSubPlot(plot_title,
                                   'Tilt axis',
                                   'Tilt angle',
                                   projection='polar')

        datap, r, theta, zaxis = self._getValues()

        if colorzaxis:
            a.scatter(theta, r, c=zaxis)
        else:
            a.scatter(theta, r)
        a.set_rmax(rmax)

        return xplotter
Exemplo n.º 6
0
    def _createAngDist2D(self, it):
        nrefs = len(self._refsList)
        nparts = self.protocol.inputParticles.get().getSize()
        gridsize = self._getGridSize(nrefs)

        if self.protocol.IS_REFINE:
            data_angularDist = self.protocol._getFileName("output_par",
                                                          iter=it)
            if exists(data_angularDist):
                plotter = EmPlotter(x=gridsize[0],
                                    y=gridsize[1],
                                    mainTitle="Iteration %d" % it,
                                    windowTitle="Angular distribution")
                title = 'iter %d' % it
                sqliteFn = self.protocol._getFileName('projections', iter=it)
                self.createAngDistributionSqlite(
                    sqliteFn,
                    nparts,
                    itemDataIterator=self._iterAngles(it, data_angularDist))
                plotter.plotAngularDistributionFromMd(sqliteFn, title)
                return plotter
            else:
                return
        else:
            for ref3d in self._refsList:
                data_angularDist = self.protocol._getFileName(
                    "output_par_class", iter=it, ref=ref3d)
                if exists(data_angularDist):
                    plotter = EmPlotter(x=gridsize[0],
                                        y=gridsize[1],
                                        mainTitle="Iteration %d" % it,
                                        windowTitle="Angular distribution")
                    title = 'class %d' % ref3d
                    sqliteFn = self.protocol._getFileName('projectionsClass',
                                                          iter=it,
                                                          ref=ref3d)
                    self.createAngDistributionSqlite(
                        sqliteFn,
                        nparts,
                        itemDataIterator=self._iterAngles(
                            it, data_angularDist))
                    plotter.plotAngularDistributionFromMd(sqliteFn, title)
            return plotter
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser(prog='Scipion Plot')
    parser.add_argument('--file', help='File to visualize', required=True)
    parser.add_argument('--block', help='Block to visualize')
    parser.add_argument('--type', help='Plot type')
    parser.add_argument('--columns', help='Columns to plot')
    parser.add_argument('--xcolumn', help='X Column to plot')
    parser.add_argument('--orderColumn', help='Column to order')
    parser.add_argument('--orderDir', help='Order direction(ASC, DESC)')
    parser.add_argument('--bins',
                        help='If plot type is histogram, number of bins')
    parser.add_argument('--colors', help='Colors to plot columns')
    parser.add_argument('--styles', help='Styles to plot columns')
    parser.add_argument('--markers', help='Markers to plot columns')
    parser.add_argument('--title', help='Plot title', default='')
    parser.add_argument('--ytitle', help='Y axis title', default='')
    parser.add_argument('--xtitle', help='X axis title', default='')

    args = parser.parse_args()
    plotfile = args.file
    block = args.block if args.block else ''
    type = args.type
    columns = args.columns
    xcolumn = args.xcolumn
    orderColumn = args.orderColumn
    orderDir = args.orderDir

    bins = args.bins
    colors = args.colors
    styles = args.styles
    markers = args.markers
    title = args.title
    xtitle = args.xtitle
    ytitle = args.ytitle

    Plotter.setBackend('TkAgg')
    plotter = EmPlotter.createFromFile(plotfile, block, type, columns, colors,
                                       styles, markers, xcolumn, ytitle,
                                       xtitle, title, bins, orderColumn,
                                       orderDir)
    plotter.show(block=True)
Exemplo n.º 8
0
def createCtfPlot(ctfSet, ctfId):
    ctfModel = ctfSet[ctfId]
    psdFn = ctfModel.getPsdFile()
    fn = removeExt(psdFn) + "_avrot.txt"
    gridsize = [1, 1]
    xplotter = EmPlotter(x=gridsize[0],
                         y=gridsize[1],
                         windowTitle='CTF Fitting')
    plot_title = "CTF Fitting"
    a = xplotter.createSubPlot(plot_title, 'pixels^-1', 'CTF', yformat=False)

    legendName = [
        'rotational avg. No Astg', 'rotational avg.', 'CTF Fit',
        'Cross Correlation', '2sigma cross correlation of noise'
    ]
    for i in range(1, 6):
        _plotCurve(a, i, fn)
    xplotter.showLegend(legendName)
    a.grid(True)
    xplotter.show()
Exemplo n.º 9
0
    def _createAngDist2D(self, it):
        nrefs = self._getNumberOfRefs()
        gridsize = self._getGridSize(nrefs)
        self.protocol._execEmanProcess(self.protocol._getRun(), it)
        angularDist = self.protocol._getFileName("angles", iter=it)

        if os.path.exists(angularDist):
            xplotter = EmPlotter(x=gridsize[0],
                                 y=gridsize[1],
                                 mainTitle="Iteration %d" % it,
                                 windowTitle="Angular distribution")

            def plot(prefix):
                nparts = self._getNumberOfParticles(it, prefix)
                title = '%s particles' % prefix
                sqliteFn = self.protocol._getFileName('projections',
                                                      iter=it,
                                                      half=prefix)
                self.createAngDistributionSqlite(
                    sqliteFn,
                    nparts,
                    itemDataIterator=self._iterAngles(it, prefix))
                xplotter.plotAngularDistributionFromMd(sqliteFn, title)

            if self.showHalves.get() == HALF_EVEN:
                plot('even')
            elif self.showHalves.get() == HALF_ODD:
                plot('odd')
            elif self.showHalves.get() == FULL_MAP:
                plot('full')
            else:
                for prefix in ['even', 'odd', 'full']:
                    plot(prefix)
            return xplotter
        else:
            return
Exemplo n.º 10
0
    def _plotHistogram(self, param=None):
        md = MetaData()
        md.read(self.protocol._getFileName(FN_METADATA_HISTOGRAM))
        x_axis = []
        y_axis = []

        for idx in md:
            x_axis_ = md.getValue(MDL_X, idx)
            y_axis_ = md.getValue(MDL_COUNT, idx)

            x_axis.append(x_axis_)
            y_axis.append(y_axis_)

        plotter = EmPlotter()
        plotter.createSubPlot("Resolutions Histogram", "Resolution (A)",
                              "# of Counts")
        barwidth = (x_axis[-1] - x_axis[0]) / len(x_axis)

        plotter.plotDataBar(x_axis, y_axis, barwidth)

        return [plotter]
Exemplo n.º 11
0
    def _showFSC(self, paramName=None):
        threshold = self.resolutionThresholdFSC.get()
        gridsize = self._getGridSize(1)
        xplotter = EmPlotter(x=gridsize[0],
                             y=gridsize[1],
                             windowTitle='Resolution FSC')

        plot_title = 'FSC'
        a = xplotter.createSubPlot(plot_title,
                                   'Angstroms^-1',
                                   'FSC',
                                   yformat=False)
        legends = []

        show = False
        for it in self._iterations:
            if self.resolutionPlotsFSC.get() == FSC_UNMASK:
                fscUnmask = self.protocol._getFileName(
                    'fscUnmasked', run=self.protocol._getRun(), iter=it)
                if os.path.exists(fscUnmask):
                    show = True
                    self._plotFSC(a, fscUnmask)
                    legends.append('unmasked map it %d' % it)
                xplotter.showLegend(legends)

            elif self.resolutionPlotsFSC.get() == FSC_MASK:
                fscMask = self.protocol._getFileName(
                    'fscMasked', run=self.protocol._getRun(), iter=it)
                if os.path.exists(fscMask):
                    show = True
                    self._plotFSC(a, fscMask)
                    legends.append('masked map it %d' % it)
                xplotter.showLegend(legends)

            elif self.resolutionPlotsFSC.get() == FSC_MASKTIGHT:
                fscMaskTight = self.protocol._getFileName(
                    'fscMaskedTight', run=self.protocol._getRun(), iter=it)
                if os.path.exists(fscMaskTight):
                    show = True
                    self._plotFSC(a, fscMaskTight)
                    legends.append('masked tight map it %d' % it)
                xplotter.showLegend(legends)
            elif self.resolutionPlotsFSC.get() == FSC_ALL:
                fscUnmask = self.protocol._getFileName(
                    'fscUnmasked', run=self.protocol._getRun(), iter=it)
                fscMask = self.protocol._getFileName(
                    'fscMasked', run=self.protocol._getRun(), iter=it)
                fscMaskTight = self.protocol._getFileName(
                    'fscMaskedTight', run=self.protocol._getRun(), iter=it)
                if os.path.exists(fscUnmask):
                    show = True
                    self._plotFSC(a, fscUnmask)
                    legends.append('unmasked map it %d' % it)
                    self._plotFSC(a, fscMask)
                    legends.append('masked map it %d' % it)
                    self._plotFSC(a, fscMaskTight)
                    legends.append('masked tight map it %d' % it)
                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]
Exemplo n.º 12
0
    def _visualizeHistogram(self, e=None):
        views = []
        numberOfBins = self.visualizeHistogram.get()
        if hasattr(self.protocol, "outputCTF"):
            numberOfBins = min(numberOfBins, self.protocol.outputCTF.getSize())
            plotter = EmPlotter()
            plotter.createSubPlot("Resolution Discrepancies histogram",
                                  "Resolution (A)", "# of Comparisons")
            resolution = [ctf.getResolution() for ctf in
                          self.protocol.outputCTF]
            plotter.plotHist(resolution, nbins=numberOfBins)
            views.append(plotter)

        if hasattr(self.protocol, "outputCTFDiscarded"):
            numberOfBins = min(numberOfBins,
                               self.protocol.outputCTFDiscarded.getSize())
            plotter = EmPlotter()
            plotter.createSubPlot(
                "Resolution Discrepancies histogram (discarded)",
                "Resolution (A)", "# of Comparisons")
            resolution = [ctf.getResolution() for ctf in
                          self.protocol.outputCTFDiscarded]
            plotter.plotHist(resolution, nbins=numberOfBins)
            views.append(plotter)
        return views
Exemplo n.º 13
0
    def _showFSC(self, paramName=None):
        threshold = self.resolutionThresholdFSC.get()
        nrefs = len(self._refsList)
        gridsize = self._getGridSize(nrefs)
        xplotter = EmPlotter(x=gridsize[0],
                             y=gridsize[1],
                             windowTitle='Resolution FSC')

        if self.protocol.IS_REFINE:
            plot_title = 'FSC'
            a = xplotter.createSubPlot(plot_title,
                                       'Angstroms^-1',
                                       'FSC',
                                       yformat=False)
            legends = []

            show = False
            for it in self._iterations:
                parFn = self.protocol._getFileName('output_vol_par', iter=it)
                if exists(parFn):
                    show = True
                    self._plotFSC(a, parFn)
                    legends.append('iter %d' % it)
            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")
        else:
            for ref3d in self._refsList:
                plot_title = 'class %s' % ref3d
                a = xplotter.createSubPlot(plot_title,
                                           'Angstroms^-1',
                                           'FSC',
                                           yformat=False)
                legends = []

                for it in self._iterations:
                    parFn = self.protocol._getFileName('output_vol_par_class',
                                                       iter=it,
                                                       ref=ref3d)
                    if exists(parFn):
                        show = True
                        self._plotFSC(a, parFn)
                        legends.append('iter %d' % it)
                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]