def _visualizeAvgPMAX(self): addRelionLabels() mdIters = MetaData() iterations = range(self.firstIter(), self._visualizeLastIteration+1) labels = [MDL_AVGPMAX, MDL_PMAX] colors = ['g', 'b'] prefixes = self._getPrefixes() for it in iterations: # range (firstIter,self._visualizeLastIteration+1): #alwaya list all iteration objId = mdIters.addObject() mdIters.setValue(MDL_ITER, it, objId) for i, prefix in enumerate(prefixes): fn = 'model_general@'+ self.getFilename(prefix + 'model', iter=it) md = MetaData(fn) pmax = md.getValue(MDL_AVGPMAX, md.firstObject()) mdIters.setValue(labels[i], pmax, objId) fn = self.getFilename('all_avgPmax_xmipp') mdIters.write(fn) #self.display2D(fn, extraParams='--label_relion') //do not display table since labels are confussing xplotter = XmippPlotter() xplotter.createSubPlot("Avg PMax per Iterations", "Iterations", "Avg PMax") for label, color in zip(labels, colors): xplotter.plotMd(mdIters, MDL_ITER, label, color) if len(prefixes) > 1: xplotter.showLegend(prefixes) xplotter.show(True)
def _visualizeDisplayResolutionPlotsSSNR(self): names = [] windowTitle = {} prefixes = self._getPrefixes() n = len(prefixes) * self._visualizeNrefs gridsize = self._getGridSize(n) addRelionLabels() activateMathExtensions() xplotter = XmippPlotter(*gridsize) for prefix in prefixes: for ref3d in self._visualizeRef3Ds: plot_title = 'Resolution SSNR %s, for Class %s' % (prefix, ref3d) a = xplotter.createSubPlot(plot_title, 'Armstrongs^-1', 'log(SSNR)', yformat=False) blockName = 'model_class_%d@' % ref3d legendName = [] for it in self._visualizeIterations: file_name = blockName + self.getFilename(prefix + 'model', iter=it) #file_name = self.getFilename('ResolutionXmdFile', iter=it, ref=ref3d) self._plotSSNR(a, file_name) legendName.append('iter %d' % it) xplotter.showLegend(legendName) a.grid(True) xplotter.show(True)
def _visualizeDisplayAngularDistribution(self): self.SpheresMaxradius = float(self.parser.getTkValue('SpheresMaxradius')) self.DisplayAngularDistribution = self.parser.getTkValue('DisplayAngularDistribution') if self.DisplayAngularDistribution == 'chimera': outerRadius = int(float(self.MaskRadiusA)/self.SamplingRate) radius = float(outerRadius) * 1.1 for it in self._visualizeIterations: data_angularDist = self._getIterAngularDist(it) for ref3d in self._visualizeRef3Ds: for prefix in self._getPrefixes(): volFn = self.getFilename(prefix + 'volume', iter=it, ref3d=ref3d) args = " --mode projector 256 -a %sclass%06d_angularDist@%s red %f " % (prefix, ref3d, data_angularDist, radius) if self.SpheresMaxradius > 0: args += ' %f ' % self.SpheresMaxradius print "runChimeraClient(%s, %s) " % (volFn, args) runChimeraClient(volFn, args) elif self.DisplayAngularDistribution == "2D plots": n = self._visualizeNrefs * len(self._getPrefixes()) gridsize = self._getGridSize(n) for it in self._visualizeIterations: data_angularDist = self._getIterAngularDist(it) xplotter = XmippPlotter(*gridsize, mainTitle='Iteration %d' % it, windowTitle="Angular Distribution") for ref3d in self._visualizeRef3Ds: for prefix in self._getPrefixes(): md = MetaData("class%06d_angularDist@%s" % (ref3d, data_angularDist)) plot_title = '%sclass %d' % (prefix, ref3d) xplotter.plotAngularDistribution(plot_title, md) xplotter.show(interactive=True)
def _visualizeDisplayResolutionPlotsFSC(self): self.ResolutionThreshold = float(self.parser.getTkValue('ResolutionThreshold')) n = self._visualizeNrefs * len(self._getPrefixes()) gridsize = self._getGridSize(n) activateMathExtensions() addRelionLabels() xplotter = XmippPlotter(*gridsize, windowTitle='Resolution FSC') for prefix in self._getPrefixes(): for ref3d in self._visualizeRef3Ds: plot_title = prefix + 'class %s' % ref3d a = xplotter.createSubPlot(plot_title, 'Armstrongs^-1', 'FSC', yformat=False) legends = [] blockName = 'model_class_%d@' % ref3d for it in self._visualizeIterations: model_star = blockName + self.getFilename(prefix + 'model', iter=it) if self._plotFSC(a, model_star): legends.append('iter %d' % it) xplotter.showLegend(legends) if self.ResolutionThreshold < self.maxFrc: a.plot([self.minInv, self.maxInv],[self.ResolutionThreshold, self.ResolutionThreshold], color='black', linestyle='--') a.grid(True) xplotter.show(True)
def _visualizeLikelihood(self): for it in self._visualizeIterations: fn = self._getIterSortedData(it) md = MetaData(fn) self.display2D(fn) xplotter = XmippPlotter(windowTitle="max Likelihood particles sorting Iter_%d"%it) xplotter.createSubPlot("Particle sorting: Iter_%d" % it, "Particle number", "maxLL") xplotter.plotMd(md, False, mdLabelY=MDL_LL) xplotter.show(True)
def run(self): from xmipp import MetaData, str2Label from protlib_gui_figure import XmippPlotter md = MetaData(self.getParam('-i')) if self.checkParam('--xlabel'): xlabel = self.getParam('--xlabel') mdLabelX = str2Label(xlabel) else: xlabel = "" mdLabelX = None if self.checkParam('--xtitle'): xlabel = self.getParam('--xtitle') ylabels = self.getParam('--ylabel').split() if self.checkParam('--ytitle'): ylabel = self.getParam('--ytitle') else: ylabel = ylabels[0] colors, lenColors = self.getList('--colors', ['g', 'b', 'r', 'y', 'c', 'm', 'k']) markers, lenMarkers = self.getList('--markers') styles, lenStyles = self.getList('--style') if self.checkParam('--nbins'): nBins = self.getIntParam('--nbins') else: nBins = None title = self.getParam('--title') xplotter = XmippPlotter() xplotter.createSubPlot(title, xlabel, ylabel) for i, l in enumerate(ylabels): c = colors[i % lenColors] m = markers[i % lenMarkers] if m == "none": m = None s = styles[i % lenStyles] if s == "none": s = None xplotter.plotMd(md, mdLabelX, str2Label(l), color=c, marker=m, linestyle=s, nbins=nBins) # if nbins is present do an histogram legendLocation = self.getParam('--legend') if legendLocation != 'none': xplotter.showLegend(ylabels, loc=legendLocation.replace('_', ' ')) xplotter.show()
def run(self): from xmipp import MetaData, str2Label from protlib_gui_figure import XmippPlotter md = MetaData(self.getParam('-i')) if self.checkParam('--xlabel'): xlabel = self.getParam('--xlabel') mdLabelX = str2Label(xlabel) else: xlabel = "" mdLabelX = None if self.checkParam('--xtitle'): xlabel = self.getParam('--xtitle') ylabels = self.getParam('--ylabel').split() if self.checkParam('--ytitle'): ylabel = self.getParam('--ytitle') else: ylabel = ylabels[0] colors, lenColors = self.getList('--colors', ['g', 'b', 'r', 'y', 'c', 'm', 'k']) markers, lenMarkers = self.getList('--markers') styles, lenStyles = self.getList('--style') if self.checkParam('--nbins'): nBins = self.getIntParam('--nbins') else: nBins = None title = self.getParam('--title') xplotter = XmippPlotter() xplotter.createSubPlot(title, xlabel, ylabel) for i, l in enumerate(ylabels): c = colors[i % lenColors] m = markers[i % lenMarkers] if m == "none": m = None s = styles[i % lenStyles] if s == "none": s = None xplotter.plotMd(md, mdLabelX, str2Label(l), color=c, marker=m, linestyle=s, nbins=nBins)#if nbins is present do an histogram legendLocation = self.getParam('--legend') if legendLocation != 'none': xplotter.showLegend(ylabels, loc=legendLocation.replace('_', ' ')) xplotter.show()
def visualize(self): if self.ExperimentalSAXS=="": fnInt=self.workingDirPath("pseudoatoms00.int") else: fnInt=self.workingDirPath("pseudoatoms00.fit") import numpy x=numpy.loadtxt(fnInt,skiprows=1) xplotter = XmippPlotter(*[1,1],windowTitle="SAXS Curves") a = xplotter.createSubPlot('SAXS curves', 'Armstrongs^-1', 'log(SAXS)', yformat=False) a.plot(x[:,0], numpy.log(x[:,1])) a.plot(x[:,0], numpy.log(x[:,2])) if self.ExperimentalSAXS=="": xplotter.showLegend(['SAXS in solution','SAXS in vacuo']) else: xplotter.showLegend(['Experimental SAXS','SAXS from volume']) xplotter.draw() xplotter.show()
def visualize(self): fn = self.getFilename('images') if exists(fn): from protlib_utils import runShowJ if getattr(self, 'TiltPairs', False): runShowJ(fn,extraParams="--mode metadata --render first") else: runShowJ(fn) from protlib_gui_figure import XmippPlotter from xmipp import MDL_ZSCORE md = MetaData(fn) if md.containsLabel(MDL_ZSCORE): #MD.sort(MDL_ZSCORE) xplotter = XmippPlotter(windowTitle="Zscore particles sorting") xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") xplotter.plotMd(md, False, mdLabelY=MDL_ZSCORE) xplotter.show()
def showDependencyTree(runsDict): ''' This function will create a figure with a dependency tree between the runs of the project ''' from protlib_gui_figure import XmippPlotter import matplotlib.lines as mlines XSIZE, YSIZE = 8, 6 DPI = 100 XDIM, YDIM = XSIZE*DPI, YSIZE*DPI DY = 56 DX = 50 FONT = "sans-serif" FONTSIZE = 9 colors = ['#D9F1FA', '#D9F1FA', '#FCCE62', '#D2F5CB', '#F5CCCB', '#F3F5CB', '#416FF0'] xplotter = XmippPlotter(figsize=(XSIZE, YSIZE), dpi=100, windowTitle='Runs dependencies TREE') # Store the right horizontal x position for better packaging of # the graph, assuming max of 100 y-levels from numpy import zeros hLimits = zeros(100) #a = xplotter.createSubPlot("Test", "Particle number", "Zscore") a = xplotter.createCanvas() a.set_xlim(0, XDIM) a.set_ylim(top=0, bottom=YDIM) def showNode(dd, x, y): if dd.prot is None: nodeText = dd.extRunName else: nodeText = "%s\n%s" % (dd.protName, dd.runName) t = a.text(x, y, nodeText, family=FONT, size=FONTSIZE, bbox = dict(boxstyle="round", fc=colors[dd.state])) xplotter.draw() box = t.get_bbox_patch() dd.width = box.get_width() dd.height = box.get_height() dd.start = x return t def showLevel(dd, level): y = level * DY if len(dd.deps): #width = (xmax - xmin) / n childs = [runsDict[rn] for rn in dd.deps] for c in childs: showLevel(c, level + 1) firstChild = childs[0] lastChild = childs[-1] t = showNode(dd, 0, y) dd.start = (lastChild.start + lastChild.width + firstChild.start - dd.width) / 2 dd.start = max(dd.start, hLimits[level] + DX) t.set_position((dd.start, y)) hLimits[level] = dd.start + dd.width xx = [dd.start + dd.width/2, 0] yy = [y + dd.height - 18, 0] for c in childs: xx[1] = c.start + c.width/2 yy[1] = y + DY - c.height a.add_line(mlines.Line2D(xx, yy, lw=2., alpha=0.4)) else: t = showNode(dd, hLimits[level] + DX, y) hLimits[level] = dd.start + dd.width root = runsDict['PROJECT'] showLevel(root, 0) xplotter.show()