Exemple #1
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
 def _plotHistogram(self, param=None):
     imageFile = self.protocol._getFileName(FN_RESOLMAP)
     img = ImageHandler().read(imageFile)
     imgData = img.getData()
     imgList = imgData.flatten()
     imgListNoZero = filter(lambda x: x > 0, imgList)
     nbins = 30
     plotter = EmPlotter(x=1, y=1, mainTitle="  ")
     plotter.createSubPlot("Resolution histogram",
                           "Resolution (A)", "# of Counts")
     plotter.plotHist(list(imgListNoZero), nbins)
     return [plotter]
 def _plotHistogram(self, param=None):
     imageFile = self.protocol._getFileName(RESMAP_VOL)
     img = ImageHandler().read(imageFile)
     imgData = img.getData()
     imgList = imgData.flatten()
     imgDataMax = self.getBackGroundValue(imgList)
     imgListNoZero = filter(lambda x: 0 < x < imgDataMax, imgList)
     nbins = 30
     plotter = EmPlotter(x=1, y=1, mainTitle="  ")
     plotter.createSubPlot("Resolution histogram", "Resolution (A)",
                           "# of Counts")
     plotter.plotHist(imgListNoZero, nbins)
     return [plotter]
    def _showHistogram(self, param=None):
        fn = self.protocol._getFileName('output_hist')
        with open(fn) as f:
            views = []
            numberOfBins = 10
            plotter = EmPlotter()
            plotter.createSubPlot("PSF Resolution histogram", "Resolution (A)",
                                  "Ang (str)")
            resolution = [float(line.strip()) for line in f]
        plotter.plotHist(resolution, nbins=numberOfBins)
        plotter.show()

        return views.append(plotter)
def plotMultiHistogram(valuesList,
                       colors=None,
                       legend=None,
                       numOfBins=100,
                       plotter=None,
                       views=None,
                       includeEmpties=False):
    """ Values list must be a n-list of list,
        where n is the number of the subhistograms to plot.
        Multiple histograms will be plot in the same chart
        If no views is passed, a new list-views will be returned with the hist.
        If no plotter is passed, a new generic one will be created.
    """

    if not all([isinstance(x, list) for x in valuesList]):
        print("Not all items in values list are lists. Returning...")
        return

    if colors is None:
        from matplotlib import colors
        from random import shuffle
        colors = colors.cnames.keys()
        shuffle(colors)

    if any([len(x) for x in valuesList]):
        if plotter is None:
            plotter = EmPlotter()
            plotter.createSubPlot("Histogram", "Score", "# of Items")

        w1 = None
        finalLegend = []
        for idx, values in enumerate(valuesList):
            if values or includeEmpties:
                if w1 is None:
                    w1 = (max(values) - min(values)) / numOfBins
                else:
                    numOfBins = int((max(values) - min(values)) / w1)

                plotter.plotHist(values, nbins=numOfBins, color=colors[idx])
                if legend:
                    finalLegend.append(legend[idx])

        if finalLegend:
            plotter.legend(labels=finalLegend)

        if views is None:
            views = [plotter]
        else:
            views.append(plotter)

        return views
Exemple #6
0
    def _visualizeHistogram(self, e=None):
        views = []
        numberOfBins = self.visualizeHistogram.get()

        outCoords = self.protocol.getOutput()
        if outCoords:
            mdLabel = emlib.MDL_GOOD_REGION_SCORE
            if getXmippAttribute(outCoords.getFirstItem(), mdLabel):
                plotter = EmPlotter()
                plotter.createSubPlot("Deep micrograph score",
                                      "Deep micrograph score",
                                      "Number of Coordinates")
                cScores = [getXmippAttribute(coord, mdLabel).get()
                           for coord in outCoords]
                plotter.plotHist(cScores, nbins=numberOfBins)
                views.append(plotter)
            else:
                print(" > 'outputCoordinates' don't have 'xmipp_zScoreDeepLearning2' label.")
        else:
            print(" > Output not ready yet.")

        return views