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 _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 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 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 _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 _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 _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 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()
def launchML2DPlots(protML, selectedPlots): ''' Launch some plot for an ML2D protocol run ''' #import matplotlib import numpy as np from protlib_gui_figure import XmippPlotter protML._plot_count = 0 lastIter = lastIteration(protML) if lastIter == 0: return refs = protML.getFilename('iter_refs', iter=lastIter) # 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) return elif n == 1: gridsize = [1, 1] elif n == 2: gridsize = [2, 1] else: gridsize = [2, 2] xplotter = XmippPlotter(*gridsize) # Create data to plot iters = range(1, lastIter+1) ll = [] pmax = [] for iter in iters: logs = protML.getFilename('iter_logs', iter=iter) md = MetaData(logs) id = md.firstObject() ll.append(md.getValue(MDL_LL, id)) pmax.append(md.getValue(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 = MetaData(refs) mirrors = [md.getValue(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', 'references', '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 = MetaData() for iter in iters: fn = protML.getFilename('iter_refs', iter=iter) md2 = MetaData(fn) md2.fillConstant(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 = MetaData() md2.aggregate(md, AGGR_MAX, MDL_ITER, MDL_SIGNALCHANGE, MDL_MAX) signal_change = [md2.getValue(MDL_MAX, id) for id in md2] xplotter.createSubPlot('Maximum signal change', 'iterations', 'signal change') xplotter.plot(iters, signal_change, color='green') return xplotter