示例#1
0
def wizardBrowseCTF2(gui, var):
    error = None
    vList = ['LowResolCutoff', 'HighResolCutoff']
    freqs = gui.getVarlistValue(vList)
    importRunName = gui.getVarValue('ImportRun')
    prot = gui.project.getProtocolFromRunName(importRunName)
    path = prot.WorkingDir
    if path and exists(path):
        mdPath = prot.getFilename('micrographs')
        if exists(mdPath):
            from xmipp import MetaData, MDL_MICROGRAPH
            md = MetaData(mdPath)
            if md.size():
                image = md.getValue(MDL_MICROGRAPH, md.firstObject())     
                if image:         
                    filterExt = "*" + splitext(image)[1]
                    value = gui.getVarValue('DownsampleFactor')
                    results = wizardHelperSetDownsampling(gui, var, path, filterExt, value, freqs, md)
                    if results:
                        gui.setVarlistValue(vList, results[1:])
                else:
                    error = "Not micrograph found in metadata <%s>" % mdPath
                    #gui.setVarValue('LowResolCutoff', results[1])
                    #gui.setVarValue('HighResolCutoff', results[2])
            else:
                error = "Micrograph metadata <%s> is empty" % mdPath
        else:
            error = "Micrograph metadata <%s> doesn't exists" % mdPath
    else:
        error = "Import run <%s> doesn't exists" % str(path)
    if error:
        showWarning("Select Downsampling Wizard", error, gui.master)
        return None
    else:
        return results
示例#2
0
def wizardChooseSizeToExtract(gui, var):
    from xmipp import MDL_PICKING_PARTICLE_SIZE, MDL_CTF_MODEL, MDL_SAMPLINGRATE, MDL_SAMPLINGRATE_ORIGINAL
    from protlib_gui_ext import ListboxDialog
    pickingRun = gui.getVarValue('PickingRun')
    pickingProt = gui.project.getProtocolFromRunName(pickingRun)
    fnConfig = pickingProt.getFilename("config")  
    if not exists(fnConfig):
        showWarning("Warning", "No elements to select", parent=gui.master)
        return
    md = MetaData(fnConfig)
    particleSize = md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject())
    type = gui.getVarValue("DownsampleType")
    mdAcquisition = MetaData(pickingProt.getFilename('acquisition'))
    objId = mdAcquisition.firstObject()
    tsOriginal = tsPicking = mdAcquisition.getValue(MDL_SAMPLINGRATE, objId)
    
    if mdAcquisition.containsLabel(MDL_SAMPLINGRATE_ORIGINAL):
        tsOriginal = mdAcquisition.getValue(MDL_SAMPLINGRATE_ORIGINAL, objId)
    
    if type == "same as picking":
        factor = 1
    else:
        factor = tsPicking / tsOriginal;
        if type == "other":
            try:
                factor /= float(gui.getVarValue("DownsampleFactor"))
            except Exception, e:
                showWarning("Warning", "Please select valid downsample factor", parent=gui.master)
                return
