コード例 #1
0
	def __isShortTiltSeries(self, tiltseriesdata):
		imgtree = apDatabase.getImagesFromTiltSeries(tiltseriesdata,False)
		imagelimit = self.params['imagelimit']
		is_short = len(imgtree) < imagelimit
		if is_short:
			apDisplay.printWarning("Tilt series has less than %d images" % imagelimit)
		return is_short
コード例 #2
0
    def _startLoop(self, tiltseriesdata):
        """
                initilizes several parameters for a new series
                and checks if it is okay to start processing series
                """
        #calc series left
        self.stats[
            'seriesleft'] = self.stats['seriescount'] - self.stats['count']

        if self.params['background'] is False:
            apDisplay.printColor(
                "\nStarting series %d ( skip:%d, remain:%d ) id:%d" % (
                    tiltseriesdata['number'],
                    self.stats['skipcount'],
                    self.stats['seriesleft'],
                    tiltseriesdata.dbid,
                ), "green")
        #only if a series was processed last
        if (self.stats['lastcount'] != self.stats['count']):
            sys.stderr.write("\n")
            self.stats['lastcount'] = self.stats['count']
            self._checkMemLeak()
        # skip if last image belong to the series doesn't exist:
        imgtree = apDatabase.getImagesFromTiltSeries(tiltseriesdata, False)
        imgpath = os.path.join(tiltseriesdata['session']['image path'],
                               imgtree[0]['filename'] + '.mrc')
        if not os.path.isfile(imgpath):
            apDisplay.printWarning(imgpath + " not found, skipping")
            return False

        # skip if there are some problem with the series
        if self.__isShortTiltSeries(tiltseriesdata) or self.isBadTiltSeries(
                tiltseriesdata):
            apDisplay.printWarning(
                "Series %d is not good enough for processing, skipping" %
                (tiltseriesdata['number']))
            seriesname = "series%3d" % (tiltseriesdata['number'])
            self._writeDoneDict(seriesname)
            self.stats['count'] += 1
            return False

        # check to see if series has already been processed
        if self._alreadyProcessed(tiltseriesdata):

            return False

        self.stats['waittime'] = 0

        if self.reprocessSeries(tiltseriesdata) is True:
            if self.params['background'] is True:
                sys.stderr.write(",")
            else:
                """apDisplay.printMsg("reprocessing series %d" % (tiltseriesdata['number']))"""
        else:
            if self.params['background'] is True:
                sys.stderr.write(".")
            else:
                """apDisplay.printMsg("processing series %d" % (tiltseriesdata['number']))"""

        return True
コード例 #3
0
	def processTiltSeries(self, tiltseriesdata):
		"""
		Call your processing command from here per tilt series
		Here we just print out the filenames of the images in the tilt series
		"""
		print "Tiltseries %d -------------------" % tiltseriesdata['number']
		imgtree = apDatabase.getImagesFromTiltSeries(tiltseriesdata,True)
		for imagedata in imgtree:
			print imagedata['filename']
