def _checkNewCTFs(self, micSet): """ Check for already computed CTF and update the output set. """ newCTFs = [] ctfDict = {} ctfSet = SetOfCTF(filename=self._getPath('ctfs.sqlite')) ctfSet.setMicrographs(self.inputMicrographs.get()) for ctf in ctfSet: ctfDict[ctf.getObjId()] = True if ctfDict: # it means there are previous ctfs computed ctfSet.loadAllProperties() if ctfSet.getSize(): ctfSet.enableAppend() else: ctfSet.setStreamState(ctfSet.STREAM_OPEN) for micFn, micDir, mic in self._iterMicrographs(micSet): if (exists(self._getMicrographDone(micDir)) and not mic.getObjId() in ctfDict): ctf = self._createCtfModel(mic) ctfSet.append(ctf) newCTFs.append(mic.getObjId()) return ctfSet, newCTFs
def _checkNewInput(self): if self.calculateConsensus: # Check if there are new ctf to process from the input set ctfsFile1 = self.inputCTF.get().getFileName() ctfsFile2 = self.inputCTF2.get().getFileName() self.lastCheck = getattr(self, 'lastCheck', datetime.now()) mTime = max(datetime.fromtimestamp(os.path.getmtime(ctfsFile1)), datetime.fromtimestamp(os.path.getmtime(ctfsFile2))) # 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 and hasattr(self, 'SetOfCtf1'): return None ctfsSet1 = SetOfCTF(filename=ctfsFile1) ctfsSet2 = SetOfCTF(filename=ctfsFile2) ctfsSet1.loadAllProperties() ctfsSet2.loadAllProperties() if len(self.allCtf1) > 0: newCtf1 = [ctf.clone() for ctf in ctfsSet1.iterItems(orderBy='creation', where='creation>"' + str( self.checkCtf1) + '"')] else: newCtf1 = [ctf.clone() for ctf in ctfsSet1] self.allCtf1 = self.allCtf1 + newCtf1 if len(newCtf1) > 0: for ctf in ctfsSet1.iterItems(orderBy='creation', direction='DESC'): self.checkCtf1 = ctf.getObjCreation() break if len(self.allCtf2) > 0: newCtf2 = [ctf.clone() for ctf in ctfsSet2.iterItems(orderBy='creation', where='creation>"' + str( self.checkCtf2) + '"')] else: newCtf2 = [ctf.clone() for ctf in ctfsSet2] self.allCtf2 = self.allCtf2 + newCtf2 if len(newCtf2) > 0: for ctf in ctfsSet2.iterItems(orderBy='creation', direction='DESC'): self.checkCtf2 = ctf.getObjCreation() break self.lastCheck = datetime.now() self.isStreamClosed = ctfsSet1.isStreamClosed() and \ ctfsSet2.isStreamClosed() ctfsSet1.close() ctfsSet2.close() outputStep = self._getFirstJoinStep() if len(set(self.allCtf1)) > len(set(self.processedDict)) and \ len(set(self.allCtf2)) > len(set(self.processedDict)): fDeps = self._insertNewCtfsSteps(ctfsSet1, ctfsSet2, self.insertedDict) if outputStep is not None: outputStep.addPrerequisites(*fDeps) self.updateSteps() else: ctfFile = self.inputCTF.get().getFileName() now = datetime.now() self.lastCheck = getattr(self, 'lastCheck', now) mTime = datetime.fromtimestamp(os.path.getmtime(ctfFile)) self.debug('Last check: %s, modification: %s' % (pwutils.prettyTime(self.lastCheck), pwutils.prettyTime(mTime))) # Open input ctfs.sqlite and close it as soon as possible ctfSet = self._loadInputCtfSet() self.isStreamClosed = ctfSet.isStreamClosed() self.allCtf1 = [m.clone() for m in ctfSet] ctfSet.close() # If the input ctfs.sqlite have not changed since our last check, # it does not make sense to check for new input data if self.lastCheck > mTime and hasattr(self, 'allCtf1'): return None self.lastCheck = now newCtf = any(ctf.getObjId() not in self.insertedDict for ctf in self.allCtf1) outputStep = self._getFirstJoinStep() if newCtf: fDeps = self._insertNewSelectionSteps(self.insertedDict, self.allCtf1) if outputStep is not None: outputStep.addPrerequisites(*fDeps) self.updateSteps()