def createSetStep(self): setObj = self.createSetObject() inputObj = self.inputObject.get() other = self.other.get() if other and ',Volume' in other: volId = int(other.split(',')[0]) if isinstance(setObj, emobj.SetOfVolumes): volSet = emobj.SetOfVolumes(filename=self._dbName) output = volSet[volId] else: classSet = emobj.SetOfClasses3D(filename=self._dbName) output = classSet[volId].getRepresentative() self._defineOutputs(outputVolume=output) elif isinstance(inputObj, emobj.SetOfImages): self._createSubSetFromImages(inputObj) elif isinstance(inputObj, emobj.SetOfClasses): self._createSubSetFromClasses(inputObj) elif isinstance(inputObj, emobj.SetOfCTF): outputClassName = self.outputClassName.get() if outputClassName.startswith('SetOfMicrographs'): self._createMicsSubSetFromCTF(inputObj) elif isinstance(inputObj, emobj.SetOfAtomStructs): self._createSubSetFromAtomStructs(inputObj) elif isinstance(inputObj, MicrographsTiltPair): self._createSubSetFromMicrographsTiltPair(inputObj) elif isinstance(inputObj, ParticlesTiltPair): self._createSubSetFromParticlesTiltPair(inputObj) elif isinstance(inputObj, EMProtocol): if self.other.hasValue(): otherid = self.other.get() otherObj = self.getProject().mapper.selectById(int(otherid)) if isinstance(setObj, emobj.SetOfClasses): setObj.setImages(otherObj) self._createSubSetFromClasses(setObj) elif isinstance(setObj, emobj.SetOfImages): setObj.copyInfo(otherObj) # copy info from original images self._createSubSetFromImages(setObj) elif isinstance(setObj, emobj.SetOfNormalModes): self._createSimpleSubset(otherObj) else: if isinstance(setObj, emobj.SetOfVolumes): volSet = emobj.SetOfVolumes(filename=self._dbName) volSet.loadAllProperties() self._createSimpleSubset(volSet) else: self._createSimpleSubset(inputObj)
def createVolumesSqlite(self, files, path, samplingRate, updateItemCallback=None): pwutils.cleanPath(path) volSet = emobj.SetOfVolumes(filename=path) volSet.setSamplingRate(samplingRate) for volFn in files: vol = emobj.Volume() vol.setFileName(volFn) if updateItemCallback: updateItemCallback(vol) volSet.append(vol) volSet.write() volSet.close() return volSet
def createSetStep(self): sourceSet = self.inputObject.get() markedSet = self.createSetObject( ) # Set equal to sourceSet but marked with disabled other = self.other.get() print("Source: %s" % sourceSet) print("Output type: %s" % self.outputClassName) print("Subset (sqlite) file: %s" % self.sqliteFile) if other: print("Other: %s" % other) # New recommended way to create subsets: making the set responsible for his own subset process # Once all Sets implement appendFromSet and the if bellow is gone we can remove this "if" if getattr(markedSet, "USE_CREATE_COPY_FOR_SUBSET", False): markedSet.loadAllProperties() newSet = markedSet.createCopy(self._getPath(), copyInfo=True, copyItems=True) # Define outputs, may be use something more specific than "subset" self._defineOutputs(subset=newSet) return if other and ',Volume' in other: volId = int(other.split(',')[0]) if isinstance(markedSet, emobj.SetOfVolumes): volSet = emobj.SetOfVolumes(filename=self._dbName) output = volSet[volId] else: classSet = emobj.SetOfClasses3D(filename=self._dbName) output = classSet[volId].getRepresentative() self._defineOutputs(outputVolume=output) elif isinstance(sourceSet, emobj.SetOfImages): self._createSubSetFromImages(sourceSet) elif isinstance(sourceSet, emobj.SetOfClasses): self._createSubSetFromClasses(sourceSet) elif isinstance(sourceSet, emobj.SetOfCTF): outputClassName = self.outputClassName.get() if outputClassName.startswith('SetOfMicrographs'): self._createMicsSubSetFromCTF(sourceSet) elif isinstance(sourceSet, emobj.SetOfAtomStructs): self._createSubSetFromAtomStructs(sourceSet) elif isinstance(sourceSet, MicrographsTiltPair): self._createSubSetFromMicrographsTiltPair(sourceSet) elif isinstance(sourceSet, ParticlesTiltPair): self._createSubSetFromParticlesTiltPair(sourceSet) elif isinstance(sourceSet, EMProtocol): if self.other.hasValue(): otherid = self.other.get() otherObj = self.getProject().mapper.selectById(int(otherid)) if isinstance(markedSet, emobj.SetOfClasses): markedSet.setImages(otherObj) self._createSubSetFromClasses(markedSet) elif isinstance(markedSet, emobj.SetOfImages): markedSet.copyInfo( otherObj) # copy info from original images self._createSubSetFromImages(markedSet) elif isinstance(markedSet, emobj.SetOfNormalModes): self._createSimpleSubset(otherObj) else: if isinstance(markedSet, emobj.SetOfVolumes): volSet = emobj.SetOfVolumes(filename=self._dbName) volSet.loadAllProperties() self._createSimpleSubset(volSet) # Go for a generic way of creating the set the the # input set is not registered (typically from viewers) else: # We might want to do this before, inside the createSetObject markedSet.loadAllProperties() self._createSimpleSubset(markedSet) else: self._createSimpleSubset(sourceSet)