コード例 #4
0
	def _startLoop(self, tiltseriesdata):
		"""
		initilizes several parameters for a new series
		and checks if it is okay to start processing series
		"""
		#calc series left
		self.stats['seriesleft'] = self.stats['seriescount'] - self.stats['count']

		if self.params['background'] is False:
			apDisplay.printColor( "\nStarting series %d ( skip:%d, remain:%d ) id:%d"
				%(tiltseriesdata['number'], self.stats['skipcount'], self.stats['seriesleft'], 
				tiltseriesdata.dbid,),
				"green")
		#only if a series was processed last
		if(self.stats['lastcount'] != self.stats['count']):
			sys.stderr.write("\n")
			self.stats['lastcount'] = self.stats['count']
			self._checkMemLeak()
		# skip if last image belong to the series doesn't exist:
		imgtree = apDatabase.getImagesFromTiltSeries(tiltseriesdata,False)
		imgpath = os.path.join(tiltseriesdata['session']['image path'], imgtree[0]['filename']+'.mrc')
		if not os.path.isfile(imgpath):
			apDisplay.printWarning(imgpath+" not found, skipping")
			return False

		# skip if there are some problem with the series
		if self.__isShortTiltSeries(tiltseriesdata) or self.isBadTiltSeries(tiltseriesdata):
			apDisplay.printWarning("Series %d is not good enough for processing, skipping" % (tiltseriesdata['number']))
			seriesname = "series%3d" % (tiltseriesdata['number'])
			self._writeDoneDict(seriesname)
			self.stats['count'] += 1
			return False

		# check to see if series has already been processed
		if self._alreadyProcessed(tiltseriesdata):
			
			return False

		self.stats['waittime'] = 0

		if self.reprocessSeries(tiltseriesdata) is True:
			if self.params['background'] is True:
				sys.stderr.write(",")
			else:
				"""apDisplay.printMsg("reprocessing series %d" % (tiltseriesdata['number']))"""
		else:
			if self.params['background'] is True:
				sys.stderr.write(".")
			else:
				"""apDisplay.printMsg("processing series %d" % (tiltseriesdata['number']))"""

		return True
コード例 #5
0
	def run(self):
		"""
		processes all series
		"""
		### get tilt series from database
		self._getAllSeries()
		os.chdir(self.params['rundir'])
		self.preLoopFunctions()
		### start the loop
		self.notdone=True
		self.badprocess = False
		self.stats['startloop'] = time.time()
		while self.notdone:
			apDisplay.printColor("\nBeginning Main Loop", "green")
			seriesnum = 0
			while seriesnum < len(self.seriestree) and self.notdone is True:
				self.stats['startseries'] = time.time()
				tiltseriesdata = self.seriestree[seriesnum]
				seriesnum += 1

				### CHECK IF IT IS OKAY TO START PROCESSING IMAGE
				if not self._startLoop(tiltseriesdata):
					continue

				### set the pixel size
				imgtree = apDatabase.getImagesFromTiltSeries(tiltseriesdata,False)
				self.params['apix'] = apDatabase.getPixelSize(imgtree[0])
				if not self.params['background']:
					apDisplay.printMsg("Pixel size: "+str(self.params['apix']))

				### START any custom functions HERE:
				results = self.loopProcessTiltSeries(tiltseriesdata)

				### WRITE db data
				if self.badprocess is False:
					if self.params['commit'] is True:
						if not self.params['background']:
							apDisplay.printColor(" ==== Committing data to database ==== ", "blue")
						self.loopCommitToDatabase(tiltseriesdata)
						self.commitResultsToDatabase(tiltseriesdata, results)
					else:
						apDisplay.printWarning("not committing results to database, all data will be lost")
						apDisplay.printMsg("to preserve data start script over and add 'commit' flag")
						self.writeResultsToFiles(tiltseriesdata, results)
				else:
					apDisplay.printWarning("IMAGE FAILED; nothing inserted into database")
					self.badprocess = False
					self.stats['lastpeaks'] = 0

				### FINISH with custom functions
				seriesname = "series%3d" % (tiltseriesdata['number'])
				self._writeDoneDict(seriesname)

				loadavg = os.getloadavg()[0]
				if loadavg > 2.0:
					apDisplay.printMsg("Load average is high "+str(round(loadavg,2)))
					loadsquared = loadavg*loadavg
					time.sleep(loadsquared)
					apDisplay.printMsg("New load average "+str(round(os.getloadavg()[0],2)))

				self._printSummary()

				if self.params['limit'] is not None and self.stats['count'] > self.params['limit']:
					apDisplay.printWarning("reached series limit of "+str(self.params['limit'])+"; now stopping")

				#END LOOP OVER IMAGES
			if self.notdone is True:
				self.notdone = self._waitForMoreSeries(timeout_min=self.params['timeout'])
			#END NOTDONE LOOP
		self.postLoopFunctions()
		self.close()