def _getIterClasses(self, it, clean=False): """ Return a classes .sqlite file for this iteration. If the file doesn't exists, it will be created by converting from this iteration data.star file. """ data_classes = self._getFileName('classes_scipion', iter=it) if clean: cleanPath(data_classes) if not exists(data_classes): clsSet = em.SetOfClasses2D(filename=data_classes) clsSet.setImages(self._getInputParticles()) self._fillClassesFromIter(clsSet, it) clsSet.write() clsSet.close() return data_classes
def _getLevelClasses(self, lev, suffix, clean=False): """ Return a classes .sqlite file for this level. If the file doesn't exists, it will be created by converting from this level level_images.xmd file. """ dataClasses = self._getFileName('classes_scipion', level=lev, sub=suffix) if clean: cleanPath(dataClasses) if not exists(dataClasses): clsSet = em.SetOfClasses2D(filename=dataClasses) clsSet.setImages(self.inputParticles.get()) self._fillClassesFromLevel(clsSet, level=lev, subset=suffix) clsSet.write() clsSet.close() return dataClasses
def createOutputClasses(self, suffix, streamingState, fillCls): baseName = '%sClasses.sqlite' % suffix setFile = self._getPath(baseName) if os.path.exists(setFile): outputSet = em.SetOfClasses2D(filename=setFile) outputSet.loadAllProperties() outputSet.enableAppend() else: outputSet = em.SetOfClasses2D(filename=setFile) outputSet.setStreamState(streamingState) outputSet.copyInfo(self.inputClasses.get()) # if fails, delete if fillCls: # FIXME: Review this !!! decision = ACCEPTED if suffix == 'output' else DISCARDED print("in createOutput... %s" % ('ACCEPTED' if suffix == 'output' else 'DISCARDED')) desiredIds = [ ids for ids, enable in self.enableCls.iteritems() if enable == decision ] print("self.enableCls: %s" % self.enableCls) print("desiredIds: %s" % desiredIds) for cls in self.inputClasses.get(): repId = cls.getObjId() if repId in desiredIds: representative = cls.getRepresentative() newClass = em.Class2D(objId=repId) newClass.setAlignment2D() newClass.copyInfo(self.inputImages) newClass.setAcquisition(self.inputImages.getAcquisition()) newClass.setRepresentative(representative) newClass.setStreamState(streamingState) outputSet.append(newClass) for cls in self.inputClasses.get(): repId = cls.getObjId() if repId in desiredIds: newClass = outputSet[repId] for img in cls: newClass.append(img) outputSet.update(newClass) self.enableCls.update({idItem: ATTACHED for idItem in desiredIds}) outputSet.setStreamState(streamingState) outputName = '%sClasses' % suffix if self.hasAttribute(outputName): outputSet.write() # Write to commit changes outputAttr = getattr(self, outputName) # Copy the properties to the object contained in the protocol outputAttr.copy(outputSet, copyId=False) # Persist changes self._store(outputAttr) else: # FIXME: no outputClasses are generated because they are corrupted. # self._defineOutputs(**{outputName: outputSet}) # self._defineSourceRelation(self.inputClasses, outputSet) self._store(outputSet) # Close set databaset to avoid locking it outputSet.close()