def processAndSaveAllImages(self): sys.stderr.write("Pre-processing images before picking\n") count = 0 total = len(self.imgtree) # if we are masking based on a previous mask run, and only want to process images with rejected masks, # remove any images with accepted masks from the imgtree. newImageTree = [] for imgdata in self.imgtree: count += 1 # useAccecepted mask is true when the assess flag is used, and an # accepted mask is found in the indicated mask run that should be retained self.useAcceptedMask = False # check to see if this image # 1. Does not have a mask region # 2. Has only mask regions that have been rejected # If both are true, continue, otherwise we do not need to display this image. filename = imgdata['filename'] maskAssessRunName = self.params['assessname'] sessiondata = apDatabase.getSessionDataFromSessionName( self.params['sessionname']) maskimg, maskbin = apMask.makeInspectedMask( sessiondata, maskAssessRunName, imgdata) if maskimg is not None and maskimg.size: apDisplay.printMsg("Skipping image with accepted mask region.") maskimg = apMask.reshapeMask(imgdata['image'], maskimg) self.maskimg = maskimg self.image = imgdata['image'] self.useAcceptedMask = True self.commitToDatabase(imgdata) continue imgpath = os.path.join(self.params['rundir'], imgdata['filename'] + '.dwn.mrc') if self.params['continue'] is True and os.path.isfile(imgpath): sys.stderr.write(".") #print "already processed: ",apDisplay.short(imgdata['filename']) else: if os.path.isfile(imgpath): os.remove(imgpath) sys.stderr.write("#") apFindEM.processAndSaveImage(imgdata, params=self.params) newImageTree.append(imgdata) if count % 60 == 0: sys.stderr.write(" %d left\n" % (total - count)) self.imgtree = newImageTree
def loopProcessImage(self, imgdata): """ Over-writes the particleLoop processImage and uses the appionLoop processImage """ #GET THE TILT PAIR tiltdata = apTiltPair.getTiltPair(imgdata) if tiltdata is None: return ### process images procimgpath = os.path.join(self.params['rundir'], imgdata['filename'] + '.dwn.mrc') if not os.path.isfile(procimgpath): apDisplay.printMsg("processing mrc for first image") apFindEM.processAndSaveImage(imgdata, params=self.params) procimg1 = apImage.mrcToArray(procimgpath, msg=False) procimgpath = os.path.join(self.params['rundir'], tiltdata['filename'] + '.dwn.mrc') if not os.path.isfile(procimgpath): apDisplay.printMsg("processing mrc for second image") apFindEM.processAndSaveImage(tiltdata, params=self.params) procimg2 = apImage.mrcToArray(procimgpath, msg=False) #RUN THE ALIGNER GUI result = self.runTiltAligner(imgdata, tiltdata) if self.badprocess is True: return numpeaks = len(self.peaktree1) #apDisplay.printMsg("Found "+str(numpeaks)+" particles for "+apDisplay.shortenImageName(imgdata['filename'])) self.stats['lastpeaks'] = numpeaks ### mask the images procimg1, procimg2 = apTiltTransform.maskOverlapRegion( procimg1, procimg2, self.data) #CREATE PEAK JPEG if self.threadJpeg is True: threading.Thread(target=apPeaks.createTiltedPeakJpeg, args=(imgdata, tiltdata, self.peaktree1, self.peaktree2, self.params, procimg1, procimg2)).start() else: apPeaks.createTiltedPeakJpeg(imgdata, tiltdata, self.peaktree1, self.peaktree2, self.params, procimg1, procimg2) #EXTRA DONE DICT CALL self._writeDoneDict(tiltdata['filename'])
def processAndSaveAllImages(self): sys.stderr.write("Pre-processing images before picking\n") count = 0 total = len(self.imgtree) # if we are masking based on a previous mask run, and only want to process images with rejected masks, # remove any images with accepted masks from the imgtree. newImageTree = [] for imgdata in self.imgtree: count += 1 # useAccecepted mask is true when the assess flag is used, and an # accepted mask is found in the indicated mask run that should be retained self.useAcceptedMask = False # check to see if this image # 1. Does not have a mask region # 2. Has only mask regions that have been rejected # If both are true, continue, otherwise we do not need to display this image. filename = imgdata['filename'] maskAssessRunName = self.params['assessname'] sessiondata = apDatabase.getSessionDataFromSessionName(self.params['sessionname']) maskimg,maskbin = apMask.makeInspectedMask( sessiondata, maskAssessRunName, imgdata ) if maskimg is not None and maskimg.size: apDisplay.printMsg("Skipping image with accepted mask region.") maskimg = apMask.reshapeMask( imgdata['image'], maskimg ) self.maskimg = maskimg self.image = imgdata['image'] self.useAcceptedMask = True self.commitToDatabase(imgdata) continue imgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc') if self.params['continue'] is True and os.path.isfile(imgpath): sys.stderr.write(".") #print "already processed: ",apDisplay.short(imgdata['filename']) else: if os.path.isfile(imgpath): os.remove(imgpath) sys.stderr.write("#") apFindEM.processAndSaveImage(imgdata, params=self.params) newImageTree.append(imgdata) if count % 60 == 0: sys.stderr.write(" %d left\n" % (total-count)) self.imgtree = newImageTree
def processAndSaveAllImages(self): sys.stderr.write("Pre-processing images before picking\n") #print self.params count = 0 total = len(self.imgtree) for imgdata in self.imgtree: count += 1 imgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc') if self.params['continue'] is True and os.path.isfile(imgpath): sys.stderr.write(".") #print "already processed: ",apDisplay.short(imgdata['filename']) else: if os.path.isfile(imgpath): os.remove(imgpath) sys.stderr.write("#") apFindEM.processAndSaveImage(imgdata, params=self.params) if count % 60 == 0: sys.stderr.write(" %d left\n" % (total-count))
def loopProcessImage(self, imgdata): """ Over-writes the particleLoop processImage and uses the appionLoop processImage """ #GET THE TILT PAIR tiltdata = apTiltPair.getTiltPair(imgdata) if tiltdata is None: return ### process images procimgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc') if not os.path.isfile(procimgpath): apDisplay.printMsg("processing mrc for first image") apFindEM.processAndSaveImage(imgdata, params=self.params) procimg1 = apImage.mrcToArray(procimgpath, msg=False) procimgpath = os.path.join(self.params['rundir'], tiltdata['filename']+'.dwn.mrc') if not os.path.isfile(procimgpath): apDisplay.printMsg("processing mrc for second image") apFindEM.processAndSaveImage(tiltdata, params=self.params) procimg2 = apImage.mrcToArray(procimgpath, msg=False) #RUN THE ALIGNER GUI result = self.runTiltAligner(imgdata, tiltdata) if self.badprocess is True: return numpeaks = len(self.peaktree1) #apDisplay.printMsg("Found "+str(numpeaks)+" particles for "+apDisplay.shortenImageName(imgdata['filename'])) self.stats['lastpeaks'] = numpeaks ### mask the images procimg1, procimg2 = apTiltTransform.maskOverlapRegion(procimg1, procimg2, self.data) #CREATE PEAK JPEG if self.threadJpeg is True: threading.Thread(target=apPeaks.createTiltedPeakJpeg, args=(imgdata, tiltdata, self.peaktree1, self.peaktree2, self.params, procimg1, procimg2)).start() else: apPeaks.createTiltedPeakJpeg(imgdata, tiltdata, self.peaktree1, self.peaktree2, self.params, procimg1, procimg2) #EXTRA DONE DICT CALL self._writeDoneDict(tiltdata['filename'])
def processAndSaveAllImages(self): print "Pre-processing images before picking\nNow is a good time to go get a candy bar" count = 0 total = len(self.imgtree) for imgdata in self.imgtree: count += 1 tiltdata = apTiltPair.getTiltPair(imgdata) if tiltdata is None: #reject it apDatabase.insertImgAssessmentStatus(imgdata, "notiltpair", False) continue #First the image imgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc') if os.path.isfile(imgpath): sys.stderr.write(".") #print "already processed: ",apDisplay.short(imgdata['filename']) else: sys.stderr.write("#") #print "processing: ",apDisplay.short(imgdata['filename']) apFindEM.processAndSaveImage(imgdata, params=self.params) #Now for its tilt pair tiltpath = os.path.join(self.params['rundir'], tiltdata['filename']+'.dwn.mrc') if os.path.isfile(tiltpath): sys.stderr.write(".") #print "already processed: ",apDisplay.short(tiltdata['filename']) else: sys.stderr.write("#") #print "processing: ",apDisplay.short(tiltdata['filename']) apFindEM.processAndSaveImage(tiltdata, params=self.params) if count % 30 == 0: sys.stderr.write(" %d left\n" % (total-count)) ### check if automation was already run outname1 = os.path.basename(imgdata['filename'])+"."+self.getExtension() outname2 = os.path.basename(tiltdata['filename'])+"."+self.getExtension() outfile1 = os.path.join(self.params['pickdatadir'], outname1) outfile2 = os.path.join(self.params['pickdatadir'], outname2) if os.path.isfile(outfile1): sys.stderr.write(",") else: ### set important parameters picks1 = self.getParticlePicks(imgdata, False) picks2 = self.getParticlePicks(tiltdata, False) pixdiam = self.params['diam']/self.params['apix']/self.params['bin'] tilt1 = apDatabase.getTiltAngleDeg(imgdata) tilt2 = apDatabase.getTiltAngleDeg(tiltdata) tiltdiff = abs(tilt2) - abs(tilt1) tiltaxis = self.params['inittiltaxis'] ### run tilt automation if self.params['autopick'] is True and self.params['importalign'] is False: if len(picks1) > 0 and len(picks2) > 0: autotilter = autotilt.autoTilt() result = autotilter.processTiltPair(imgpath, tiltpath, picks1, picks2, tiltdiff, outfile1, pixdiam, tiltaxis, msg=False) if os.path.isfile(outfile1): if os.path.exists(outfile2): os.remove(outfile2) os.symlink(os.path.basename(outfile1), outfile2) sys.stderr.write("%") apDisplay.printMsg("done") return
def processImage(self, imgdata, filterarray): if self.params['sessionname'] is not None: apFindEM.processAndSaveImage(imgdata, params=self.params) self.runManualPicker(imgdata)
def runFindEM(imgdict, params, thread=False): """ runs a separate thread of findem.exe for each template to get cross-correlation maps """ ### check image apFindEM.processAndSaveImage(imgdict, params) dwnimgname = imgdict['filename'] + ".dwn.mrc" if not os.path.isfile(dwnimgname): apDisplay.printError("cound not find image to process: " + dwnimgname) ### check template if len(params['templatelist']) < 1: apDisplay.printError("templatelist == 0; there are no templates") joblist = [] ccmapfilelist = [] t0 = time.time() for i, templatename in enumerate(params['templatelist']): classavg = i + 1 #DETERMINE OUTPUT FILE NAME #CHANGE THIS TO BE 00%i in future numstr = "%03d" % classavg #numstr = str(classavg%10)+"00" ccmapfile = "cccmaxmap" + numstr + ".mrc" apFile.removeFile(ccmapfile) #GET FINDEM RUN COMMANDS feed = findEMString(classavg, templatename, dwnimgname, ccmapfile, params) #RUN THE PROGRAM if thread is True: job = findemjob(feed) joblist.append(job) job.start() else: execFindEM(feed) #TO REMOVE LATER: Fake output fakeOutput(dwnimgname, ccmapfile, params) #STORE OUTPUT FILE ccmapfilelist.append(ccmapfile) ### WAIT FOR THREADS TO COMPLETE if thread is True: apDisplay.printMsg("waiting for " + str(len(joblist)) + " findem threads to complete") for i, job in enumerate(joblist): while job.isAlive(): sys.stderr.write(".") time.sleep(1.5) sys.stderr.write("\n") apDisplay.printMsg("FindEM finished in " + apDisplay.timeString(time.time() - t0)) for ccmapfile in ccmapfilelist: if not os.path.isfile(ccmapfile): apDisplay.printError("findem.exe did not run or crashed.\n") return ccmapfilelist
def runFindEM(imgdict, params, thread=False): """ runs a separate thread of findem.exe for each template to get cross-correlation maps """ ### check image apFindEM.processAndSaveImage(imgdict, params) dwnimgname = imgdict['filename']+".dwn.mrc" if not os.path.isfile(dwnimgname): apDisplay.printError("cound not find image to process: "+dwnimgname) ### check template if len(params['templatelist']) < 1: apDisplay.printError("templatelist == 0; there are no templates") joblist = [] ccmapfilelist = [] t0 = time.time() for i,templatename in enumerate(params['templatelist']): classavg = i + 1 #DETERMINE OUTPUT FILE NAME #CHANGE THIS TO BE 00%i in future numstr = "%03d" % classavg #numstr = str(classavg%10)+"00" ccmapfile="cccmaxmap"+numstr+".mrc" apFile.removeFile(ccmapfile) #GET FINDEM RUN COMMANDS feed = findEMString(classavg, templatename, dwnimgname, ccmapfile, params) #RUN THE PROGRAM if thread is True: job = findemjob(feed) joblist.append(job) job.start() else: execFindEM(feed) #TO REMOVE LATER: Fake output fakeOutput(dwnimgname,ccmapfile,params) #STORE OUTPUT FILE ccmapfilelist.append(ccmapfile) ### WAIT FOR THREADS TO COMPLETE if thread is True: apDisplay.printMsg("waiting for "+str(len(joblist))+" findem threads to complete") for i,job in enumerate(joblist): while job.isAlive(): sys.stderr.write(".") time.sleep(1.5) sys.stderr.write("\n") apDisplay.printMsg("FindEM finished in "+apDisplay.timeString(time.time()-t0)) for ccmapfile in ccmapfilelist: if not os.path.isfile(ccmapfile): apDisplay.printError("findem.exe did not run or crashed.\n") return ccmapfilelist
def processImage(self, imgdata,filterarray): if self.params['sessionname'] is not None: apFindEM.processAndSaveImage(imgdata, params=self.params) self.runManualLocalMasker(imgdata)