def _showBFactorPlot(self, key): if key == 'guinier': label = 'rlnFittedInterceptGuinierPlot' title = "Polishing scale-factors" else: # bfactor label = 'rlnBfactorUsedForSharpening' title = "Polishing B-factors" modelStar = self.protocol._getFileName('bfactors') if os.path.exists(modelStar): table = Table(fileName=modelStar, tableName='perframe_bfactors') frame = table.getColumnValues('rlnMovieFrameNumber') bfactor = map(float, table.getColumnValues(label)) plotter = Plotter() figure = plotter.getFigure() a = figure.add_subplot(111) a.grid(True) a.set_xlabel('Movie frame number') a.set_ylabel(label) a.invert_yaxis() a.plot(frame, list(bfactor)) a.set_title(title) plotter.tightLayout() return [plotter]
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Global shift') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') i = first skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in izip(meanX, meanY): if labelTick == 1: ax.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(meanX, meanY, color='b') ax.plot(meanX, meanY, 'yo') plotter.tightLayout() return plotter
def createAlignmentPlot(meanX, meanY): """ Create a plotter with the cumulative shift per frame. """ figureSize = (8, 6) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.axis('equal') ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') # Max range of the plot of the two coordinates plotRange = max(max(meanX) - min(meanX), max(meanY) - min(meanY)) i = 1 skipLabels = ceil(len(meanX) / 10.0) for x, y in izip(meanX, meanY): if i % skipLabels == 0: ax.text(x - 0.02 * plotRange, y + 0.02 * plotRange, str(i)) i += 1 ax.plot(meanX, meanY, color='b') ax.plot(meanX, meanY, 'yo') # setting the plot windows to properly see the data ax.axis([min(meanX) - 0.1 * plotRange, max(meanX) + 0.1 * plotRange, min(meanY) - 0.1 * plotRange, max(meanY) + 0.1 * plotRange]) plotter.tightLayout() return plotter
def createAlignmentPlot(meanX, meanY): """ Create a plotter with the cumulative shift per frame. """ sumMeanX = [] sumMeanY = [] figureSize = (8, 6) plotter = Plotter(*figureSize) figure = plotter.getFigure() preX = 0.0 preY = 0.0 sumMeanX.append(0.0) sumMeanY.append(0.0) ax = figure.add_subplot(111) ax.grid() ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') ax.plot(0, 0, 'yo-') i = 1 for x, y in izip(meanX, meanY): preX += x preY += y sumMeanX.append(preX) sumMeanY.append(preY) #ax.plot(preX, preY, 'yo-') ax.text(preX-0.02, preY+0.02, str(i)) i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def plotFile(dbName, dbPreffix, plotType, columnsStr, colorsStr, linesStr, markersStr, xcolumn, ylabel, xlabel, title, bins, orderColumn, orderDirection): columns = columnsStr.split() colors = colorsStr.split() lines = linesStr.split() markers = markersStr.split() data = PlotData(dbName, dbPreffix, orderColumn, orderDirection) #setObj = getSetObject(dbName, dbPreffix) plotter = Plotter(windowTitle=title) ax = plotter.createSubPlot(title, xlabel, ylabel) xvalues = data.getColumnValues(xcolumn) if xcolumn else range(0, data.getSize()) #xvalues = range(0, setObj.getSize()) if not isxvalues else [] for i, col in enumerate(columns): yvalues = data.getColumnValues(col) color = colors[i] line = lines[i] if bins: ax.hist(yvalues, bins=int(bins), color=color, linestyle=line, label=col) else: if plotType == 'Plot': marker = (markers[i] if not markers[i] == 'none' else None) ax.plot(xvalues, yvalues, color, marker=marker, linestyle=line, label=col) else: ax.scatter(xvalues, yvalues, c=color, label=col, alpha=0.5) ax.legend(columns) return plotter
def createPlot2D(self, volPrefix, md): import xmipp figurePath = self._getExtraPath(volPrefix + 'softAlignmentValidation2D.png') figureSize = (8, 6) #alignedMovie = mic.alignMetaData plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Soft alignment validation map') ax.set_xlabel('Angular Precision') ax.set_ylabel('Angular Accuracy') for objId in md: x = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, objId) y = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, objId) ax.plot(x, y, 'r.', markersize=1) ax.grid(True, which='both') ax.autoscale_view(True, True, True) plotter.savefig(figurePath) plotter.show() return plotter
def movieCreatePlot(mic, saveFig): import xmipp meanX = [] meanY = [] figureSize = (8, 6) #alignedMovie = mic.alignMetaData md = xmipp.MetaData(mic.alignMetaData) plotter = Plotter(*figureSize) figure = plotter.getFigure() preX = 0.0 preY = 0.0 meanX.append(0.0) meanY.append(0.0) ax = figure.add_subplot(111) ax.grid() ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') ax.plot(0, 0, 'yo-') for objId in md: preX += md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId) preY += md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId) meanX.append(preX) meanY.append(preY) ax.plot(preX, preY, 'yo-') ax.text(preX - 0.02, preY + 0.01, str(objId + 1)) ax.plot(np.asarray(meanX), np.asarray(meanY)) if saveFig: plotter.savefig(mic.plotCart) return plotter
def createFromFile(cls, dbName, dbPreffix, plotType, columnsStr, colorsStr, linesStr, markersStr, xcolumn, ylabel, xlabel, title, bins, orderColumn, orderDirection): columns = columnsStr.split() colors = colorsStr.split() lines = linesStr.split() markers = markersStr.split() data = PlotData(dbName, dbPreffix, orderColumn, orderDirection) plotter = Plotter(windowTitle=title) ax = plotter.createSubPlot(title, xlabel, ylabel) xvalues = data.getColumnValues(xcolumn) if xcolumn else range(0, data.getSize()) for i, col in enumerate(columns): yvalues = data.getColumnValues(col) color = colors[i] line = lines[i] colLabel = col if not col.startswith("_") else col[1:] if bins: yvalues = data._removeInfinites(yvalues) ax.hist(yvalues, bins=int(bins), color=color, linestyle=line, label=colLabel) else: if plotType == 'Plot': marker = (markers[i] if not markers[i] == 'none' else None) ax.plot(xvalues, yvalues, color, marker=marker, linestyle=line, label=colLabel) else: ax.scatter(xvalues, yvalues, c=color, label=col, alpha=0.5) ax.legend() return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the cumulative shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Global frame shift (cumulative)') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') if meanX[0] != 0 or meanY[0] != 0: raise Exception("First frame shift must be (0,0)!") i = first for x, y in izip(meanX, meanY): preX += x preY += y sumMeanX.append(preX) sumMeanY.append(preY) ax.text(preX - 0.02, preY + 0.02, str(i)) i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def _plotHistogram(self, param=None): md = MetaData() md.read(self.protocol._getFileName(FN_METADATA_HISTOGRAM)) x_axis = [] y_axis = [] i = 0 for idx in md: x_axis_ = md.getValue(MDL_X, idx) if i == 0: x0 = x_axis_ elif i == 1: x1 = x_axis_ y_axis_ = md.getValue(MDL_COUNT, idx) i += 1 x_axis.append(x_axis_) y_axis.append(y_axis_) delta = x1 - x0 fig = plt.figure() plt.bar(x_axis, y_axis, width=delta) plt.title("Resolutions Histogram") plt.xlabel("Resolution (A)") plt.ylabel("Counts") return [Plotter(figure2=fig)]
def _plotResMapSlices(self, data=None, **kwargs): from ResMap_visualization import plotResMapVolume plotDict = loads(self.plotData.get()) if data is None: data = self._getVolumeMatrix('volume1_resmap.map') data = np.ma.masked_where(data > plotDict['currentRes'], data, copy=True) kwargs.update(plotDict) fig = plotResMapVolume(data, **kwargs) return Plotter(figure=fig)
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] def px_to_ang(px): y1, y2 = px.get_ylim() x1, x2 = px.get_xlim() ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize) ax_ang.set_xlim(x1 * pixSize, x2 * pixSize) ax_ang.figure.canvas.draw() ax_ang2.figure.canvas.draw() figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax_px = figure.add_subplot(111) ax_px.grid() ax_px.set_xlabel('Shift x (px)') ax_px.set_ylabel('Shift y (px)') ax_ang = ax_px.twiny() ax_ang.set_xlabel('Shift x (A)') ax_ang2 = ax_px.twinx() ax_ang2.set_ylabel('Shift y (A)') i = first # The output and log files list the shifts relative to the first frame. # ROB unit seems to be pixels since sampling rate is only asked # by the program if dose filtering is required skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in zip(meanX, meanY): sumMeanX.append(x) sumMeanY.append(y) if labelTick == 1: ax_px.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 # automatically update lim of ax_ang when lim of ax_px changes. ax_px.callbacks.connect("ylim_changed", px_to_ang) ax_px.callbacks.connect("xlim_changed", px_to_ang) ax_px.plot(sumMeanX, sumMeanY, color='b') ax_px.plot(sumMeanX, sumMeanY, 'yo') ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5) ax_px.set_title('Global frame alignment') plotter.tightLayout() return plotter
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] def px_to_ang(ax_px): y1, y2 = ax_px.get_ylim() x1, x2 = ax_px.get_xlim() ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize) ax_ang.set_xlim(x1 * pixSize, x2 * pixSize) ax_ang.figure.canvas.draw() ax_ang2.figure.canvas.draw() figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax_px = figure.add_subplot(111) ax_px.grid() ax_px.set_xlabel('Shift x (px)') ax_px.set_ylabel('Shift y (px)') ax_ang = ax_px.twiny() ax_ang.set_xlabel('Shift x (A)') ax_ang2 = ax_px.twinx() ax_ang2.set_ylabel('Shift y (A)') i = first # The output _rlnMicrographShiftX/Y shifts relative to the first frame. # Unit is pixels of the original (unbinned) movies (Takanori, 2018) skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in zip(meanX, meanY): sumMeanX.append(x) sumMeanY.append(y) if labelTick == 1: ax_px.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 # automatically update lim of ax_ang when lim of ax_px changes. ax_px.callbacks.connect("ylim_changed", px_to_ang) ax_px.callbacks.connect("xlim_changed", px_to_ang) ax_px.plot(sumMeanX, sumMeanY, color='b') ax_px.plot(sumMeanX, sumMeanY, 'yo') ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5) ax_px.set_title('Global frame alignment') plotter.tightLayout() return plotter
def getTestPlot(request): """ Just a test of a custom render function. """ from pyworkflow.gui.plotter import Plotter xplotter = Plotter() xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") x = range(100) xplotter.plot(x) canvas = xplotter.getCanvas() response = HttpResponse(content_type='image/png') canvas.print_png(response) return response
def _runPreWhiteningWeb(protocol, results): newAng = protocol.prewhitenAng.get() newRamp = protocol.prewhitenRamp.get() figsize = (18, 9) gridsize = [0, 0] plotter = Plotter(*gridsize, figsize=figsize, windowTitle="ResMap") myCreatePrewhiteningFigure(results, plotter.getFigure(), newAng, newRamp) return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Alignment based upon full frames') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') # morioncor2 (1.0.2) values refer to the middle frame, so first frame is no longer 0,0 #if meanX[0] != 0 or meanY[0] != 0: # raise Exception("First frame shift must be (0,0)!") i = first # ROB no accumulation is needed # see Motioncor2 user manual: "The output and log files list the shifts relative to the first frame." # or middle frame for motioncor2 1.0.2 # ROB unit seems to be pixels since samplingrate is only asked by the program if # dose filtering is required skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in izip(meanX, meanY): #preX += x #preY += y preX = x preY = y sumMeanX.append(preX) sumMeanY.append(preY) if labelTick == 1: ax.text(preX - 0.02, preY + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def _plotGrid(self, grid, x, y): plotter = Plotter(windowTitle="Acquisitions for grid %s" % grid) plt = plotter.createSubPlot("Locations", "X", "Y") plt.axis('scaled') plt.autoscale(tight=True) self.loadAtlasImg(plt, grid) colors = ["cyan"] * len(x) area = np.pi * 3 plotter.scatterP(x, y, s=area, c=colors, edgecolors='none', alpha=1) return plotter
def _visualizeLLPlot(self, e=None): """ Plot -LL vs cycle :N:1,5: """ headerList, dataList, msg, title = self.parseFile.retrievemLLPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], '-LL', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html a.plot(dataList[0], dataList[1], 'bx-') xplotter.showLegend(headerList[1:]) xplotter.show()
def _createSpectraPlot(self, label, array, index, objId=None): if objId is None: objId = index # Number of harmonics calculated plotter = Plotter() a = plotter.createSubPlot('Spectrum for %s %d' % (label, objId), xlabel='Harmonics', ylabel='Energy') n = self.spectraHighHarmonic.get() - self.spectraLowHarmonic.get() + 1 i1 = (index-1) * n i2 = i1 + n xdata = range(self.spectraLowHarmonic.get(), self.spectraHighHarmonic.get()+1) ydata = array[i1:i2] a.plot(xdata, ydata) plotFile = join(self.plotsDir, 'spectra_%s%06d.png' % (label, objId)) plotter.savefig(plotFile) return plotFile
def visualize(self, obj, **args): cls = type(obj) if issubclass(cls, AtsasProtConvertPdbToSAXS): if obj.experimentalSAXS.empty(): fnInt=obj._getPath("pseudoatoms00.int") else: fnInt=obj._getPath("pseudoatoms00.fit") import numpy x=numpy.loadtxt(fnInt,skiprows=1) xplotter = Plotter(windowTitle="SAXS Curves") a = xplotter.createSubPlot('SAXS curves', 'Angstrongs^-1', 'log(SAXS)', yformat=False) a.plot(x[:,0], numpy.log(x[:,1])) a.plot(x[:,0], numpy.log(x[:,2])) if obj.experimentalSAXS.empty(): xplotter.showLegend(['SAXS in solution','SAXS in vacuo']) else: xplotter.showLegend(['Experimental SAXS','SAXS from volume']) xplotter.show()
def _visualizeRFactorPlot(self, e=None): """ Plot Rfactor and Rfree vs cycle :N:[1,3]: """ headerList, dataList, msg, title = self.parseFile.retrieveRFactorPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], 'Rfactor', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html # for plot options a.plot(dataList[0], dataList[1], 'bx-', dataList[0], dataList[2], 'gx-') # plot start over line in blue xplotter.showLegend(headerList[1:]) xplotter.show()
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Alignment based upon full frames') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') i = first skipLabels = ceil(len(meanX)/10.0) labelTick = 1 for x, y in izip(meanX, meanY): preX = x preY = y sumMeanX.append(preX) sumMeanY.append(preY) if labelTick == 1: ax.text(preX - 0.02, preY + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def _visualizeGeometryPlot(self, e=None): """ Plot rmsBOND,zBOND, rmsANGL, zANGL and rmsCHIRALvs cycle : N:1,7,8,9,10,11: """ headerList, dataList, msg, title = \ self.parseFile.retrieveGeometryPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], 'geometry', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html # for plot options a.plot( dataList[0], dataList[1], 'bx-', dataList[0], dataList[2], 'gx-', dataList[0], dataList[3], 'rx-', dataList[0], dataList[4], 'cx-', dataList[0], dataList[5], 'mx-', ) # plot start over line in blue xplotter.showLegend(headerList[1:]) xplotter.show()
def _plotHistogram(self): from ResMap_visualization import plotResolutionHistogram histogramData = loads(self.histogramData.get()) fig = plotResolutionHistogram(histogramData) return Plotter(figure=fig)
def _plotVolumeSlices(self, **kwargs): from ResMap_visualization import plotOriginalVolume fig = plotOriginalVolume(self._getVolumeMatrix('volume1.map'), **kwargs) return Plotter(figure=fig)