コード例 #1
0
    def createOutputStep(self):
        particles = self.inputParticles.get()

        # Generate the SetOfAlignmet
        alignedSet = self._createSetOfParticles()
        alignedSet.copyInfo(particles)

        inputMd = self._getPath('aligned_particles.xmd')
        alignedSet.copyItems(particles,
                             updateItemCallback=self._updateItem,
                             itemDataIterator=iterMdRows(inputMd))
        # Remove alignment 2D
        alignedSet.setAlignment(ALIGN_NONE)

        # Define the output average

        avgFile = self._getExtraPath("average.xmp")

        imgh = ImageHandler()
        avgImage = imgh.computeAverage(alignedSet)

        avgImage.write(avgFile)

        avg = Particle()
        avg.setLocation(1, avgFile)
        avg.copyInfo(alignedSet)

        self._defineOutputs(outputAverage=avg)
        self._defineSourceRelation(self.inputParticles, avg)

        self._defineOutputs(outputParticles=alignedSet)
        self._defineSourceRelation(self.inputParticles, alignedSet)
コード例 #2
0
ファイル: convert.py プロジェクト: denisfortun/scipion
def createClassesFromImages2(inputImages, inputMd, 
                             classesFn, ClassType, classLabel, 
                             alignType, getClassFn=None, preprocessImageRow=None):
    """ From an intermediate X.xmd file produced by xmipp, create
    the set of classes in which those images are classified.
    Params:
        inputImages: the SetOfImages that were initially classified by relion. 
        inputMd: the filename metadata.
        classesFn: filename where to write the classes.
        ClassType: the output type of the classes set ( usually SetOfClass2D or 3D )
        classLabel: label that is the class reference.
        classFnTemplate: the template to get the classes averages filenames
        iter: the iteration number, just used in Class template
    """
    mdIter = iterMdRows(inputMd)
    clsDict = {} # Dictionary to store the (classId, classSet) pairs
    clsSet = ClassType(filename=classesFn)
    clsSet.setImages(inputImages)
    hasCtf = inputImages.hasCTF()
    sampling = inputImages.getSamplingRate()
    
    for img, row in izip(inputImages, mdIter):
        ref = row.getValue(xmipp.MDL_REF)
        if ref is None:
            raise Exception('MDL_REF not found in metadata: %s' % inputMd)
        
        if not ref in clsDict: # Register a new class set if the ref was not found.
            classItem = clsSet.ITEM_TYPE(objId=ref)
            if getClassFn is None:
                refFn = ''
            else:
                refFn = getClassFn(ref)
            refLocation = xmippToLocation(refFn)
            rep = clsSet.REP_TYPE()
            rep.setLocation(refLocation)
            rep.setSamplingRate(sampling)
            classItem.setRepresentative(rep)
            
            clsDict[ref] = classItem
            classItem.copyInfo(inputImages)
            classItem.setAlignment(alignType)
            classItem.setAcquisition(inputImages.getAcquisition())
            clsSet.append(classItem)
        else:
            classItem = clsDict[ref] # Try to get the class set given its ref number
        
        img.setTransform(rowToAlignment(row, alignType))
        classItem.append(img)
        
    for classItem in clsDict.values():
        clsSet.update(classItem)
        
    clsSet.write()
    return clsSet
コード例 #3
0
ファイル: convert.py プロジェクト: EyeSeeTea/scipion-web
def createClassesFromImages2(inputImages, inputMd, 
                             classesFn, ClassType, classLabel, 
                             alignType, getClassFn=None, preprocessImageRow=None):
    """ From an intermediate X.xmd file produced by xmipp, create
    the set of classes in which those images are classified.
    Params:
        inputImages: the SetOfImages that were initially classified by relion. 
        inputMd: the filename metadata.
        classesFn: filename where to write the classes.
        ClassType: the output type of the classes set ( usually SetOfClass2D or 3D )
        classLabel: label that is the class reference.
        classFnTemplate: the template to get the classes averages filenames
        iter: the iteration number, just used in Class template
    """
    mdIter = iterMdRows(inputMd)
    clsDict = {} # Dictionary to store the (classId, classSet) pairs
    clsSet = ClassType(filename=classesFn)
    clsSet.setImages(inputImages)
    hasCtf = inputImages.hasCTF()
    sampling = inputImages.getSamplingRate()
    
    for img, row in izip(inputImages, mdIter):
        ref = row.getValue(xmipp.MDL_REF)
        if ref is None:
            raise Exception('MDL_REF not found in metadata: %s' % inputMd)
        
        if not ref in clsDict: # Register a new class set if the ref was not found.
            classItem = clsSet.ITEM_TYPE(objId=ref)
            if getClassFn is None:
                refFn = ''
            else:
                refFn = getClassFn(ref)
            refLocation = xmippToLocation(refFn)
            rep = clsSet.REP_TYPE()
            rep.setLocation(refLocation)
            rep.setSamplingRate(sampling)
            classItem.setRepresentative(rep)
            
            clsDict[ref] = classItem
            classItem.copyInfo(inputImages)
            classItem.setAlignment(alignType)
            classItem.setAcquisition(inputImages.getAcquisition())
            clsSet.append(classItem)
        else:
            classItem = clsDict[ref] # Try to get the class set given its ref number
        
        img.setTransform(rowToAlignment(row, alignType))
        classItem.append(img)
        
    for classItem in clsDict.values():
        clsSet.update(classItem)
        
    clsSet.write()
    return clsSet
コード例 #4
0
ファイル: protocol_process.py プロジェクト: josegutab/scipion
    def createOutputStep(self):
        inputSet = self.inputParticles.get()
        # outputSet could be SetOfParticles, SetOfAverages or any future sub-class of SetOfParticles
        className = inputSet.getClassName()
        outputSet = self._createSetFromName(className)
        outputSet.copyInfo(inputSet)

        self._preprocessOutput(outputSet)
        
        outputSet.copyItems(inputSet, 
                            updateItemCallback=self._updateItem,
                            itemDataIterator=iterMdRows(self.outputMd))
        #readSetOfParticles(self.outputMd, outputSet)
        self._postprocessOutput(outputSet)
        
        outputKey = className.replace('SetOf', 'output')
        self._defineOutputs(**{outputKey: outputSet})
        self._defineTransformRelation(inputSet, outputSet)
コード例 #5
0
    def createOutputStep(self, outImgsFn):
        inputSet = self.inputSet.get()
        if isinstance(inputSet, SetOfClasses2D):
            outputSet = self._createSetOfClasses2D(inputSet.getImages())
            outputName = 'outputClasses'
        else: # SetOfAverages
            outputSet = self._createSetOfAverages()
            outputSet.setAlignment3D()
            outputName = 'outputAverages'
            
        md = xmipp.MetaData(outImgsFn)
        outputSet.copyInfo(inputSet)
        outputSet.copyItems(inputSet, 
                            updateItemCallback=self.updateItem,
                            itemDataIterator=iterMdRows(md))

        self._defineOutputs(**{outputName: outputSet})
        self._defineTransformRelation(inputSet, outputSet)