示例#3
0
 def visualize(self):
     if self.getRunState() == SqliteDb.RUN_FINISHED:
         from protlib_utils import runShowJ
         runShowJ("classes@"+self.workingDirPath("classes.xmd"), extraParams=" --columns %d" % self.SomXdim)
     else:
         from protlib_gui_ext import showWarning
         showWarning("Warning", "The algorithm has not finished yet", parent=self.master)
 def visualize(self):
     summaryFile = self.getFilename('micrographs')
     
     if not exists(summaryFile): # Try to create partial summary file
         summaryFile = summaryFile.replace(self.WorkingDir, self.TmpDir)
         buildSummaryMetadata(self.WorkingDir, self.Input['micrographs'], summaryFile, self.MDL_TYPE)
     
     if exists(summaryFile):
         self.regenerateSummary(summaryFile)
         runShowJ(summaryFile, extraParams = "--mode metadata --render psd psdEnhanced image1 image2 --order psd psdEnhanced image1 image2 --zoom 50")
     else:
         showWarning('Warning', 'There are not results yet',self.master)
    def visualize(self):
        from protlib_gui_figure import XmippArrayPlotter1D, XmippArrayPlotter2D, XmippArrayPlotter3D

        components = self.DisplayRawDeformation.split()
        dim = len(components)
        if dim > 0:
            modeList = []
            modeNameList = []
            # Get modes
            MD = MetaData(self.Modesfile)
            MD.removeDisabled()
            for modeComponent in components:
                mode = int(modeComponent)
                if mode > MD.size():
                    from protlib_gui_ext import showWarning

                    showWarning("Warning", "You don't have so many modes", parent=self.master)
                else:
                    mode -= 1
                    currentMode = 0
                    modeName = ""
                    for id in MD:
                        modeName = MD.getValue(MDL_NMA_MODEFILE, id)
                        currentMode += 1
                        if currentMode > mode:
                            break
                    modeNameList.append(modeName)
                    modeList.append(mode)

            # Actually plot
            if dim == 1:
                XmippArrayPlotter1D(
                    self.extraPath("deformations.txt"),
                    modeList[0],
                    "Histogram for mode %s" % modeNameList[0],
                    "Deformation value",
                    "Number of images",
                )
            elif dim == 2:
                XmippArrayPlotter2D(
                    self.extraPath("deformations.txt"), modeList[0], modeList[1], "", modeNameList[0], modeNameList[1]
                )
            elif dim == 3:
                XmippArrayPlotter3D(
                    self.extraPath("deformations.txt"),
                    modeList[0],
                    modeList[1],
                    modeList[2],
                    "",
                    modeNameList[0],
                    modeNameList[1],
                    modeNameList[2],
                )
示例#6
0
def wizardSelectFromList(master, frame, list):
    '''Helper function to select elements from a list '''
    L=len(list)
    if L == 0:
        showWarning("Warning", "No elements to select", parent=master)
        return
    if L == 1:
        return list[0]
    from protlib_gui_ext import ListboxDialog
    d = ListboxDialog(frame, list, selectmode=tk.SINGLE)
    if len(d.result) > 0:
        index = d.result[0]
        return(list[index])
    else:
        return None
示例#7
0
def wizardHelperFilter(gui, browser, title, **args):
    extra = {'previewLabel': 'Image', 'computingMessage': 'Applying filter...'}
    extra.update(args)
    varName = args.get('varName', 'InSelFile')
    selfile = gui.getVarValue(varName)
    path, filename = split(selfile)
    if not exists(selfile):
        showWarning("Warning", "The input metadata is not a valid file", parent=gui.master)
        return
    # Select the first 10 particles to display the filter
    md = MetaData(selfile)
    fileList = []
    for i, objId in enumerate(md):
        if i == 10:
            break  
        fileList.append(md.getValue(MDL_IMAGE, objId))
    extra['fileList'] = fileList
    return showBrowseDialog(path=path, parent=gui.master, browser=browser,title=title, 
                            seltype="file", selmode="browse", filter=filename, previewDim=256, extra=extra)        
 def visualize(self):
     if not os.path.exists(self.outputFile):
         from protlib_gui_ext import showWarning
         showWarning("Error", "There is no result yet",self.master)
     else:   
         runShowJ(self.outputFile)                                     
示例#9
0
def wizardShowJ(gui, var):
    value = var.getTkValue().strip()
    if len(value):
        openFile(var.getTkValue())
    else:
        showWarning("Empty file", "Please select a file to visualize", parent=gui.master)
示例#10
0
 def visualize(self):
     summaryFile = self.getFilename('micrographs')
     if exists(summaryFile):
         runShowJ(summaryFile, extraParams = "--mode metadata")
     else:
         showWarning('Warning', 'There are not results yet',self.master)
示例#11
0
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