def createOutputStep(self):
        # Create the SetOfImages object on the database
        fnImages = self._getOutputImgMd()
        # Create output SetOfParticles
        self.imgSet = self._createSetOfParticles()
        self.imgSet.copyInfo(self.inputMics)
        # set coords from the input, will update later if needed
        self.imgSet.setCoordinates(self.inputCoords)
        coords2 = SetOfCoordinates()

        if self.doFlip:
            self.imgSet.setIsPhaseFlipped(not self.inputMics.isPhaseFlipped())

        self.imgSet.setSamplingRate(self._getNewSampling())
        self.imgSet.setHasCTF(self.ctfRelations.hasValue())

        # a SetMdIterator is needed because in some cases, the number of
        # items in SetOfCoordinates and in the metadata could be different.
        iterator = md.SetMdIterator(fnImages, sortByLabel=md.MDL_ITEM_ID,
                                    updateItemCallback=self.createParticles,
                                    skipDisabled=True)
        # THis use case is special, because copyItems method is designed to
        # modified the same type of object of the input set. Here, a new type
        #  (SetOfParticles) is generated, and its needed an auxiliary set of
        # coordinates and it not stored.
        coordsAux = SetOfCoordinates()
        coordsAux.copyItems(self.inputCoords,
                            updateItemCallback=iterator.updateItem,
                            copyDisabled=True)

        self._storeMethodsInfo(fnImages)
        self._defineOutputs(outputParticles=self.imgSet)
        self._defineSourceRelation(self.inputCoordinates, self.imgSet)
        if self.ctfRelations.hasValue():
            self._defineSourceRelation(self.ctfRelations.get(), self.imgSet)
Exemplo n.º 2
0
    def createOutputStep(self):
        self.mdClasses = xmipp.MetaData(self._getDirectionalClassesFn())
        self.mdImages = xmipp.MetaData(self._getDirectionalImagesFn())

        inputParticles = self.inputParticles.get()
        classes2D = self._createSetOfClasses2D(inputParticles)

        self.averageSet = self._createSetOfAverages()
        self.averageSet.copyInfo(inputParticles)
        self.averageSet.setAlignmentProj()

        # Let's use a SetMdIterator because it could be less particles
        # in the metadata produced than in the input set
        iterator = md.SetMdIterator(self.mdImages,
                                    sortByLabel=md.MDL_ITEM_ID,
                                    updateItemCallback=self._updateParticle,
                                    skipDisabled=True)

        classes2D.classifyItems(updateItemCallback=iterator.updateItem,
                                updateClassCallback=self._updateClass)

        self._defineOutputs(outputClasses=classes2D)
        self._defineOutputs(outputAverages=self.averageSet)
        self._defineSourceRelation(self.inputParticles, classes2D)
        self._defineSourceRelation(self.inputParticles, self.averageSet)
    def createOutputStep(self):
        inputParticles = self.inputParticles.get()
        if not self._useSeveralClasses():
            newTs = inputParticles.getSamplingRate()
        else:
            newTs = self.readInfoField(self._getExtraPath(),"sampling",xmippLib.MDL_SAMPLINGRATE)

        self.mdClasses = xmippLib.MetaData(self._getDirectionalClassesFn())
        self.mdImages = xmippLib.MetaData(self._getDirectionalImagesFn())

        classes2D = self._createSetOfClasses2D(inputParticles)
        classes2D.getImages().setSamplingRate(newTs)

        self.averageSet = self._createSetOfAverages()
        self.averageSet.copyInfo(inputParticles)
        self.averageSet.setAlignmentProj()
        self.averageSet.setSamplingRate(newTs)

        # Let's use a SetMdIterator because it should be less particles
        # in the metadata produced than in the input set
        iterator = md.SetMdIterator(self.mdImages, sortByLabel=md.MDL_ITEM_ID,
                                    updateItemCallback=self._updateParticle,
                                    skipDisabled=True)

        fnHomogeneous = self._getExtraPath("images_homogeneous.xmd")
        if exists(fnHomogeneous):
            homogeneousSet = self._createSetOfParticles()
            homogeneousSet.copyInfo(inputParticles)
            homogeneousSet.setSamplingRate(newTs)
            homogeneousSet.setAlignmentProj()
            self.iterMd = md.iterRows(fnHomogeneous, md.MDL_PARTICLE_ID)
            self.lastRow = next(self.iterMd) 
            homogeneousSet.copyItems(inputParticles,
                                     updateItemCallback=self._updateHomogeneousItem)
            self._defineOutputs(outputHomogeneous=homogeneousSet)
            self._defineSourceRelation(self.inputParticles, homogeneousSet)

        classes2D.classifyItems(updateItemCallback=iterator.updateItem,
                                updateClassCallback=self._updateClass)

        self._defineOutputs(outputClasses=classes2D)
        self._defineOutputs(outputAverages=self.averageSet)
        self._defineSourceRelation(self.inputParticles, classes2D)
        self._defineSourceRelation(self.inputParticles, self.averageSet)

        if self.splitVolume and self.directionalClasses.get()>1:
            volumesSet = self._createSetOfVolumes()
            volumesSet.setSamplingRate(newTs)
            for i in range(2):
                vol = Volume()
                vol.setLocation(1, self._getExtraPath("split_v%d.vol"%(i+1)))
                volumesSet.append(vol)

            self._defineOutputs(outputVolumes=volumesSet)
            self._defineSourceRelation(inputParticles, volumesSet)
 def _fillClassesFromLevel(self, clsSet):
     """ Create the SetOfClasses2D from a given iteration. """
     myFileClasses = self._getExtraPath('last_classes.xmd')
     myFileImages = self._getExtraPath('last_images.xmd')
     self._loadClassesInfo(myFileClasses)
     xmpMd = myFileImages
     iterator = md.SetMdIterator(xmpMd, sortByLabel=md.MDL_ITEM_ID,
                                 updateItemCallback=self._updateParticle,
                                 skipDisabled=True)
     clsSet.classifyItems(updateItemCallback=iterator.updateItem,
                          updateClassCallback=self._updateClass)
 def _fillClassesFromLevel(self, clsSet):
     """ Create the SetOfClasses2D from a given iteration. """
     blocks = md.getBlocksInMetaDataFile(self._getExtraPath('output.xmd'))
     for bId, b in enumerate(blocks):
         if b.startswith('class0'):
             self._loadClassesInfo(
                 self._getExtraPath("level_00/%s_classes.stk" % b), bId)
             xmpMd = b + "@" + self._getExtraPath('output.xmd')
             iterator = md.SetMdIterator(
                 xmpMd,
                 sortByLabel=md.MDL_ITEM_ID,
                 updateItemCallback=self._updateParticle,
                 skipDisabled=True)
             clsSet.classifyItems(updateItemCallback=iterator.updateItem,
                                  updateClassCallback=self._updateClass)
