def _plotFactorMaps(self, param=None): # Parse the file fn = self.protocol._getFileName('imcFile') f = open(fn) values = f.readline().split() n = int(values[0]) # Number of images nf = int(values[1]) # Number of factors x = self.firstFactor.get() y = self.secondFactor.get() xFactors = [] yFactors = [] i = 0 while i < n: imgFactors = [] while len(imgFactors) < nf: values = f.readline().split() imgFactors += [float(v) for v in values] xFactors.append(imgFactors[x-1]) yFactors.append(imgFactors[y-1]) i += 1 f.close() # Create the plot xplotter = EmPlotter(1,1) a = xplotter.createSubPlot("Factor %d vs %d" % (x, y), "Factor %d" % x, "Factor %d" % y) a.plot(xFactors, yFactors, 'o') return [xplotter]
def paint(self, labels): for label in labels: if (label == 'standard_deviation'): self.lines[label], = \ self.ax2.plot([], [], '-o', label='Standard deviation', color='r') if (label == 'ratio1'): self.lines[label], = \ self.ax.plot([], [], '-o', label='97.5/2.5 percentile', color='b') if (label == 'ratio2'): self.lines[label], = \ self.ax.plot([], [], '-*', label='max/97.5 percentile', color='b') anim = animation.FuncAnimation(self.fig, self.animate, interval=self.monitor.samplingInterval * 1000) #miliseconds self.fig.canvas.mpl_connect('scroll_event', self.onscroll) self.fig.canvas.mpl_connect('key_press_event', self.press) EmPlotter.show(self)
def _displayAngDist(self, *args): #print "_displayAngDist...." iterations = self._getIterations() nparts = self.protocol.inputParticles.get().getSize() views = [] if self.displayAngDist == ANGDIST_2DPLOT: #print " self.displayAngDist == ANGDIST_2DPLO " for it in iterations: anglesSqlite = self._getFinalPath('angular_dist_%03d.sqlite' % it) title = 'Angular distribution iter %03d' % it plotter = EmPlotter(x=1, y=1, windowTitle=title) self.createAngDistributionSqlite( anglesSqlite, nparts, itemDataIterator=self._iterAngles(it)) plotter.plotAngularDistributionFromMd(anglesSqlite, title) views.append(plotter) else: it = iterations[-1] print "Using last iteration: ", it anglesSqlite = self._getFinalPath('angular_dist_%03d.sqlite' % it) self.createAngDistributionSqlite( anglesSqlite, nparts, itemDataIterator=self._iterAngles(it)) volumes = self.getVolumeNames(it) views.append( em.ChimeraClientView( volumes[0], showProjection=True, angularDistFile=anglesSqlite, spheresDistance=2)) #self.spheresScale.get())) return views
def _visualize(self, obj, **kwargs): fnResults = self.protocol._getPath("results.txt") if exists(fnResults): X, Y, _, _ = self.protocol.getXYValues(False) minX = min(X) maxX = max(X) step = (maxX - minX) / 50 xValues = np.arange(minX, maxX + step, step) yValues = self.protocol.evalFunction(xValues) plotter = EmPlotter() varNameX = self.protocol.labelX.get() varNameY = self.protocol.labelY.get() ax = plotter.createSubPlot( "Regression Plot", "%s [%s]" % (varNameX, strUnit( self.protocol.experiment.variables[varNameX].units.unit)), "%s [%s]" % (varNameY, strUnit( self.protocol.experiment.variables[varNameY].units.unit))) ax.plot(xValues, yValues) ax.plot(X, Y, 'o') return [plotter] else: return [ self.errorMessage("Result file '%s' not produced yet. " % fnResults) ]
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]
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 _onPlotClick(self, e=None): sampleKeys = self.samplesTree.selection() if sampleKeys: if self.plotter is None or self.plotter.isClosed(): self.plotter = EmPlotter() doShow = True ax = self.plotter.createSubPlot("Plot", self.getTimeLabel(), self.getMeasureLabel()) self.plotDict = {} else: doShow = False ax = self.plotter.getLastSubPlot() samples = [self.experiment.samples[k] for k in sampleKeys] for s in samples: if not s.sampleName in self.plotDict: x, y = self.getPlotValues(s) ax.plot(x, y, label=s.sampleName) self.plotDict[s.sampleName] = True leg = ax.legend() if leg: leg.draggable() if doShow: self.plotter.show() else: self.plotter.draw() else: self.showInfo("Please select some sample(s) to plot.")
def visualize(self, obj, **kwargs): prot = obj fnProfiles = prot._getPath("profiles.txt") fh = open(fnProfiles,"r") state = 0 legends = ['Iliver', 'Iinlet', 'Isys'] for line in fh: if state==0: tokens = line.split("::") title = tokens[1].strip() I3=[] state=1 elif state==1: tokens=line.strip().split() if len(tokens)==0: plotter = EmPlotter() ax = plotter.createSubPlot("Simulation", "t [h]", "[I] [mg/mL]") t = np.asarray(I3[0],dtype=np.float64)/60 for n in range(1,len(I3)): y = np.asarray(I3[n],dtype=np.float64) ax.plot(t, y, label=legends[n-1]) ax.legend() plotter.show() state=0 else: if len(I3)==0: for n in range(len(tokens)): I3.append([]) for n in range(len(tokens)): I3[n].append(tokens[n]) fh.close()
def _visualize(self, obj, **kwargs): fnResults = self.protocol._getPath("results.txt") if exists(fnResults): X, Y, _, _ = self.protocol.getXYValues(False) minX = min(X) maxX = max(X) step = (maxX - minX) / 50 xValues = np.arange(minX, maxX+step, step) yValues = self.protocol.evalFunction(xValues) plotter = EmPlotter() varNameX = self.protocol.labelX.get() varNameY = self.protocol.labelY.get() ax = plotter.createSubPlot("Regression Plot", "%s [%s]"%(varNameX,strUnit(self.protocol.experiment.variables[varNameX].units.unit)), "%s [%s]"%(varNameY,strUnit(self.protocol.experiment.variables[varNameY].units.unit))) ax.plot(xValues, yValues) ax.plot(X, Y, 'o') return [plotter] else: return [self.errorMessage("Result file '%s' not produced yet. " % fnResults)]
def _displayAngDist(self, *args): #print "_displayAngDist...." iterations = self._getIterations() nparts = self.protocol.inputParticles.get().getSize() views = [] if self.displayAngDist == ANGDIST_2DPLOT: #print " self.displayAngDist == ANGDIST_2DPLO " for it in iterations: anglesSqlite = self._getFinalPath('angular_dist_%03d.sqlite' % it) title = 'Angular distribution iter %03d' % it plotter = EmPlotter(x=1, y=1, windowTitle=title) self.createAngDistributionSqlite(anglesSqlite, nparts, itemDataIterator=self._iterAngles(it)) plotter.plotAngularDistributionFromMd(anglesSqlite, title) views.append(plotter) else: it = iterations[-1] print "Using last iteration: ", it anglesSqlite = self._getFinalPath('angular_dist_%03d.sqlite' % it) self.createAngDistributionSqlite(anglesSqlite, nparts, itemDataIterator=self._iterAngles(it)) volumes = self.getVolumeNames(it) views.append(em.ChimeraClientView(volumes[0], showProjection=True, angularDistFile=anglesSqlite, spheresDistance=2))#self.spheresScale.get())) return views
def _visualizeMatrix(self,e=None): views = [] self.isComputed() inputCTFs=self.protocol.inputCTFs shape=len(inputCTFs)#number of methods _matrix = np.zeros(shape=(shape, shape)) ticksLablesMajorX=[None] * shape ticksLablesMajorY=[None] * shape for ctf in self.setOfCTFsConst: m1 = int(self.extract(ctf.getAttributeValue('method1')))-1 m2 = int(self.extract(ctf.getAttributeValue('method2')))-1 _matrix[m1][m2] += 1 _matrix[m2][m1] = _matrix[m1][m2] #rather inefficient but since outputCTF is not ordered... if ticksLablesMajorX[m1] is None: ticksLablesMajorX[m1] = "(%d)"%(m1+1) ticksLablesMajorY[m1] = ctf.getAttributeValue('method1') if ticksLablesMajorX[m2] is None: ticksLablesMajorX[m2] = "(%d)"%(m2+1) ticksLablesMajorY[m2] = ctf.getAttributeValue('method2') plotter = EmPlotter(fontsize=14) resolution=self.resolutionThreshold.get() plotter.createSubPlot("# micrographs with resolution (A)\n lower than %d"%(resolution), "Method #", "Method") # plotter.plotMatrix(_matrix,cmap='seismic_r' plotter.plotMatrix(_matrix,cmap='Greens' , xticksLablesMajor=ticksLablesMajorX,rotationX=0 , yticksLablesMajor=ticksLablesMajorY) views.append(plotter) return views
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 iter %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 iter %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 iter %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 iter %d' % it) self._plotFSC(a, fscMask) legends.append('masked map iter %d' % it) self._plotFSC(a, fscMaskTight) legends.append('masked tight map 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]
def paint(self,labels): for label in labels: self.lines[label],=self.ax.plot([], [], '-',label=label) anim = animation.FuncAnimation(self.fig, self.animate, interval=self.monitor.samplingInterval * 1000)#miliseconds self.fig.canvas.mpl_connect('scroll_event', self.onscroll) self.fig.canvas.mpl_connect('key_press_event', self.press) EmPlotter.show(self)
def press(self,event): sys.stdout.flush() if event.key == 'S': self.stop = True self.ax.set_title('Plot is Stopped. Press C to continue plotting') elif event.key == 'C': self.ax.set_title(self._getTitle()) self.stop = False self.animate() EmPlotter.show(self)
def _visualizeHistogram(self, e=None): views = [] self.isComputed() numberOfBins = self.visualizeHistogram.get() numberOfBins = min(numberOfBins, self.setOfCTFsConst.getSize()) plotter = EmPlotter() plotter.createSubPlot("Resolution Discrepancies histogram", "Resolution (A)", "# of Comparisons") resolution = [ctf.resolution.get() for ctf in self.setOfCTFsConst] plotter.plotHist(resolution, nbins=numberOfBins) return views.append(plotter)
def paint(self, labels): for label in labels: self.lines[label], = self.ax.plot([], [], '-', label=label) anim = animation.FuncAnimation( self.fig, self.animate, interval=self.monitor.samplingInterval * 1000) # miliseconds self.fig.canvas.mpl_connect('scroll_event', self.onscroll) self.fig.canvas.mpl_connect('key_press_event', self.press) EmPlotter.show(self)
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") fig = plotter.plotHist(imgListNoZero, nbins) return [plotter]
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.metadata.utils import getSize from pyworkflow.em.plotter import EmPlotter 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
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.plotter 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
def _plot(varLabelX, varLabelY, x, y, yp): plotter = EmPlotter() ax = plotter.createSubPlot("Plot", varLabelX, varLabelY) xValues = _values(x, useLog=self.useTimeLog()) ax.plot(xValues, _values(y), 'x', label="Observations") idx = np.argsort(xValues) ypValues = _values(yp) ax.plot(np.asarray(xValues)[idx], np.asarray(ypValues)[idx], 'g', label="Fit") leg = ax.legend() if leg: leg.draggable() plotter.show()
def onscroll(self, event): if event.button == 'up': self.win += self.step else: self.win -= self.step if self.win < self.step: self.win = self.step if self.oldWin != self.win: self.ax.set_title(self._getTitle()) self.oldWin = self.win self.animate() EmPlotter.show(self)
def onscroll(self, event): if event.button == 'up': self.win += self.step else: self.win -= self.step if self.win < self.step: self.win = self.step if self.oldWin != self.win: self.ax.set_title(self._getTitle()) self.oldWin= self.win self.animate() EmPlotter.show(self)
def visualize(self, obj, **kwargs): model = PKPDAllometricScale() model.load(obj.fnScale.get()) x = np.log10(np.asarray(model.X)) xlabel = "%s [%s]" % (model.predictor, model.predictorUnits) for varName, varUnits in model.scaled_vars: plotter = EmPlotter() y = np.log10(np.asarray(model.Y[varName])) ylabel = "%s [%s]" % (varName, varUnits) ax = plotter.createSubPlot(varName, xlabel, ylabel) ax.plot(x, y, '.', label='Species') ax.plot(x, np.log10(model.models[varName][0])+x*model.models[varName][1],'r', label='R2=%f'%model.qualifiers[varName][0]) leg = ax.legend(loc='upper right') if leg: leg.draggable() plotter.show() for varName, varUnits in model.averaged_vars: plotter = EmPlotter() y = np.asarray(model.Y[varName]) ylabel = "%s [%s]" % (varName, varUnits) ax = plotter.createSubPlot("Scatter Plot", xlabel, ylabel) ax.plot(x, y, '.', label='Species') ax.plot(x, model.models[varName][0]*np.ones(x.shape),'r',label='Std=%f'%model.qualifiers[varName][0]) leg = ax.legend(loc='upper right') if leg: leg.draggable() plotter.show()
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
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
def __init__(self, monitor): EmPlotter.__init__(self, windowTitle="CTF Monitor") self.monitor = monitor self.y2 = 0.; self.y1 = 100. self.win = 250 # number of samples to be ploted self.step = 50 # self.win will be modified in steps of this size self.createSubPlot(self._getTitle(), "Micrographs", "Defocus (A)") self.fig = self.getFigure() self.ax = self.getLastSubPlot() self.ax.margins(0.05) self.ax.grid(True) self.oldWin = self.win self.lines = {} self.init = True self.stop = False
def _showFSC(self, paramName=None): threshold = self.resolutionThresholdFSC.get() iterations = self._getIterations() groups = self._getGroups() if self.groupFSC == 0: # group by iterations files = [(it, self._getFinalPath('fscdoc_%02d.stk' % it)) for it in iterations] legendPrefix = 'iter' else: it = iterations[-1] legendPrefix = 'group' def group(f): # retrieve the group number return int(f.split('_')[-1].split('.')[0]) groupFiles = glob(self._getFinalPath('fscdoc_%02d_???.stk' % it)) groupFiles.sort() files = [(group(f), f) for f in groupFiles if group(f) in groups] if not files: #empty files return [ self.errorMessage("Please select valid groups to display", title="Wrong groups selection") ] plotter = EmPlotter(x=1, y=1, windowTitle='Resolution FSC') a = plotter.createSubPlot("FSC", 'Angstroms^-1', 'FSC', yformat=False) #fscFile = self._getFinalPath('fscdoc_%02d.stk' % iterations[0]) legends = [] for it, fscFile in files: if os.path.exists(fscFile): self._plotFSC(a, fscFile) legends.append('%s %d' % (legendPrefix, it)) else: print "Missing file: ", fscFile if threshold < self.maxfsc: a.plot([self.minInv, self.maxInv], [threshold, threshold], color='black', linestyle='--') plotter.showLegend(legends) a.grid(True) return [plotter]
def __init__(self, monitor): EmPlotter.__init__(self, windowTitle="Movie Gain Monitor") self.monitor = monitor self.y2 = 0. self.y1 = 100. self.win = 250 # number of samples to be plotted self.step = 50 # self.win will be modified in steps of this size self.createSubPlot(self._getTitle(), "", "") self.fig = self.getFigure() self.ax = self.getLastSubPlot() self.ax2 = self.ax.twinx() self.ax2.margins(0.05) self.oldWin = self.win self.lines = {} self.init = True self.stop = False
def __init__(self, monitor): EmPlotter.__init__(self, windowTitle="CTF Monitor") self.monitor = monitor self.y2 = 0. self.y1 = 100. self.win = 250 # number of samples to be ploted self.step = 50 # self.win will be modified in steps of this size self.createSubPlot(self._getTitle(), "Micrographs", "Defocus (A)") self.fig = self.getFigure() self.ax = self.getLastSubPlot() self.ax.margins(0.05) self.ax.grid(True) self.oldWin = self.win self.lines = {} self.init = True self.stop = False
def __init__(self, monitor): EmPlotter.__init__(self, windowTitle="system Monitor") self.monitor = monitor self.y2 = 0. self.y1 = 100. self.win = 250 # number of samples to be ploted self.step = 50 # self.win will be modified in steps of this size self.createSubPlot(self._getTitle(), "time (hours)", "percentage (or Mb for IO)") self.fig = self.getFigure() self.ax = self.getLastSubPlot() self.ax.margins(0.05) self.ax.grid(True) self.oldWin = self.win self.lines = {} self.init = True self.stop = False
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
def _visualizeHistogram(self, e=None): views = [] numberOfBins = self.visualizeHistogram.get() 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) # ROB: why do I need this show? plotter.show() return views.append(plotter)
def __init__(self, monitor, nifName=None): EmPlotter.__init__(self, windowTitle="system Monitor") self.monitor = monitor self.y2 = 0. self.y1 = 100. self.win = 250 # number of samples to be ploted self.step = 50 # self.win will be modified in steps of this size self.createSubPlot(self._getTitle(), "time (hours)", "percentage (or MB for IO or NetWork)") self.fig = self.getFigure() self.ax = self.getLastSubPlot() self.ax.margins(0.05) self.ax.grid(True) self.oldWin = self.win self.lines = {} self.init = True self.stop = False self.nifName = nifName
def _onPlotSummaryClick(self, e=None): sampleKeys = self.samplesTree.selection() n = len(sampleKeys) if n == 1: self.showInfo("Please select several samples to plot.") else: if n > 1: samples = [self.experiment.samples[k] for k in sampleKeys] else: samples = self.experiment.samples.values() dataDict = {} # key will be time values for s in samples: xValues, yValues = self.getPlotValues(s) for x, y in izip(xValues, yValues): if x in dataDict: dataDict[x].append(y) else: dataDict[x] = [y] sortedTime = sorted(dataDict.keys()) # We will store five values (min, 25%, 50%, 75%, max) # for each of the time entries computed percentileList = [0, 25, 50, 75, 100] Y = np.zeros((len(sortedTime), 5)) for i, t in enumerate(sortedTime): Y[i,:] = np.percentile(dataDict[t], percentileList) plotter = EmPlotter() ax = plotter.createSubPlot("Summary Plot", self.getTimeLabel(), self.getMeasureLabel()) ax.plot(sortedTime, Y[:, 0], 'r--', label="Minimum") ax.plot(sortedTime, Y[:, 1], 'b--', label="25%") ax.plot(sortedTime, Y[:, 2], 'g', label="50% (Median)") ax.plot(sortedTime, Y[:, 3], 'b--', label="75%") ax.plot(sortedTime, Y[:, 4], 'r--', label="Maximum") ax.legend() plotter.show()
def createCtfPlot(ctfSet, ctfId): from pyworkflow.utils.path import removeExt 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 = [] for i in range(1, 5): _plotCurve(a, i, fn) if i == 1: legendName.append('rotational avg. No Astg') elif i == 2: legendName.append('rotational avg.') elif i == 3: legendName.append('CTF Fit') elif i == 4: legendName.append('Cross Correlation') elif i == 5: legendName.append('2sigma cross correlation of noise') xplotter.showLegend(legendName) a.grid(True) xplotter.show()
def _visualizeMatrix(self, e=None): views = [] self.isComputed() inputCTFs = self.protocol.inputCTFs shape = len(inputCTFs) #number of methods _matrix = np.zeros(shape=(shape, shape)) ticksLablesMajorX = [None] * shape ticksLablesMajorY = [None] * shape for ctf in self.setOfCTFsConst: m1 = int(self.extract(ctf.getAttributeValue('method1'))) - 1 m2 = int(self.extract(ctf.getAttributeValue('method2'))) - 1 _matrix[m1][m2] += 1 _matrix[m2][m1] = _matrix[m1][m2] #rather inefficient but since outputCTF is not ordered... if ticksLablesMajorX[m1] is None: ticksLablesMajorX[m1] = "(%d)" % (m1 + 1) ticksLablesMajorY[m1] = ctf.getAttributeValue('method1') if ticksLablesMajorX[m2] is None: ticksLablesMajorX[m2] = "(%d)" % (m2 + 1) ticksLablesMajorY[m2] = ctf.getAttributeValue('method2') plotter = EmPlotter(fontsize=14) resolution = self.resolutionThreshold.get() plotter.createSubPlot( "# micrographs with resolution (A)\n lower than %d" % (resolution), "Method #", "Method") # plotter.plotMatrix(_matrix,cmap='seismic_r' plotter.plotMatrix(_matrix, cmap='Greens', xticksLablesMajor=ticksLablesMajorX, rotationX=0, yticksLablesMajor=ticksLablesMajorY) views.append(plotter) return views
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
def _showFSC(self, paramName=None): threshold = self.resolutionThresholdFSC.get() iterations = self._getIterations() groups = self._getGroups() if self.groupFSC == 0: # group by iterations files = [(it, self._getFinalPath('fscdoc_%02d.stk' % it)) for it in iterations] legendPrefix = 'iter' else: it = iterations[-1] legendPrefix = 'group' def group(f): # retrieve the group number return int(f.split('_')[-1].split('.')[0]) groupFiles = glob(self._getFinalPath('fscdoc_%02d_???.stk' % it)) groupFiles.sort() files = [(group(f), f) for f in groupFiles if group(f) in groups] if not files: #empty files return [self.errorMessage("Please select valid groups to display", title="Wrong groups selection")] plotter = EmPlotter(x=1, y=1, windowTitle='Resolution FSC') a = plotter.createSubPlot("FSC", 'Angstroms^-1', 'FSC', yformat=False) #fscFile = self._getFinalPath('fscdoc_%02d.stk' % iterations[0]) legends = [] for it, fscFile in files: if os.path.exists(fscFile): self._plotFSC(a, fscFile) legends.append('%s %d' % (legendPrefix, it)) else: print "Missing file: ", fscFile if threshold < self.maxfsc: a.plot([self.minInv, self.maxInv],[threshold, threshold], color='black', linestyle='--') plotter.showLegend(legends) a.grid(True) return [plotter]
def plotResults(self): if self.plotter is None or self.plotter.isClosed(): self.plotter = EmPlotter() doShow = True else: doShow = False ax = self.plotter.getLastSubPlot() self.plotter.clear() ax = self.plotter.createSubPlot("Sample: %s" % self.sample.sampleName, self.getTimeLabel(), self.getMeasureLabel()) self.newXPValues, self.newYPValues = self.computePlotValues( self.xpValues[0], self.ypValues[0]) ax.plot(self.newXValues, self.newYValues, 'x', label="Observations") ax.plot(self.newXPValues, self.newYPValues, label="Fit") ax.legend() if doShow: self.plotter.show() else: self.plotter.draw()
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 _plotHistogram(self, param=None): """ First we parse the cas_EIG file and we read: first line: take the number of eigen values. then one line per factor and we read the percent and cumulative percent. """ from numpy import arange from matplotlib.ticker import FormatStrFormatter fn = self.protocol._getFileName('eigFile') f = open(fn) values = f.readline().split() n = int(values[0]) # Number of factors factors = arange(1, n+1) percents = [] cumPercents = [] for i in factors: values = f.readline().split() percents.append(float(values[1])) cumPercents.append(float(values[2])) f.close() width = 0.85 xplotter = EmPlotter() a = xplotter.createSubPlot('Eigenvalues histogram', 'Eigenvalue number', '%') a.set_xticks(factors + 0.45) a.xaxis.set_major_formatter(FormatStrFormatter('%1.0f')) bars = a.bar(factors, percents, width, color='b') for i, rect in enumerate(bars): h = rect.get_height() a.text(rect.get_x()+rect.get_width()/2., h+0.3, '%d' % cumPercents[i], ha='center', va='bottom') a.set_ylim([0, percents[0] + 5]) return [xplotter]
def paint(self, labels): for label in labels: if (label == 'standard_deviation'): self.lines[label], = \ self.ax2.plot([], [], '-o', label='Standard deviation', color='r') if (label == 'ratio1'): self.lines[label], = \ self.ax.plot([], [], '-o', label='97.5/2.5 percentile', color='b') if (label == 'ratio2'): self.lines[label], = \ self.ax.plot([], [], '-*', label='max/97.5 percentile', color='b') anim = animation.FuncAnimation(self.fig, self.animate, interval=self.monitor.samplingInterval*1000)#miliseconds self.fig.canvas.mpl_connect('scroll_event', self.onscroll) self.fig.canvas.mpl_connect('key_press_event', self.press) EmPlotter.show(self)
def visualize(self, obj, **kwargs): model = PKPDAllometricScale() model.load(obj.fnScale.get()) x = np.log10(np.asarray(model.X)) xlabel = "%s [%s]" % (model.predictor, model.predictorUnits) for varName, varUnits in model.scaled_vars: plotter = EmPlotter() y = np.log10(np.asarray(model.Y[varName])) ylabel = "%s [%s]" % (varName, varUnits) ax = plotter.createSubPlot(varName, xlabel, ylabel) ax.plot(x, y, '.', label='Species') ax.plot(x, np.log10(model.models[varName][0]) + x * model.models[varName][1], 'r', label='R2=%f' % model.qualifiers[varName][0]) leg = ax.legend(loc='upper right') if leg: leg.draggable() plotter.show() for varName, varUnits in model.averaged_vars: plotter = EmPlotter() y = np.asarray(model.Y[varName]) ylabel = "%s [%s]" % (varName, varUnits) ax = plotter.createSubPlot("Scatter Plot", xlabel, ylabel) ax.plot(x, y, '.', label='Species') ax.plot(x, model.models[varName][0] * np.ones(x.shape), 'r', label='Std=%f' % model.qualifiers[varName][0]) leg = ax.legend(loc='upper right') if leg: leg.draggable() plotter.show()
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
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]
def _onPlotClick(self, e=None): selection = self.tree.selection() n = len(selection) if n < 1 or n > 2: self.showError("Select one or two variables to plot.") else: plotter = EmPlotter() varX = self._variables[selection[0]] xValues = self.observations[:, varX.index] def _label(var): return "%s [%s]" % (var.varName, var.unitStr) if n == 1: plotter.createSubPlot("Histogram", _label(varX), "Count") plotter.plotHist(xValues, 50) else: # n == 2 varY = self._variables[selection[1]] yValues = self.observations[:, varY.index] ax = plotter.createSubPlot("Scatter Plot", _label(varX), _label(varY)) ax.plot(xValues, yValues, '.') plotter.show()
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()
def plotResults(self): if self.plotter is None or self.plotter.isClosed(): self.plotter = EmPlotter() doShow = True else: doShow = False ax = self.plotter.getLastSubPlot() self.plotter.clear() ax = self.plotter.createSubPlot("Sample: %s" % self.sample.sampleName, self.getTimeLabel(), self.getMeasureLabel()) self.newXPValues, self.newYPValues = self.computePlotValues(self.xpValues[0], self.ypValues[0]) ax.plot(self.newXValues, self.newYValues, 'x', label="Observations") ax.plot(self.newXPValues, self.newYPValues, label="Fit") ax.legend() if doShow: self.plotter.show() else: self.plotter.draw()
def createCtfPlot(ctfSet, ctfId): ctfModel = ctfSet[ctfId] psdFn = ctfModel.getPsdFile() fn = pwutils.removeExt(psdFn) + "_EPA.txt" gridsize = [1, 1] xplotter = EmPlotter(x=gridsize[0], y=gridsize[1], windowTitle='CTF Fitting') plot_title = "CTF Fitting" a = xplotter.createSubPlot(plot_title, 'Resolution (Angstroms)', 'CTF', yformat=False) a.invert_xaxis() for i in range(1, 5): _plotCurve(a, i, fn) xplotter.showLegend(['simulated CTF', 'equiphase avg.', 'equiphase avg. - bg', 'cross correlation']) a.grid(True) xplotter.show()
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()