Exemplo n.º 1
0
    def openPath(self, path):
        "Try to open the selected path"
        path = expandPattern(path)

        # If the path is a dir, open it with scipion browser dir <path>
        if os.path.isdir(path):
            dpath = (path if os.path.isabs(path)
                     else os.path.join(os.getcwd(), path))
            subprocess.Popen([pw.getScipionScript(), 'view', dpath])
            return

        # If it is a file, interpret it correctly and open it with DataView
        dirname = os.path.dirname(path)
        fname = os.path.basename(path)
        if '@' in fname:
            path = os.path.join(dirname, fname.split('@', 1)[-1])
        else:
            path = os.path.join(dirname, fname)

        if os.path.exists(path):
            import xmippLib
            fn = xmippLib.FileName(path)
            if fn.isImage() or fn.isMetaData():
                from pyworkflow.em.viewers import DataView
                DataView(path).show()
            else:
                _open_cmd(path)
        else:
            # This is probably one special reference, like sci-open:... that
            # can be interpreted with our handlers.
            tag = path.split(':', 1)[0] if ':' in path else None
            if tag in self.handlers:
                self.handlers[tag](path.split(':', 1)[-1])
            else:
                print "Can't find %s" % path
Exemplo n.º 2
0
Arquivo: test.py Projeto: I2PC/xmipp
 def _checkOutputs(self, outputs, random=False, errorthreshold=0.001):
     """ Check that all output files are produced
     and are equivalent to the ones in goldStandard folder.
     """
     import xmippLib
     for out in outputs:
         outFile = os.path.join(self._testDir, self.outputDir, out)
         fileGoldStd = os.path.join(self.goldDir, out)
         
         # Check the expect output file was produced
         msg = "Missing expected output file:\n  output: %s" % outFile
         self.assertTrue(os.path.exists(outFile), red(msg))
         
         if random:
             print(yellow("WARNING: %s was created using a random seed, check skipped..." % outFile))
         else:
             fnGoldStd = xmippLib.FileName(fileGoldStd)
             if fnGoldStd.isImage():
                 im1 = xmippLib.Image(fileGoldStd)
                 im2 = xmippLib.Image(outFile)
                 msg = "Images are not equal (+-%f):\n  output: %s\n  gold: %s" % \
                       (errorthreshold, outFile, fileGoldStd)
                 self.assertTrue(im1.equal(im2, errorthreshold), red(msg))
             elif fnGoldStd.isMetaData():
                 msg = "MetaDatas are not equal:\n  output: %s\n  gold: %s" % (outFile, fileGoldStd)
                 self.assertTrue(xmippLib.compareTwoMetadataFiles(outFile, fileGoldStd), red(msg))
             else:
                 msg = "Files are not equal:\n  output: %s\n  gold: %s" % (outFile, fileGoldStd)
                 self.assertTrue(xmippLib.compareTwoFiles(outFile, fileGoldStd, 0), red(msg))
Exemplo n.º 3
0
def createMetaDataFromPattern(pattern, isStack=False, label="image"):
    ''' Create a metadata from files matching pattern'''
    import glob
    files = glob.glob(pattern)
    files.sort()

    label = xmippLib.str2Label(label)  #Check for label value

    mD = xmippLib.MetaData()
    inFile = xmippLib.FileName()

    nSize = 1
    for file in files:
        fileAux = file
        if isStack:
            if file.endswith(".mrc"):
                fileAux = file + ":mrcs"
            x, x, x, nSize = xmippLib.getImageSize(fileAux)
        if nSize != 1:
            counter = 1
            for jj in range(nSize):
                inFile.compose(counter, fileAux)
                objId = mD.addObject()
                mD.setValue(label, inFile, objId)
                mD.setValue(xmippLib.MDL_ENABLED, 1, objId)
                counter += 1
        else:
            objId = mD.addObject()
            mD.setValue(label, fileAux, objId)
            mD.setValue(xmippLib.MDL_ENABLED, 1, objId)
    return mD
Exemplo n.º 4
0
    def _getImgPath(self, mdFn, imgFn):
        """ Get ups and ups until finding the relative location to images. """
        path = dirname(mdFn)
        index, fn = xmippLib.FileName(imgFn).decompose()

        while path and path != '/':
            newFn = os.path.join(path, fn)
            if os.path.exists(newFn):
                if index:
                    newFn = '%d@%s' % (index, newFn)
                return newFn
            path = dirname(path)

        return None
Exemplo n.º 5
0
def xmippExists(path):
    return xmippLib.FileName(path).exists()
Exemplo n.º 6
0
 def isImageFile(cls, imgFn):
     """ Check if imgFn has an image extension. The function
     is implemented in the Xmipp binding.
     """
     return xmippLib.FileName(imgFn).isImage()
def runCreateOutputStep(self):
    ''' Create standard output results_images, result_classes'''
    #creating results files
    imgSet = self.inputParticles.get()
    lastIter = self.numberOfIterations.get()
    if self.numberOfReferences != 1:
        inDocfile = self._getFileName('docfileInputAnglesIters', iter=lastIter)
        ClassFnTemplate = '%(rootDir)s/reconstruction_Ref3D_%(ref)03d.vol'

        allExpImagesinDocfile = xmippLib.FileName()
        all_exp_images = "all_exp_images"
        allExpImagesinDocfile.compose(all_exp_images, inDocfile)

        dataClasses = self._getFileName('sqliteClasses')

        createClassesFromImages(imgSet, str(allExpImagesinDocfile),
                                dataClasses, SetOfClasses3D,
                                xmippLib.MDL_REF3D, ClassFnTemplate, lastIter)

        classes = self._createSetOfClasses3D(imgSet)
        clsSet = SetOfClasses3D(dataClasses)
        classes.appendFromClasses(clsSet)

        volumes = self._createSetOfVolumes()
        volumes.setSamplingRate(imgSet.getSamplingRate())

        for refN in self.allRefs():
            volFn = self._getFileName('reconstructedFileNamesIters',
                                      iter=lastIter,
                                      ref=refN)
            vol = Volume()
            vol.setFileName(volFn)
            volumes.append(vol)

        self._defineOutputs(outputVolumes=volumes)
        self._defineOutputs(outputClasses=classes)
        self._defineSourceRelation(self.inputParticles, volumes)
        self._defineSourceRelation(self.inputParticles, classes)
        self._defineSourceRelation(self.input3DReferences, volumes)
        self._defineSourceRelation(self.input3DReferences, classes)
    else:
        volFn = self._getFileName('reconstructedFileNamesIters',
                                  iter=lastIter,
                                  ref=1)
        halfMap1 = self._getFileName('reconstructedFileNamesItersSplit1',
                                     iter=lastIter,
                                     ref=1)
        halfMap2 = self._getFileName('reconstructedFileNamesItersSplit2',
                                     iter=lastIter,
                                     ref=1)

        vol = Volume()
        vol.setFileName(volFn)
        vol.setSamplingRate(imgSet.getSamplingRate())
        vol.setHalfMaps([halfMap1, halfMap2])
        self._defineOutputs(outputVolume=vol)
        self._defineSourceRelation(self.inputParticles, vol)
        self._defineSourceRelation(self.input3DReferences, vol)

        #create set of images
        imgSetOut = self._createSetOfParticles("_iter_%03d" % lastIter)
        self._fillParticlesFromIter(imgSetOut, lastIter)

        self._defineOutputs(outputParticles=imgSetOut)
        self._defineSourceRelation(self.inputParticles, imgSetOut)
        self._defineSourceRelation(self.input3DReferences, imgSetOut)