def createOutputStep(self): volInput = self.inputVolumes.get() if self._isSingleInput(): # Create the output with the same class as # the input, that should be Volume or a subclass # of Volume like VolumeMask volClass = volInput.getClass() vol = volClass() # Create an instance with the same class of input vol.copyInfo(volInput) vol.setLocation(1, self.outputStk) self._postprocessOutput(vol) self._defineOutputs(outputVol=vol) else: # ToDo: createSetOfVolumes not work properly when the protocol is resumed. volumes = self._createSetOfVolumes() volumes.copyInfo(volInput) self._preprocessOutput(volumes) numberOfVols = self.inputVolumes.get().getSize() for i in range(1, numberOfVols + 1): vol = Volume() vol.setLocation(i, self.outputStk) volumes.append(vol) self._postprocessOutput(volumes) self._defineOutputs(outputVol=volumes) self._defineTransformRelation(volInput, self.outputVol)
def createOutputStep(self): volInput = self.inputVolumes.get() if self._isSingleInput(): # Create the output with the same class as # the input, that should be Volume or a subclass # of Volume like VolumeMask volClass = volInput.getClass() vol = volClass() # Create an instance with the same class of input vol.copyInfo(volInput) vol.setLocation(1, self.outputStk) self._postprocessOutput(vol) self._defineOutputs(outputVol=vol) else: # ToDo: createSetOfVolumes not work properly when the protocol is resumed. volumes = self._createSetOfVolumes() volumes.copyInfo(volInput) self._preprocessOutput(volumes) numberOfVols = self.inputVolumes.get().getSize() for i in range(1, numberOfVols + 1): vol = Volume() vol.setLocation(i, self.outputStk) volumes.append(vol) self._postprocessOutput(volumes) self._defineOutputs(outputVol=volumes) self._defineTransformRelation(self.inputVolumes, self.outputVol)
def importVolumesStep(self, pattern, samplingRate): """ Copy images matching the filename pattern Register other parameters. """ self.info("Using pattern: '%s'" % pattern) # Create a Volume template object vol = Volume() vol.setSamplingRate(self.samplingRate.get()) copyOrLink = self.getCopyOrLink() imgh = ImageHandler() volSet = self._createSetOfVolumes() volSet.setSamplingRate(self.samplingRate.get()) for fileName, fileId in self.iterFiles(): dst = self._getExtraPath(basename(fileName)) copyOrLink(fileName, dst) x, y, z, n = imgh.getDimensions(dst) # First case considers when reading mrc without volume flag # Second one considers single volumes (not in stack) if (z == 1 and n != 1) or (z !=1 and n == 1): vol.setObjId(fileId) vol.setLocation(dst) volSet.append(vol) else: for index in range(1, n+1): vol.cleanObjId() vol.setLocation(index, dst) volSet.append(vol) if volSet.getSize() > 1: self._defineOutputs(outputVolumes=volSet) else: self._defineOutputs(outputVolume=vol)
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 createOutput(self): inputParticles = self.directionalClasses.get() volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(inputParticles.getSamplingRate()) 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 createOutput(self): inputParticles = self.directionalClasses.get() volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(inputParticles.getSamplingRate()) 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 createOutput(self): volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(self.inputParticles.get().getSamplingRate()) Nvols = len(self.splitPercentiles.get().split()) fnStack = self._getPath("splittedVolumes.stk") for i in range(Nvols): vol = Volume() vol.setLocation(i + 1, fnStack) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(self.inputParticles.get(), volumesSet)
def createOutput(self): volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(self.inputParticles.get().getSamplingRate()) Nvols = len(self.splitPercentiles.get().split()) fnStack = self._getPath("splittedVolumes.stk") for i in range(Nvols): vol = Volume() vol.setLocation(i+1, fnStack) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(self.inputParticles.get(), volumesSet)
def createOutputStep(self): volume = Volume() volume.setFileName(self._getExtraPath('sharpenedMap_last.mrc')) volume.setSamplingRate(self.inputVolume.get().getSamplingRate()) volume.setOrigin(self.inputVolume.get().getOrigin(True)) volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(self.inputVolume.get().getSamplingRate()) for i in range(self.iteration): vol = Volume() vol.setLocation( i, self._getExtraPath('sharpenedMap_%d.mrc' % (i + 1))) vol.setObjComment("Sharpened Map, \n Epoch %d" % (i + 1)) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(self.inputVolume, volumesSet)
def createOutputStep(self): volSet = self.inputVolumes.get() if self._isSingleInput(): vol = Volume() vol.copyInfo(volSet) if self.doResize: vol.setSamplingRate(self.samplingRate) vol.setFileName(self.outputStk) self._defineOutputs(outputVol=vol) else: volumes = self._createSetOfVolumes() volumes.copyInfo(volSet) if self.doResize: volumes.setSamplingRate(self.samplingRate) for i, vol in enumerate(volSet): j = i + 1 vol.setSamplingRate(self.samplingRate) vol.setLocation(j, self.outputStk) volumes.append(vol) self._defineOutputs(outputVol=volumes) self._defineTransformRelation(volSet, self.outputVol)
def createOutputStep(self): classListProtocols = [] classListIds = [] classListSizes = [] fnOutFile = self.inputMetaProt.get()._getExtraPath('auxOutputFile.txt') outFile = open(fnOutFile, 'r') nameRead = outFile.readline() while nameRead != '': nameRead = nameRead[:-1] for i, item in enumerate(self.inputSignifProts): if nameRead == self.inputSignifProts[i].get()._objLabel: classListProtocols.append(self.inputSignifProts[i].get()) idRead = outFile.readline() classListIds.append(int(idRead)) sizeRead = outFile.readline() classListSizes.append(int(sizeRead)) break nameRead = outFile.readline() # print(classListProtocols) # print(classListIds) # print(classListSizes) inputVolume = self.inputMetaProt.get().inputVolume myVolList = [] # outputVolumes = self._createSetOfVolumes('Def') # outputVolumes.setDim(inputVolume.get().getDim()) # outputVolumes.setSamplingRate(inputVolume.get().getSamplingRate()) origDim = inputVolume.get().getDim()[0] for i, prot in enumerate(classListProtocols): # print("createOutputStep ", i) classItem = prot.outputClasses[classListIds[i]] volFn = str(classItem._representative._filename) volFnOut = self._getExtraPath('outVol%d.vol' % (i + 1)) volDim = classItem._representative.getDim()[0] if volDim != origDim: self.runJob("xmipp_image_resize", "-i %s -o %s --fourier %d" % (volFn, volFnOut, origDim), numberOfMpi=self.numberOfMpi.get() * self.numberOfThreads.get()) else: copy(volFn, volFnOut) vol = Volume() vol.setLocation(volFnOut) vol.setSamplingRate(inputVolume.get().getSamplingRate()) myVolList.append(vol) # outputVolumes.append(vol) # self._defineOutputs(** {'outputVolumesDef': outputVolumes}) # self._store(outputVolumes) inputParticles = self.inputMetaProt.get().inputParticles outputDefClasses = self._createSetOfClasses3D(inputParticles.get(), 'Def') for i, prot in enumerate(classListProtocols): classItem = prot.outputClasses[classListIds[i]] signifInputParts = inputParticles.get() partIds = classItem.getIdSet() newClass = Class3D() newClass.copyInfo(signifInputParts) newClass.setAcquisition(signifInputParts.getAcquisition()) newClass.setRepresentative(myVolList[i]) outputDefClasses.append(newClass) enabledClass = outputDefClasses[newClass.getObjId()] enabledClass.enableAppend() for itemId in partIds: enabledClass.append(signifInputParts[itemId]) outputDefClasses.update(enabledClass) self._defineOutputs(**{'outputClasses3DDef': outputDefClasses}) self._store(outputDefClasses)
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)