def getContourPointsFromContour(contourdata):
        q = appiondata.ApContourPointData(contour=contourdata)
        pointresults = q.query()
        points = []
        for pointdata in pointresults:
                points.append((pointdata['x'],pointdata['y']))
        return points   
	def loadOld(self,imgdata):
		partq = appiondata.ApContourData()
		partq['image'] = imgdata
		partd = partq.query()
		try: 
			name = partd[0]['name']
			self.startPoint = name.lstrip('contour')
		except IndexError:
			self.startPoint = 0		
		points = appiondata.ApContourPointData()
		oldPolyPoints = []
		contourPoints = []
		types = []
		singleTypes = []
		singleTargets = []
		tubePoints = []
		self.maxVersion = -1
		bin = float(self.params['bin'])
		for i in partd:
			if not i['version']==None and int(i['version'])>self.maxVersion and i['runname']==self.params['runname']:
				self.maxVersion = int(i['version'])
		for i in partd:
			if not i['version']==None and int(i['version'])==self.maxVersion and not i['method']=='single' and i['runname']==self.params['runname']:
				contourPoints.append((i['x'],i['y']))
				types.append(i['particleType'])
				contour = i['name']
				points['contour'] = i
				point = points.query()
				contourList = []
				for j in point:
					contourList.append((int(j['x']/bin), int(j['y'])/bin))
				oldPolyPoints.append(contourList)
		return self.app.loadOld((contourPoints,oldPolyPoints,types))
	def upgradeAppionDB(self):
		if self.appion_dbupgrade.tableExists('ApContourPointData'):
			q = appiondata.ApContourPointData()
			results = q.query()
			for pointdata in results:
				bin = pointdata['contour']['selectionrun']['manparams']['bin']
				pointid = pointdata.dbid
				new_x = pointdata['x']*bin
				new_y = pointdata['y']*bin
				self.appion_dbupgrade.updateColumn('ApContourPointData','x',new_x,'`DEF_id`=%d' % pointid, timestamp=False)
				self.appion_dbupgrade.updateColumn('ApContourPointData','y',new_y,'`DEF_id`=%d' % pointid, timestamp=False)
	def runManualPicker(self, imgdata):
		# Contourpicker does not do assessment.  Setting the current assessment to be
		# the same as the old prevents committing it to the database
		self.assessold = None
		self.assess = self.assessold
		#reset targets
		self.targets = {}
		for label in self.labels:
			self.app.panel.setTargets(label, [])
			self.targets[label] = []

					
		#open new file
		imgname = imgdata['filename']+'.dwn.mrc'
		imgpath = os.path.join(self.params['rundir'],imgname)
		self.app.panel.openImageFile(imgpath)

		self.app.panel.originaltargets = {}

		#set vital stats
		self.app.vitalstats.SetLabel("Vital Stats: Image "+str(self.stats['count'])
			+" of "+str(self.stats['imagecount'])
			+" image name: "+imgdata['filename'])
		#run the picker
		self.loadOld(imgdata)
		self.app.MainLoop()

		#targets are copied to self.targets by app
		#parse and return the targets in peaktree form
		self.app.panel.openImageFile(None)
		peaktree=[]
		for label,targets in self.targets.items():
			for target in targets:
				peaktree.append(self.XY2particle(target.x, target.y, label=label))
		
		targetsList = self.getPolyParticlePoints()
		contourTargets = self.app.panel.getTargets('Auto Create Contours')

		try:
			rundata = apParticle.getSelectionRunDataFromName(imgdata,self.params['runname'])
		except IndexError:
			# the first image does not have rundata in the database, yet
			rundata = self.commitRunToDatabase(imgdata['session'], True)
		bin = rundata['manparams']['bin']
		c = None
		counter = 0
		for i in range(len(targetsList)):
			# safe-guard from 1 or 2 point target
			if len(targetsList[i]) < 3:
				apDisplay.printWarning('contour %d has only %d points....IGNORED' % (i,len(targetsList[i])))
				counter += 1
				continue
			c=appiondata.ApContourData(name="contour"+str(int(self.startPoint)+i), image=imgdata, x=contourTargets[counter].x, y=contourTargets[counter].y,version=self.maxVersion+1, method='auto', particleType=self.app.particleTypeList[counter], selectionrun=rundata)
			c.insert()
			counter += 1
			for point in targetsList[i]:
				# save points in the scale of the original image, like particles
				point1=appiondata.ApContourPointData(x=point[0]*bin, y=point[1]*bin, contour=c)
				point1.insert()

		return peaktree
예제 #5
0
    def start(self):
        sessionname = self.params['sessionname']
        runname = self.params['runname']
        preset = self.params['preset']

        sessionq = leginondata.SessionData(name=sessionname)
        presetq = leginondata.PresetData(name=preset)
        imgquery = leginondata.AcquisitionImageData()
        imgquery['preset'] = presetq
        imgquery['session'] = sessionq
        imgtree = imgquery.query(readimages=False)
        partq = appiondata.ApContourData()
        sessiond = sessionq.query()
        selectionid = apParticle.getSelectionIdFromName(runname, sessionname)
        if not selectionid:
            apDisplay.printWarning(
                'No Object Tracing Run found in database, Skipping.......')
            return
        selectionrundata = apParticle.getSelectionRunDataFromID(selectionid)

        file = open('contourpickerData-' + sessionname + '.txt', 'w')
        file.write('session_id ' + runname + '\n')
        file.write('usr_id ' + os.getlogin() + '\n')
        file.write('experiment_name ' + sessionname + '\n')
        file.write('experiment_description ' + sessiond[0]['comment'].strip() +
                   '\n')
        file.write('nimages ' + str(len(imgtree)) + '\n')

        for imgdata in imgtree:
            file.write('START_IMAGE' + '\n')
            partq['image'] = imgdata
            partq['selectionrun'] = selectionrundata
            partd = partq.query()
            if len(partd) > 0:
                file.write('image_refID ' + str(partd[0]['image'].dbid) + '\n')
            file.write('image_name ' + imgdata['filename'] + '\n')
            if len(partd) > 0:
                file.write('time_roi ' + str(partd[0].timestamp) + '\n')
            #file.write('time_roi ' + partd[0]['DEF_timestamp'] + '\n')
            file.write('dfac = 1\n')
            maxversion = 0
            numparticles = 0
            for part in partd:
                if int(part['version']) > maxversion:
                    maxversion = int(part['version'])
            for part in partd:
                if int(part['version']) == maxversion:
                    numparticles += 1
            file.write('version_id ' + str(maxversion) + '\n')
            file.write('ncontours ' + str(numparticles) + '\n')
            pointq = appiondata.ApContourPointData()
            for part in partd:
                if int(part['version']) == maxversion:
                    #		file.write('contour_number ' + )
                    file.write('method_used ' + part['method'] + ' ')
                    pointq['contour'] = part
                    pointd = pointq.query()
                    for point in pointd:
                        file.write(
                            str(point['x']) + ',' + str(point['y']) + ';')
                    file.write('\n')
            file.write('END_IMAGE' + '\n')