def subStackCmd(self): keepfile = os.path.join(self.params['rundir'], "keeplist-tot" + self.datastr + ".lst") stackdata = apStack.getRunsInStack(self.params['stackid']) cmd = ("subStack.py " + " --projectid=" + str(self.params['projectid']) + " --old-stack-id=" + str(self.params['stackid']) + " --commit" + " \\\n --keep-file=" + keepfile + " \\\n --new-stack-name=sub-" + stackdata[0]['stackRun']['stackRunName'] + " \\\n --description='sat from recon " + str(self.params['reconid']) + " iter " + str(self.iternum) + " with angle " + str(self.params['angle']) + " +/- " + str(self.params['cutrange']) + "' \n") print "New subStack.py Command:" apDisplay.printColor(cmd, "purple")
def subStackCmd(self): keepfile = os.path.join(self.params['rundir'], "keeplist-tot"+self.datastr+".lst") stackdata = apStack.getRunsInStack(self.params['stackid']) cmd = ( "subStack.py " +" --projectid="+str(self.params['projectid']) +" --old-stack-id="+str(self.params['stackid']) +" --commit" +" \\\n --keep-file="+keepfile +" \\\n --new-stack-name=sub-"+stackdata[0]['stackRun']['stackRunName'] +" \\\n --description='sat from recon "+str(self.params['reconid']) +" iter "+str(self.iternum) +" with angle "+str(self.params['angle']) +" +/- "+str(self.params['cutrange']) +"' \n" ) print "New subStack.py Command:" apDisplay.printColor(cmd, "purple")
def commitStack(self, stackid): startpart = self.partnum stackq = appiondata.ApStackData() oldstackdata = apStack.getOnlyStackData(stackid) stackq['name'] = self.params['stackfilename'] stackq['path'] = appiondata.ApPathData( path=os.path.abspath(self.params['rundir'])) stackq['description'] = self.params[ 'description'] + " ... combined stack ids " + str( self.params['stacks']) stackq['substackname'] = self.params['runname'] stackq['hidden'] = False stackq['pixelsize'] = self.newpixelsize * 1e-10 stackq['boxsize'] = self.newboxsize rinstackdata = apStack.getRunsInStack(stackid) for run in rinstackdata: rinstackq = appiondata.ApRunsInStackData() rinstackq['stack'] = stackq rinstackq['stackRun'] = run['stackRun'] rinstackq.insert() stpartsdata = apStack.getStackParticlesFromId(stackid) apDisplay.printMsg("inserting " + str(len(stpartsdata)) + " particles into DB") for particle in stpartsdata: stpartq = appiondata.ApStackParticleData() stpartq['particleNumber'] = self.partnum stpartq['stack'] = stackq stpartq['stackRun'] = particle['stackRun'] stpartq['particle'] = particle['particle'] stpartq.insert() self.partnum += 1 if self.partnum % 1000 == 0: sys.stderr.write(".") sys.stderr.write("\n") apDisplay.printMsg("commited particles " + str(startpart) + "-" + str(self.partnum)) return
def commitStack(self, stackid): startpart = self.partnum stackq = appiondata.ApStackData() oldstackdata = apStack.getOnlyStackData(stackid) stackq['name'] = self.params['stackfilename'] stackq['path'] = appiondata.ApPathData(path=os.path.abspath(self.params['rundir'])) stackq['description'] = self.params['description']+" ... combined stack ids "+str(self.params['stacks']) stackq['substackname'] = self.params['runname'] stackq['hidden'] = False stackq['pixelsize'] = self.newpixelsize*1e-10 stackq['boxsize'] = self.newboxsize rinstackdata = apStack.getRunsInStack(stackid) for run in rinstackdata: rinstackq = appiondata.ApRunsInStackData() rinstackq['stack'] = stackq rinstackq['stackRun'] = run['stackRun'] rinstackq.insert() stpartsdata = apStack.getStackParticlesFromId(stackid) apDisplay.printMsg("inserting "+str(len(stpartsdata))+" particles into DB") for particle in stpartsdata: stpartq = appiondata.ApStackParticleData() stpartq['particleNumber'] = self.partnum stpartq['stack'] = stackq stpartq['stackRun'] = particle['stackRun'] stpartq['particle'] = particle['particle'] stpartq.insert() self.partnum += 1 if self.partnum % 1000 == 0: sys.stderr.write(".") sys.stderr.write("\n") apDisplay.printMsg("commited particles "+str(startpart)+"-"+str(self.partnum)) return
def uploadResults(self): if self.params['commit'] is False: return # Produce new stacks oldstack = apStack.getOnlyStackData(self.params['notstackid'], msg=False) notstack = appiondata.ApStackData() notstack['path'] = appiondata.ApPathData(path=os.path.abspath(self.params['rundir'])) notstack['name'] = self.notstackdata['name'] if notstack.query(results=1): apDisplay.printError("A stack with these parameters already exists") tiltstack = appiondata.ApStackData() tiltstack['path'] = appiondata.ApPathData(path=os.path.abspath(self.params['rundir'])) tiltstack['name'] = self.tiltstackdata['name'] if tiltstack.query(results=1): apDisplay.printError("A stack with these parameters already exists") # Fill in data and submit notstack['oldstack'] = oldstack notstack['hidden'] = False notstack['substackname'] = self.params['runname'] notstack['description'] = self.params['description']+" ... tilt stack sorted" notstack['pixelsize'] = oldstack['pixelsize'] notstack.insert() tiltstack['oldstack'] = oldstack tiltstack['hidden'] = False tiltstack['substackname'] = self.params['runname'] tiltstack['description'] = self.params['description']+" ... tilt stack sorted" tiltstack['pixelsize'] = oldstack['pixelsize'] tiltstack.insert() # Insert stack images apDisplay.printMsg("Inserting stack particles") count=0 for partdict in parttree: count += 1 if count % 100 == 0: sys.stderr.write("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b") sys.stderr.write(str(count)+" of "+(str(total))+" complete") # Get particles from the old stacks oldnotparticle = apStack.getStackParticle(self.params['notstackid'], partdict['not']) oldtiltparticle = apStack.getStackParticle(self.params['tiltstackid'], partdict['tilt']) # Insert particle notparticle = appiondata.ApStackParticleData() notparticle.update(oldnotparticle) notparticle['particleNumber'] = count notparticle['stack'] = notstack notparticle.insert() tiltparticle = appiondata.ApStackParticleData() tiltparticle.update(oldtiltparticle) tiltparticle['particleNumber'] = count tiltparticle['stack'] = tiltstack tiltparticle.insert() apDisplay.printMsg("\n%d particles have been inserted into the tilt synchronized stacks"%(count)) # Insert runs in stack apDisplay.printMsg("Inserting Runs in Stack") runsinstack = apStack.getRunsInStack(self.params['notstackid']) for run in runsinstack: newrunsq = appiondata.ApRunsInStackData() newrunsq['stack'] = notstack newrunsq['stackRun'] = run['stackRun'] newrunsq.insert() runsinstack = apStack.getRunsInStack(self.params['tiltstackid']) for run in runsinstack: newrunsq = appiondata.ApRunsInStackData() newrunsq['stack'] = tiltstack newrunsq['stackRun'] = run['stackRun'] newrunsq.insert() apDisplay.printMsg("finished") return
def uploadResults(self): if self.params['commit'] is False: return # Get the new file order fh = open("sort_junk.sel", 'r') lines = fh.readlines() i = 0 fileorder = {} for line in lines: args = line.split() if (len(args) > 1): match = re.match('[A-Za-z]+([0-9]+)\.[A-Za-z]+', (args[0].split('/'))[-1]) if (match): filenumber = int(match.groups()[0]) fileorder[i] = filenumber i += 1 fh.close() # Produce a new stack oldstack = apStack.getOnlyStackData(self.params['stackid'], msg=False) newstack = appiondata.ApStackData() newstack['path'] = appiondata.ApPathData( path=os.path.abspath(self.params['rundir'])) newstack['name'] = "sorted.hed" if newstack.query(results=1): apDisplay.printError( "A stack with these parameters already exists") # Fill in data and submit newstack['oldstack'] = oldstack newstack['hidden'] = False newstack['substackname'] = self.params['runname'] newstack['description'] = self.params['description'] newstack['pixelsize'] = oldstack['pixelsize'] newstack['boxsize'] = oldstack['boxsize'] newstack['junksorted'] = True newstack.insert() # Insert stack images apDisplay.printMsg("Inserting stack particles") count = 0 total = len(fileorder.keys()) if total == 0: apDisplay.printError( "No particles can be inserted in the sorted stack") for i in fileorder.keys(): count += 1 if count % 100 == 0: sys.stderr.write( "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b") sys.stderr.write( str(count) + " of " + (str(total)) + " complete") # Get particle from the old stack oldparticle = apStack.getStackParticle(self.params['stackid'], fileorder[i] + 1) # Insert particle newparticle = appiondata.ApStackParticleData() newparticle['particleNumber'] = i + 1 newparticle['stack'] = newstack newparticle['stackRun'] = oldparticle['stackRun'] newparticle['particle'] = oldparticle['particle'] newparticle['mean'] = oldparticle['mean'] newparticle['stdev'] = oldparticle['stdev'] newparticle.insert() apDisplay.printMsg( "\n" + str(total) + " particles have been inserted into the sorted stack") # Insert runs in stack apDisplay.printMsg("Inserting Runs in Stack") runsinstack = apStack.getRunsInStack(self.params['stackid']) for run in runsinstack: newrunsq = appiondata.ApRunsInStackData() newrunsq['stack'] = newstack newrunsq['stackRun'] = run['stackRun'] newrunsq.insert() apDisplay.printMsg("finished") return
def uploadResults(self): if self.params['commit'] is False: return # Get the new file order fh=open("sort_junk.sel",'r') lines=fh.readlines() i=0; fileorder={}; for line in lines: args=line.split() if (len(args)>1): match=re.match('[A-Za-z]+([0-9]+)\.[A-Za-z]+', (args[0].split('/'))[-1]) if (match): filenumber=int(match.groups()[0]) fileorder[i]=filenumber i+=1 fh.close() # Produce a new stack oldstack = apStack.getOnlyStackData(self.params['stackid'],msg=False) newstack = appiondata.ApStackData() newstack['path'] = appiondata.ApPathData(path=os.path.abspath(self.params['rundir'])) newstack['name'] = "sorted.hed" if newstack.query(results=1): apDisplay.printError("A stack with these parameters already exists") # Fill in data and submit newstack['oldstack'] = oldstack newstack['hidden'] = False newstack['substackname'] = self.params['runname'] newstack['description'] = self.params['description'] newstack['pixelsize'] = oldstack['pixelsize'] newstack['boxsize'] = oldstack['boxsize'] newstack['junksorted'] = True newstack.insert() # Insert stack images apDisplay.printMsg("Inserting stack particles") count=0 total=len(fileorder.keys()) if total==0: apDisplay.printError("No particles can be inserted in the sorted stack") for i in fileorder.keys(): count += 1 if count % 100 == 0: sys.stderr.write("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b") sys.stderr.write(str(count)+" of "+(str(total))+" complete") # Get particle from the old stack oldparticle = apStack.getStackParticle(self.params['stackid'], fileorder[i]+1) # Insert particle newparticle = appiondata.ApStackParticleData() newparticle['particleNumber'] = i+1 newparticle['stack'] = newstack newparticle['stackRun'] = oldparticle['stackRun'] newparticle['particle'] = oldparticle['particle'] newparticle['mean'] = oldparticle['mean'] newparticle['stdev'] = oldparticle['stdev'] newparticle.insert() apDisplay.printMsg("\n"+str(total)+" particles have been inserted into the sorted stack") # Insert runs in stack apDisplay.printMsg("Inserting Runs in Stack") runsinstack = apStack.getRunsInStack(self.params['stackid']) for run in runsinstack: newrunsq = appiondata.ApRunsInStackData() newrunsq['stack'] = newstack newrunsq['stackRun'] = run['stackRun'] newrunsq.insert() apDisplay.printMsg("finished") return
appion database and output a new binned stack to the current directory. The new stack will be commited to the database """ sys.exit() #parse params params = {} params['stackid'] = int(sys.argv[1]) params['newstackname'] = sys.argv[2] params['bin'] = int(sys.argv[3]) params['newstackpath'] = os.getcwd() params['description'] = "stackid %d was scaled by a factor of %d" % ( params['stackid'], params['bin']) #check for multiple runs in stack runs_in_stack = apStack.getRunsInStack(params['stackid']) if len(runs_in_stack) > 1: print "scalestack.py can't scale this stack because it is a combination of multiple makestack runs." print "Instead, use makestack to create a new single scaled stack" sys.exit() #get stackdata stackdata = apStack.getStackParticlesFromId(params['stackid']) #do operations on stack print "Scaling stack" scaleStack(stackdata, params) #commit new stack to db print "Commiting new stack to db" commitScaledStack(stackdata, params)
scalestack.py will take a stack that has been uploaded to the appion database and output a new binned stack to the current directory. The new stack will be commited to the database """ sys.exit() #parse params params={} params['stackid']=int(sys.argv[1]) params['newstackname']=sys.argv[2] params['bin']=int(sys.argv[3]) params['newstackpath']=os.getcwd() params['description']="stackid %d was scaled by a factor of %d" % (params['stackid'],params['bin']) #check for multiple runs in stack runs_in_stack=apStack.getRunsInStack(params['stackid']) if len(runs_in_stack) > 1: print "scalestack.py can't scale this stack because it is a combination of multiple makestack runs." print "Instead, use makestack to create a new single scaled stack" sys.exit() #get stackdata stackdata=apStack.getStackParticlesFromId(params['stackid']) #do operations on stack print "Scaling stack" scaleStack(stackdata,params) #commit new stack to db print "Commiting new stack to db" commitScaledStack(stackdata,params)