def _viewPlot(self, title, xTitle, yTitle, mdFn, mdLabelX, mdLabelY, color='g'): #xplotter = XmippPlotter(1, 1, figsize=(4,4), windowTitle="Plot") #xplotter.createSubPlot(title, xTitle, yTitle) #xplotter.plotMdFile(md, mdLabelX, mdLabelY, color) mdFn.sort(md.MDL_WEIGHT) plotter = XmippPlotter() plotter.createSubPlot("", IMAGE_INDEX, P_INDEX) plotter.plotMdFile(mdFn, None, md.MDL_WEIGHT) return plotter
def _plotHistogramAngularMovement(self, paramName=None): views = [] for it in self._iterations: fnDir = self.protocol._getExtraPath("Iter%03d"%it) fnAngles = join(fnDir,"angles.xmd") if self.protocol.weightJumper and it>1: import xmipp xplotter = XmippPlotter(windowTitle="Jumper weight") a = xplotter.createSubPlot("Jumper weight", "Weight", "Count") xplotter.plotMdFile(fnAngles,xmipp.MDL_WEIGHT_JUMPER,xmipp.MDL_WEIGHT_JUMPER,nbins=100) views.append(xplotter) return views
def _createPlot(self, title, xTitle, yTitle, md, mdLabelX, mdLabelY, color='g', figure=None): xplotter = XmippPlotter(figure=figure) xplotter.plot_title_fontsize = 11 xplotter.createSubPlot(title, xTitle, yTitle, 1, 1) xplotter.plotMdFile(md, mdLabelX, mdLabelY, color) return xplotter
def _visualize(self, obj, **kwargs): cls = type(obj) if issubclass(cls, SetOfNormalModes): fn = obj.getFileName() from .viewer_nma import OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD) self._views.append( ObjectView(self._project, self.protocol.strId(), fn, obj.strId(), viewParams={OBJCMDS: objCommands}, **kwargs)) elif issubclass(cls, XmippProtCTFMicrographs): if obj.hasAttribute('outputCTF'): ctfSet = obj.outputCTF else: mics = obj.inputMicrographs.get() ctfSet = self.__createTemporaryCtfs(obj, mics) if ctfSet.isEmpty(): self._views.append( self.infoMessage("No CTF estimation has finished yet")) else: self.getCTFViews(ctfSet) elif (issubclass(cls, XmippProtExtractParticles) or issubclass(cls, XmippProtScreenParticles)): particles = obj.outputParticles self._visualize(particles) fn = obj._getPath('images.xmd') if os.path.exists(fn): # it doesnt unless cls is Xmipp md = xmippLib.MetaData(fn) # If Zscore on output images plot Zscore particle sorting if md.containsLabel(xmippLib.MDL_ZSCORE): from plotter import XmippPlotter xplotter = XmippPlotter( windowTitle="Zscore particles sorting") xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") xplotter.plotMd(md, False, mdLabelY=xmippLib.MDL_ZSCORE) self._views.append(xplotter) # If VARscore on output images plot VARscore particle sorting if md.containsLabel(xmippLib.MDL_SCORE_BY_VAR): from plotter import XmippPlotter xplotter = XmippPlotter( windowTitle="Variance particles sorting") xplotter.createSubPlot("Variance Histogram", "Variance", "Number of particles") xplotter.plotMd(md, False, mdLabelY=xmippLib.MDL_SCORE_BY_VAR, nbins=100) self._views.append(xplotter) elif issubclass(cls, XmippProtDeepDenoising): fn = obj.outputParticles.getFileName() self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ VISIBLE: 'enabled id _filename ' '_xmipp_corrDenoisedProjection ' '_xmipp_corrDenoisedNoisy ' '_xmipp_imageOriginal _xmipp_imageRef', SORT_BY: 'id', MODE: MODE_MD })) elif issubclass(cls, XmippProtMovieGain): self._visualize(obj.outputMovies) movieGainMonitor = MonitorMovieGain( obj, workingDir=obj.workingDir.get(), samplingInterval=60, monitorTime=300, stddevValue=0.04, ratio1Value=1.15, ratio2Value=4.5) self._views.append(MovieGainMonitorPlotter(movieGainMonitor)) elif issubclass(cls, XmippProtRotSpectra): self._visualize( obj.outputClasses, viewParams={ 'columns': obj.SomXdim.get(), RENDER: ' spectraPlot._filename average._filename', ZOOM: 30, VISIBLE: 'enabled id _size average._filename spectraPlot._filename', 'labels': 'id _size', SORT_BY: 'id' }) elif issubclass(cls, XmippProtKerdensom): self._visualize(obj.outputClasses, viewParams={ 'columns': obj.SomXdim.get(), 'render': 'average._filename _representative._filename', 'labels': '_size', 'sortby': 'id' }) elif issubclass(cls, XmippProtCompareReprojections): fn = obj.outputParticles.getFileName() labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY' labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename" self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_cost asc', RENDER: labelRender, MODE: MODE_MD })) elif issubclass(cls, XmippProtCompareAngles): fn = obj.outputParticles.getFileName() labels = 'id enabled _index _filename _xmipp_shiftDiff _xmipp_angleDiff' labelRender = "_filename" self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_angleDiff asc', RENDER: labelRender, MODE: MODE_MD })) elif issubclass(cls, XmippParticlePickingAutomatic): micSet = obj.getInputMicrographs() mdFn = getattr(micSet, '_xmippMd', None) inTmpFolder = False if mdFn: micsfn = mdFn.get() else: # happens if protocol is not an xmipp one micsfn = self._getTmpPath(micSet.getName() + '_micrographs.xmd') writeSetOfMicrographs(micSet, micsfn) inTmpFolder = True posDir = obj._getExtraPath() memory = showj.getJvmMaxMemory() launchSupervisedPickerGUI(micsfn, posDir, obj, mode='review', memory=memory, inTmpFolder=inTmpFolder) elif issubclass(cls, XmippProtParticleBoxsize): """ Launching a Coordinates viewer with only one coord in the center with the estimated boxsize. """ micSet = obj.inputMicrographs.get() coordsFn = self._getTmpPath(micSet.getName() + '_coords_to_view.sqlite') if not os.path.exists(coordsFn): # Just creating the coords once coordsSet = SetOfCoordinates(filename=coordsFn) coordsSet.setBoxSize(obj.boxsize) for mic in micSet: coord = Coordinate() coord.setMicrograph(mic) coord.setPosition(mic.getXDim() / 2, mic.getYDim() / 2) coordsSet.append(coord) coordsSet.write() else: coordsSet = SetOfCoordinates(filename=coordsFn) coordsSet.loadAllProperties() coordsSet.setMicrographs(micSet) coordsSet.setName(micSet.getName()) self._visualize(coordsSet) # We need this case to happens before the ProtParticlePicking one elif issubclass(cls, XmippProtAssignmentTiltPair): if obj.getOutputsSize() >= 1: coordsSet = obj.getCoordsTiltPair() self._visualize(coordsSet) elif issubclass(cls, XmippProtValidateNonTilt): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weight' self._views.append( ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={ MODE: MODE_MD, VISIBLE: labels, ORDER: labels, SORT_BY: 'weight desc', RENDER: '_filename' })) elif issubclass(cls, XmippProtMultiRefAlignability): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weightAlignabilityPrecision weightAlignabilityAccuracy' self._views.append( ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={ MODE: MODE_MD, VISIBLE: labels, ORDER: labels, SORT_BY: 'weightAlignabilityAccuracy desc', RENDER: '_filename' })) fn = obj.outputParticles.getFileName() labels = 'id enabled _index _filename _xmipp_scoreAlignabilityAccuracy _xmipp_scoreAlignabilityPrecision' labelRender = "_filename" self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_scoreAlignabilityAccuracy desc', RENDER: labelRender, MODE: MODE_MD })) fn = obj._getExtraPath('vol001_pruned_particles_alignability.xmd') md = xmippLib.MetaData(fn) from .plotter import XmippPlotter plotter = XmippPlotter() plotter.createSubPlot('Soft-alignment validation plot', 'Angular Precision', 'Angular Accuracy') plotter.plotMdFile(md, xmippLib.MDL_SCORE_BY_ALIGNABILITY_PRECISION, xmippLib.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, marker='.', markersize=.55, color='red', linestyle='') self._views.append(plotter) elif issubclass(cls, XmippProtExtractParticlesPairs): self._visualize(obj.outputParticlesTiltPair) else: # Use default visualization defined in base class DataViewer._visualize(self, obj, **kwargs) return self._views
def _visualize(self, obj, **kwargs): cls = type(obj) if issubclass(cls, Volume): fn = getImageLocation(obj) self._views.append( ObjectView(self._project, obj.strId(), fn, viewParams={ RENDER: 'image', SAMPLINGRATE: obj.getSamplingRate() })) elif issubclass(cls, Image): fn = getImageLocation(obj) self._views.append(ObjectView(self._project, obj.strId(), fn)) elif issubclass(cls, SetOfNormalModes): fn = obj.getFileName() from nma.viewer_nma import OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD) self._views.append( ObjectView(self._project, self.protocol.strId(), fn, obj.strId(), viewParams={OBJCMDS: objCommands}, **kwargs)) elif issubclass(cls, SetOfMovies): fn = obj.getFileName() # Enabled for the future has to be available labels = 'id _filename _samplingRate ' self._views.append( ObjectView(self._project, obj.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, MODE: MODE_MD, RENDER: "no" })) elif issubclass(cls, SetOfMicrographs): self._views.append(MicrographsView(self._project, obj, **kwargs)) elif issubclass(cls, MicrographsTiltPair): labels = 'id enabled _untilted._filename _tilted._filename' self._views.append( ObjectView(self._project, obj.strId(), obj.getFileName(), viewParams={ ORDER: labels, VISIBLE: labels, MODE: MODE_MD, RENDER: '_untilted._filename _tilted._filename' })) elif issubclass(cls, ParticlesTiltPair): labels = 'id enabled _untilted._filename _tilted._filename' self._views.append( ObjectView(self._project, obj.strId(), obj.getFileName(), viewParams={ ORDER: labels, VISIBLE: labels, RENDER: '_untilted._filename _tilted._filename', MODE: MODE_MD })) elif issubclass(cls, SetOfCoordinates): micSet = obj.getMicrographs( ) # accessing mics to provide metadata file if micSet is None: raise Exception( 'visualize: SetOfCoordinates has no micrographs set.') mdFn = getattr(micSet, '_xmippMd', None) if mdFn: fn = mdFn.get() else: # happens if protocol is not an xmipp one fn = self._getTmpPath(micSet.getName() + '_micrographs.xmd') writeSetOfMicrographs(micSet, fn) tmpDir = self._getTmpPath(obj.getName()) cleanPath(tmpDir) makePath(tmpDir) # FIXME: (JMRT) We are always writing the SetOfCoordinates and removing # the tmpDir, we need to take into account if the user have pick # some particles in the tmpDir and have not save them, that now # will loose all picked particles. # A possible solution could be to alert that changes have not been # written during modification of tmpDir or create a new Xmipp picking # protocol to continue picking later without loosing the coordinates. writeSetOfCoordinates(tmpDir, obj) self._views.append( CoordinatesObjectView(self._project, fn, tmpDir, self.protocol, inTmpFolder=True)) elif issubclass(cls, SetOfParticles): fn = obj.getFileName() labels = 'id enabled _index _filename _xmipp_zScore _xmipp_cumulativeSSNR _sampling ' labels += '_ctfModel._defocusU _ctfModel._defocusV _ctfModel._defocusAngle _transform._matrix' self._views.append( ObjectView(self._project, obj.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, 'sortby': '_xmipp_zScore asc', RENDER: '_filename' })) elif issubclass(cls, SetOfVolumes): fn = obj.getFileName() labels = 'id enabled comment _filename ' self._views.append( ObjectView(self._project, obj.strId(), fn, viewParams={ MODE: MODE_MD, ORDER: labels, VISIBLE: labels, RENDER: '_filename' })) elif issubclass(cls, SetOfClasses2D): fn = obj.getFileName() self._views.append( ClassesView(self._project, obj.strId(), fn, **kwargs)) elif issubclass(cls, SetOfClasses3D): fn = obj.getFileName() self._views.append(Classes3DView(self._project, obj.strId(), fn)) elif issubclass(cls, SetOfImages): fn = obj.getFileName() self._views.append( ObjectView(self._project, obj.strId(), fn, **kwargs)) if issubclass(cls, XmippProtCTFMicrographs): if obj.hasAttribute('outputCTF'): ctfSet = obj.outputCTF else: mics = obj.inputMicrographs.get() ctfSet = self.__createTemporaryCtfs(obj, mics) if ctfSet.isEmpty(): self._views.append( self.infoMessage("No CTF estimation has finished yet")) else: self._views.append(CtfView(self._project, ctfSet)) elif issubclass(cls, SetOfCTF): self._views.append(CtfView(self._project, obj)) elif issubclass(cls, CoordinatesTiltPair): tmpDir = self._getTmpPath(obj.getName()) makePath(tmpDir) mdFn = join(tmpDir, 'input_micrographs.xmd') writeSetOfMicrographsPairs(obj.getUntilted().getMicrographs(), obj.getTilted().getMicrographs(), mdFn) parentProtId = obj.getObjParentId() parentProt = self.getProject().mapper.selectById(parentProtId) extraDir = parentProt._getExtraPath() # extraDir = parentProt._getExtraPath() #TODO: Review this if ever a non Xmipp CoordinatesTiltPair is available writeSetOfCoordinates(tmpDir, obj.getUntilted()) writeSetOfCoordinates(tmpDir, obj.getTilted()) launchTiltPairPickerGUI(mdFn, tmpDir, self.protocol) elif (issubclass(cls, XmippProtExtractParticles) or issubclass(cls, XmippProtScreenParticles)): particles = obj.outputParticles self._visualize(particles) fn = obj._getPath('images.xmd') if os.path.exists(fn): # it doesnt unless cls is Xmipp md = xmipp.MetaData(fn) # If Zscore on output images plot Zscore particle sorting if md.containsLabel(xmipp.MDL_ZSCORE): from plotter import XmippPlotter xplotter = XmippPlotter( windowTitle="Zscore particles sorting") xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") xplotter.plotMd(md, False, mdLabelY=xmipp.MDL_ZSCORE) self._views.append(xplotter) elif issubclass(cls, XmippProtRotSpectra): self._visualize( obj.outputClasses, viewParams={ 'columns': obj.SomXdim.get(), RENDER: ' spectraPlot._filename average._filename', ZOOM: 30, VISIBLE: 'enabled id _size average._filename spectraPlot._filename', 'labels': 'id _size', SORT_BY: 'id' }) elif issubclass(cls, XmippProtKerdensom): self._visualize(obj.outputClasses, viewParams={ 'columns': obj.SomXdim.get(), 'render': 'average._filename _representative._filename', 'labels': '_size', 'sortby': 'id' }) elif issubclass(cls, XmippProtCompareReprojections): fn = obj.outputParticles.getFileName() labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY' labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename" self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_cost asc', RENDER: labelRender, MODE: MODE_MD })) elif issubclass(cls, XmippParticlePickingAutomatic): micSet = obj.getInputMicrographs() mdFn = getattr(micSet, '_xmippMd', None) inTmpFolder = False if mdFn: micsfn = mdFn.get() else: # happens if protocol is not an xmipp one micsfn = self._getTmpPath(micSet.getName() + '_micrographs.xmd') writeSetOfMicrographs(micSet, micsfn) inTmpFolder = True posDir = obj._getExtraPath() memory = '%dg' % obj.memory.get(), launchSupervisedPickerGUI(micsfn, posDir, obj, mode='review', memory=memory, inTmpFolder=inTmpFolder) # We need this case to happens before the ProtParticlePicking one elif issubclass(cls, XmippProtAssignmentTiltPair): if obj.getOutputsSize() >= 1: coordsSet = obj.getCoordsTiltPair() self._visualize(coordsSet) elif issubclass(cls, ProtParticlePicking): if obj.getOutputsSize() >= 1: coordsSet = obj.getCoords() self._visualize(coordsSet) elif issubclass(cls, XmippProtValidateNonTilt): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weight' self._views.append( ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={ MODE: MODE_MD, VISIBLE: labels, ORDER: labels, SORT_BY: 'weight desc', RENDER: '_filename' })) elif issubclass(cls, XmippProtMultiRefAlignability): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weightAlignabilityPrecision weightAlignabilityAccuracy' self._views.append( ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={ MODE: MODE_MD, VISIBLE: labels, ORDER: labels, SORT_BY: 'weightAlignabilityAccuracy desc', RENDER: '_filename' })) fn = obj.outputParticles.getFileName() labels = 'id enabled _index _filename _xmipp_scoreAlignabilityAccuracy _xmipp_scoreAlignabilityPrecision' labelRender = "_filename" self._views.append( ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_scoreAlignabilityAccuracy desc', RENDER: labelRender, MODE: MODE_MD })) fn = obj._getExtraPath('vol001_pruned_particles_alignability.xmd') md = xmipp.MetaData(fn) from plotter import XmippPlotter from pyworkflow.em.plotter import EmPlotter plotter = XmippPlotter() plotter.createSubPlot('Soft-alignment validation plot', 'Angular Precision', 'Angular Accuracy') plotter.plotMdFile(md, xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, marker='.', markersize=.55, color='red', linestyle='') self._views.append(plotter) elif issubclass(cls, XmippProtExtractParticlesPairs): self._visualize(obj.outputParticlesTiltPair) return self._views
def _visualize(self, obj, **kwargs): cls = type(obj) if issubclass(cls, Volume): fn = getImageLocation(obj) self._views.append(ObjectView(self._project, obj.strId(), fn, viewParams={RENDER: 'image', SAMPLINGRATE: obj.getSamplingRate()})) elif issubclass(cls, Image): fn = getImageLocation(obj) self._views.append(ObjectView(self._project, obj.strId(), fn)) elif issubclass(cls, SetOfNormalModes): fn = obj.getFileName() from nma.viewer_nma import OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD) self._views.append(ObjectView(self._project, self.protocol.strId(), fn, obj.strId(), viewParams={OBJCMDS: objCommands}, **kwargs)) elif issubclass(cls, SetOfMovies): fn = obj.getFileName() # Enabled for the future has to be available labels = 'id _filename _samplingRate ' moviesView = ObjectView(self._project, obj.strId(), fn, viewParams={ORDER: labels, VISIBLE: labels, MODE: MODE_MD, RENDER: "no"}) # For movies increase the JVM memory by 1 GB, just in case moviesView.setMemory(showj.getJvmMaxMemory() + 1) self._views.append(moviesView) elif issubclass(cls, SetOfMicrographs): self._views.append(MicrographsView(self._project, obj, **kwargs)) elif issubclass(cls, MicrographsTiltPair): labels = 'id enabled _untilted._filename _tilted._filename' self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(), viewParams={ORDER: labels, VISIBLE: labels, MODE: MODE_MD, RENDER: '_untilted._filename _tilted._filename'})) elif issubclass(cls, ParticlesTiltPair): labels = 'id enabled _untilted._filename _tilted._filename' self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(), viewParams={ORDER: labels, VISIBLE: labels, RENDER:'_untilted._filename _tilted._filename', MODE: MODE_MD})) elif issubclass(cls, SetOfCoordinates): micSet = obj.getMicrographs() # accessing mics to provide metadata file if micSet is None: raise Exception('visualize: SetOfCoordinates has no micrographs set.') mdFn = getattr(micSet, '_xmippMd', None) if mdFn: fn = mdFn.get() else: # happens if protocol is not an xmipp one fn = self._getTmpPath(micSet.getName() + '_micrographs.xmd') writeSetOfMicrographs(micSet, fn) tmpDir = self._getTmpPath(obj.getName()) cleanPath(tmpDir) makePath(tmpDir) # FIXME: (JMRT) We are always writing the SetOfCoordinates and removing # the tmpDir, we need to take into account if the user have pick # some particles in the tmpDir and have not save them, that now # will loose all picked particles. # A possible solution could be to alert that changes have not been # written during modification of tmpDir or create a new Xmipp picking # protocol to continue picking later without loosing the coordinates. writeSetOfCoordinates(tmpDir, obj) self._views.append(CoordinatesObjectView(self._project, fn, tmpDir, self.protocol, inTmpFolder=True)) elif issubclass(cls, SetOfParticles): fn = obj.getFileName() labels = 'id enabled _index _filename _xmipp_zScore _xmipp_cumulativeSSNR _sampling ' labels += '_ctfModel._defocusU _ctfModel._defocusV _ctfModel._defocusAngle _transform._matrix' self._views.append(ObjectView(self._project, obj.strId(), fn, viewParams={ORDER: labels, VISIBLE: labels, 'sortby': '_xmipp_zScore asc', RENDER:'_filename'})) elif issubclass(cls, SetOfVolumes): fn = obj.getFileName() labels = 'id enabled comment _filename ' self._views.append(ObjectView(self._project, obj.strId(), fn, viewParams={MODE: MODE_MD, ORDER: labels, VISIBLE: labels, RENDER: '_filename'})) elif issubclass(cls, SetOfClasses2D): fn = obj.getFileName() self._views.append(ClassesView(self._project, obj.strId(), fn, **kwargs)) elif issubclass(cls, SetOfClasses3D): fn = obj.getFileName() self._views.append(Classes3DView(self._project, obj.strId(), fn)) elif issubclass(cls, SetOfImages): fn = obj.getFileName() self._views.append( ObjectView(self._project, obj.strId(), fn, **kwargs)) if issubclass(cls, XmippProtCTFMicrographs): if obj.hasAttribute('outputCTF'): ctfSet = obj.outputCTF else: mics = obj.inputMicrographs.get() ctfSet = self.__createTemporaryCtfs(obj, mics) if ctfSet.isEmpty(): self._views.append(self.infoMessage("No CTF estimation has finished yet")) else: self._views.append(CtfView(self._project, ctfSet)) elif issubclass(cls, SetOfCTF): self._views.append(CtfView(self._project, obj)) elif issubclass(cls, CoordinatesTiltPair): tmpDir = self._getTmpPath(obj.getName()) makePath(tmpDir) mdFn = join(tmpDir, 'input_micrographs.xmd') writeSetOfMicrographsPairs(obj.getUntilted().getMicrographs(), obj.getTilted().getMicrographs(), mdFn) parentProtId = obj.getObjParentId() parentProt = self.getProject().mapper.selectById(parentProtId) extraDir = parentProt._getExtraPath() # extraDir = parentProt._getExtraPath() #TODO: Review this if ever a non Xmipp CoordinatesTiltPair is available writeSetOfCoordinates(tmpDir, obj.getUntilted()) writeSetOfCoordinates(tmpDir, obj.getTilted()) launchTiltPairPickerGUI(mdFn, tmpDir, self.protocol) elif (issubclass(cls, XmippProtExtractParticles) or issubclass(cls, XmippProtScreenParticles)): particles = obj.outputParticles self._visualize(particles) fn = obj._getPath('images.xmd') if os.path.exists(fn): # it doesnt unless cls is Xmipp md = xmipp.MetaData(fn) # If Zscore on output images plot Zscore particle sorting if md.containsLabel(xmipp.MDL_ZSCORE): from plotter import XmippPlotter xplotter = XmippPlotter(windowTitle="Zscore particles sorting") xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") xplotter.plotMd(md, False, mdLabelY=xmipp.MDL_ZSCORE) self._views.append(xplotter) elif issubclass(cls, XmippProtRotSpectra): self._visualize(obj.outputClasses, viewParams={'columns': obj.SomXdim.get(), RENDER: ' spectraPlot._filename average._filename', ZOOM: 30, VISIBLE: 'enabled id _size average._filename spectraPlot._filename', 'labels': 'id _size', SORT_BY: 'id'}) elif issubclass(cls, XmippProtKerdensom): self._visualize(obj.outputClasses, viewParams={'columns': obj.SomXdim.get(), 'render': 'average._filename _representative._filename', 'labels': '_size', 'sortby': 'id'}) elif issubclass(cls, XmippProtCompareReprojections): fn = obj.outputParticles.getFileName() labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY' labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename" self._views.append(ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_cost asc', RENDER:labelRender, MODE: MODE_MD})) elif issubclass(cls, XmippParticlePickingAutomatic): micSet = obj.getInputMicrographs() mdFn = getattr(micSet, '_xmippMd', None) inTmpFolder = False if mdFn: micsfn = mdFn.get() else: # happens if protocol is not an xmipp one micsfn = self._getTmpPath(micSet.getName() + '_micrographs.xmd') writeSetOfMicrographs(micSet, micsfn) inTmpFolder = True posDir = obj._getExtraPath() memory = '%d' % obj.memory.get() launchSupervisedPickerGUI(micsfn, posDir, obj, mode='review', memory=memory, inTmpFolder=inTmpFolder) # We need this case to happens before the ProtParticlePicking one elif issubclass(cls, XmippProtAssignmentTiltPair): if obj.getOutputsSize() >= 1: coordsSet = obj.getCoordsTiltPair() self._visualize(coordsSet) elif issubclass(cls, ProtParticlePicking): if obj.getOutputsSize() >= 1: coordsSet = obj.getCoords() self._visualize(coordsSet) elif issubclass(cls, XmippProtValidateNonTilt): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weight' self._views.append(ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={MODE: MODE_MD, VISIBLE:labels, ORDER: labels, SORT_BY: 'weight desc', RENDER: '_filename'})) elif issubclass(cls, XmippProtMultiRefAlignability): outputVols = obj.outputVolumes labels = 'id enabled comment _filename weightAlignabilityPrecision weightAlignabilityAccuracy' self._views.append(ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={MODE: MODE_MD, VISIBLE:labels, ORDER: labels, SORT_BY: 'weightAlignabilityAccuracy desc', RENDER: '_filename'})) fn = obj.outputParticles.getFileName() labels = 'id enabled _index _filename _xmipp_scoreAlignabilityAccuracy _xmipp_scoreAlignabilityPrecision' labelRender = "_filename" self._views.append(ObjectView(self._project, obj.outputParticles.strId(), fn, viewParams={ORDER: labels, VISIBLE: labels, SORT_BY: '_xmipp_scoreAlignabilityAccuracy desc', RENDER:labelRender, MODE: MODE_MD})) fn = obj._getExtraPath('vol001_pruned_particles_alignability.xmd') md = xmipp.MetaData(fn) from plotter import XmippPlotter from pyworkflow.em.plotter import EmPlotter plotter = XmippPlotter() plotter.createSubPlot('Soft-alignment validation plot','Angular Precision', 'Angular Accuracy') plotter.plotMdFile(md, xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, marker='.', markersize=.55, color='red', linestyle='') self._views.append(plotter) elif issubclass(cls, XmippProtExtractParticlesPairs): self._visualize(obj.outputParticlesTiltPair) return self._views
def _createPlot(self, title, xTitle, yTitle, md, mdLabelX, mdLabelY, color="g"): xplotter = XmippPlotter(1, 1, figsize=(4, 4), windowTitle="Plot") xplotter.createSubPlot(title, xTitle, yTitle) xplotter.plotMdFile(md, mdLabelX, mdLabelY, color) return xplotter