def _loadInput(self): partsFile = self.inputParticles.get().getFileName() inPartsSet = SetOfParticles(filename=partsFile) inPartsSet.loadAllProperties() if self.check == None: writeSetOfParticles(inPartsSet, self.fnInputMd, alignType=em.ALIGN_NONE, orderBy='creation') else: writeSetOfParticles(inPartsSet, self.fnInputMd, alignType=em.ALIGN_NONE, orderBy='creation', where='creation>"' + str(self.check) + '"') writeSetOfParticles(inPartsSet, self.fnInputOldMd, alignType=em.ALIGN_NONE, orderBy='creation', where='creation<"' + str(self.check) + '"') for p in inPartsSet.iterItems(orderBy='creation', direction='DESC'): self.check = p.getObjCreation() break streamClosed = inPartsSet.isStreamClosed() inputSize = inPartsSet.getSize() inPartsSet.close() return inputSize, streamClosed
class XmippProtEliminateEmptyParticles(XmippProtEliminateEmptyBase): """ Takes a set of particles and using statistical methods (variance of variances of sub-parts of input image) eliminates those samples, where there is no object/particle (only noise is presented there). Threshold parameter can be used for fine-tuning the algorithm for type of data. """ _label = 'eliminate empty particles' def __init__(self, **args): XmippProtEliminateEmptyBase.__init__(self, **args) # --------------------------- DEFINE param functions ---------------------- def _defineParams(self, form): form.addSection(label=Message.LABEL_INPUT) # - - - F O R P A R T I C L E S - - - form.addParam('inputParticles', param.PointerParam, important=True, label="Input particles", pointerClass='SetOfParticles', help='Select the input particles to be classified.') form.addParam('threshold', param.FloatParam, default=1.1, label='Threshold used in elimination:', help='Higher threshold => more particles will be ' 'eliminated. Set to -1 for no elimination, even so ' 'the "xmipp_scoreEmptiness" value will be attached to ' 'every paricle for a posterior inspection.') self.addAdvancedParams(form) # --------------------------- INSERT steps functions ---------------------- def _checkNewInput(self): # Check if there are new particles to process from the input set partsFile = self.inputParticles.get().getFileName() self.lastCheck = getattr(self, 'lastCheck', datetime.now()) mTime = datetime.fromtimestamp(os.path.getmtime(partsFile)) # If the input movies.sqlite have not changed since our last check, # it does not make sense to check for new input data if self.lastCheck > mTime: return None self.lastCheck = datetime.now() outputStep = self._getFirstJoinStep() fDeps = self._insertNewPartsSteps() if outputStep is not None: outputStep.addPrerequisites(*fDeps) self.updateSteps() def eliminationStep(self, fnInputMd): self.inputImages = self.inputParticles.get() partsFile = self.inputImages.getFileName() self.partsSet = SetOfParticles(filename=partsFile) self.partsSet.loadAllProperties() self.streamClosed = self.partsSet.isStreamClosed() if self.check == None: writeSetOfParticles(self.partsSet, fnInputMd, alignType=em.ALIGN_NONE, orderBy='creation') else: writeSetOfParticles(self.partsSet, fnInputMd, alignType=em.ALIGN_NONE, orderBy='creation', where='creation>"' + str(self.check) + '"') for p in self.partsSet.iterItems(orderBy='creation', direction='DESC'): self.check = p.getObjCreation() break self.partsSet.close() self.lenPartsSet = len(self.partsSet) print("os.path.exists(fnInputMd)): %s" % os.path.exists(fnInputMd)) args = "-i %s -o %s -e %s -t %f" % ( fnInputMd, self.fnOutputMd, self.fnElimMd, self.threshold.get()) if self.addFeatures: args += " --addFeatures" if self.useDenoising: args += " --useDenoising -d %f" % self.denoising.get() self.runJob("xmipp_image_eliminate_empty_particles", args) cleanPath(fnInputMd) def createOutputs(self): streamMode = Set.STREAM_CLOSED if getattr(self, 'finished', False) \ else Set.STREAM_OPEN def updateOutputs(mdFn, suffix): newData = os.path.exists(mdFn) lastToClose = getattr(self, 'finished', False) and \ hasattr(self, '%sParticles'%suffix) if newData or lastToClose: outSet = self._loadOutputSet(em.SetOfParticles, '%sParticles.sqlite' % suffix) if newData: partsSet = self._createSetOfParticles("AUX") readSetOfParticles(mdFn, partsSet) outSet.copyItems(partsSet, updateItemCallback=self._updateParticle, itemDataIterator=md.iterRows( mdFn, sortByLabel=md.MDL_ITEM_ID)) self.outputSize = self.outputSize + len(partsSet) self._updateOutputSet('%sParticles' % suffix, outSet, streamMode) cleanPath(mdFn) updateOutputs(self.fnOutMdTmp, 'output') updateOutputs(self.fnElimMdTmp, 'eliminated') def getInput(self): return self.inputParticles.get()