Exemplo n.º 6
0
    def _fillClassesFromLevel(self, clsSet, level, subset):
        """ Create the SetOfClasses2D from a given iteration. """
        self._loadClassesInfo(self._getLevelMdClasses(lev=level,
                                                      subset=subset))

        if subset == '' and level == "last":
            xmpMd = self._getFileName('output_particles')
            if not exists(xmpMd):
                xmpMd = self._getLevelMdImages(level, subset)
        else:
            xmpMd = self._getLevelMdImages(level, subset)

        iterator = md.SetMdIterator(xmpMd,
                                    sortByLabel=md.MDL_ITEM_ID,
                                    updateItemCallback=self._updateParticle,
                                    skipDisabled=True)

        # itemDataIterator is not neccesary because, the class SetMdIterator
        # contain all the information about the metadata
        clsSet.classifyItems(updateItemCallback=iterator.updateItem,
                             updateClassCallback=self._updateClass)
    def createOutputStep(self):

        inputParticles = self.inputParticles.get()
        # if not self._useSeveralClasses():
        #     newTs = inputParticles.getSamplingRate()
        # else:
        #     newTs = self.readInfoField(self._getExtraPath(), "sampling",
        #                                xmipp.MDL_SAMPLINGRATE)

        self.mdClasses = xmippLib.MetaData(self._getDirectionalClassesFn())
        self.mdImages = xmippLib.MetaData(self._getDirectionalImagesFn())

        origTs = inputParticles.getSamplingRate()
        lastTs = self.readInfoField(self._getExtraPath(), "sampling",
                                       xmippLib.MDL_SAMPLINGRATE)

        if origTs!=lastTs:
            newXdim=inputParticles.getXDim()
            self.runJob("xmipp_image_resize", "-i %s -o %s --save_metadata_stack %s --fourier %d"
                        % (self._getDirectionalClassesFn(),
                           self._getPath("aux_directional_local_classes.stk"),
                           self._getPath("aux_directional_classes.xmd"),
                           newXdim), numberOfMpi=1)
            from shutil import copy
            copy(self._getPath("aux_directional_local_classes.stk"),
                 self._getPath("directional_local_classes.stk"))
            copy(self._getPath("aux_directional_classes.xmd"),
                 self._getPath("directional_classes.xmd"))
            cleanPattern(self._getPath("aux_directional*"))


        classes2D = self._createSetOfClasses2D(inputParticles)
        #classes2D.getImages().setSamplingRate(newTs)
        classes2D.getImages().setSamplingRate(origTs)

        self.averageSet = self._createSetOfAverages()
        self.averageSet.copyInfo(inputParticles)
        self.averageSet.setAlignmentProj()
        #self.averageSet.setSamplingRate(newTs)
        self.averageSet.setSamplingRate(origTs)

        # Let's use a SetMdIterator because it should be less particles
        # in the metadata produced than in the input set
        iterator = md.SetMdIterator(self.mdImages, sortByLabel=md.MDL_ITEM_ID,
                                    updateItemCallback=self._updateParticle,
                                    skipDisabled=True)

        fnHomogeneous = self._getExtraPath("images_homogeneous.xmd")
        if exists(fnHomogeneous):
            if origTs != lastTs:
                newXdim = inputParticles.getXDim()
                self.runJob("xmipp_image_resize", "-i %s --dim %d"
                            % (fnHomogeneous, newXdim), numberOfMpi=1)
            homogeneousSet = self._createSetOfParticles()
            homogeneousSet.copyInfo(inputParticles)
            #homogeneousSet.getImages().setSamplingRate(newTs)
            homogeneousSet.getImages().setSamplingRate(origTs)
            homogeneousSet.setAlignmentProj()
            self.iterMd = md.iterRows(fnHomogeneous, md.MDL_PARTICLE_ID)
            self.lastRow = next(self.iterMd)
            homogeneousSet.copyItems(inputParticles,
                                     updateItemCallback=self._updateHomogeneousItem)
            self._defineOutputs(outputHomogeneous=homogeneousSet)
            self._defineSourceRelation(self.inputParticles, homogeneousSet)

        #AJ testing
        #AJ por que desaparece una clase que tiene imagenes asignadas
        listRefId=[]
        for row in md.iterRows(self.mdClasses, xmippLib.MDL_REF2):

            refId = row.getValue(xmippLib.MDL_REF2, row.getObjId())
            if len(listRefId)>0 and refId != listRefId[-1]+1:
                whereEnd = listRefId[-1]+1
                for i in range(refId-whereEnd):
                    rowNew = row
                    rowNew.setValue(xmippLib.MDL_REF2, listRefId[-1]+i+1)
                    rowNew.setValue(xmippLib.MDL_IMAGE, 'None')
                    rowNew.setValue(xmippLib.MDL_IMAGE1, 'None')
                    rowNew.addToMd(self.mdClasses)
                    listRefId.append(listRefId[-1]+i+1)

                listRefId.append(refId)
            else:
                listRefId.append(refId)

        self.mdClasses.write(self._getDirectionalClassesFn())
        self.mdClasses = xmippLib.MetaData(self._getDirectionalClassesFn())
        #END AJ


        classes2D.classifyItems(updateItemCallback=iterator.updateItem,
                                updateClassCallback=self._updateClass)

        self._defineOutputs(outputClasses=classes2D)
        self._defineOutputs(outputAverages=self.averageSet)
        self._defineSourceRelation(self.inputParticles, classes2D)
        self._defineSourceRelation(self.inputParticles, self.averageSet)

        if self.splitVolume and self.directionalClasses.get() > 1:
            volumesSet = self._createSetOfVolumes()
            #volumesSet.setSamplingRate(newTs)
            volumesSet.setSamplingRate(origTs)
            for i in range(2):
                vol = Volume()
                if origTs != lastTs:
                    newXdim = inputParticles.getXDim()
                    self.runJob("xmipp_image_resize", "-i %s --dim %d"
                                % (self._getExtraPath("split%d.vol" % (i + 1)),
                                   newXdim), numberOfMpi=1)
                vol.setLocation(1, self._getExtraPath("split%d.vol" % (i + 1)))
                volumesSet.append(vol)

            self._defineOutputs(outputVolumes=volumesSet)
            self._defineSourceRelation(inputParticles, volumesSet)