def createPeakJpeg(imgdata, peaktree, params, procimgarray=None): if 'templatelist' in params: count = len(params['templatelist']) else: count = 1 bin = int(params["bin"]) diam = float(params["diam"]) apix = float(params["apix"]) binpixrad = diam/apix/2.0/float(bin) imgname = imgdata['filename'] jpegdir = os.path.join(params['rundir'],"jpgs") apParam.createDirectory(jpegdir, warning=False) if params['uncorrected']: imgarray = apDBImage.correctImage(imgdata) else: imgarray = imgdata['image'] if procimgarray is not None: #instead of re-processing image use one that is already processed... imgarray = procimgarray else: imgarray = apImage.preProcessImage(imgarray, bin=bin, planeReg=False, params=params) outfile = os.path.join(jpegdir, imgname+".prtl.jpg") msg = not params['background'] subCreatePeakJpeg(imgarray, peaktree, binpixrad, outfile, bin, msg) return
def processAndSaveImage(imgdata, params): imgpath = os.path.join(params['rundir'], imgdata['filename'] + ".dwn.mrc") if os.path.isfile(imgpath): return False #downsize and filter leginon image if params['uncorrected']: imgarray = apDBImage.correctImage(imgdata) else: imgarray = imgdata['image'] imgarray = apImage.preProcessImage(imgarray, params=params, msg=False) apImage.arrayToMrc(imgarray, imgpath, msg=False) return True
def processAndSaveImage(imgdata, params): imgpath = os.path.join(params['rundir'], imgdata['filename']+".dwn.mrc") if os.path.isfile(imgpath): return False #downsize and filter leginon image if params['uncorrected']: imgarray = apDBImage.correctImage(imgdata) else: imgarray = imgdata['image'] imgarray = apImage.preProcessImage(imgarray, params=params, msg=False) apImage.arrayToMrc(imgarray, imgpath, msg=False) return True
def runAce(matlab, imgdata, params, showprev=True): imgname = imgdata['filename'] if showprev is True: bestctfvalue, bestconf = ctfdb.getBestCtfValueForImage(imgdata) if bestctfvalue: print ( "Prev best: '"+bestctfvalue['acerun']['name']+"', conf="+ apDisplay.colorProb(bestconf)+", defocus="+str(round(-1.0*abs(bestctfvalue['defocus1']*1.0e6),2))+ " microns" ) if params['uncorrected']: tmpname='temporaryCorrectedImage.mrc' imgarray = apDBImage.correctImage(imgdata) imgpath = os.path.join(params['rundir'],tmpname) apImage.arrayToMrc(imgarray, imgpath) print "processing", imgpath else: imgpath = os.path.join(imgdata['session']['image path'], imgname+'.mrc') nominal = None if params['nominal'] is not None: nominal=params['nominal'] elif params['newnominal'] is True: nominal = ctfdb.getBestDefocusForImage(imgdata, msg=True) if nominal is None: nominal = imgdata['scope']['defocus'] if nominal is None or nominal > 0 or nominal < -15e-6: apDisplay.printWarning("Nominal should be of the form nominal=-1.2e-6"+\ " for -1.2 microns NOT:"+str(nominal)) #Neil's Hack #if 'autosample' in params and params['autosample']: # x = abs(nominal*1.0e6) # val = 1.585 + 0.057587 * x - 0.044106 * x**2 + 0.010877 * x**3 # resamplefr_override = round(val,3) # print "resamplefr_override=",resamplefr_override # pymat.eval(matlab, "resamplefr="+str(resamplefr_override)+";") pymat.eval(matlab,("dforig = %e;" % nominal)) if params['stig'] == 0: plist = (imgpath, params['outtextfile'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/") acecmd = makeMatlabCmd("ctfparams = ace(",");",plist) else: plist = (imgname, imgpath, params['outtextfile'], params['opimagedir'], \ params['matdir'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/", params['resamplefr']) acecmd = makeMatlabCmd("ctfparams = measureAstigmatism(",");",plist) #print acecmd pymat.eval(matlab,acecmd) matfile = os.path.join(params['matdir'], imgname+".mrc.mat") if params['stig']==0: savematcmd = "save('"+matfile+"','ctfparams','scopeparams', 'dforig');" pymat.eval(matlab,savematcmd) ctfvalue = pymat.get(matlab, 'ctfparams') ctfvalue=ctfvalue[0] ctfdb.printResults(params, nominal, ctfvalue) return ctfvalue
def runAce(matlab, imgdata, params, showprev=True): imgname = imgdata['filename'] if showprev is True: bestctfvalue = ctfdb.getBestCtfByResolution(imgdata) if bestctfvalue: bestconf = ctfdb.calculateConfidenceScore(bestctfvalue) print ( "Prev best: '"+bestctfvalue['acerun']['name']+"', conf="+ apDisplay.colorProb(bestconf)+", defocus="+str(round(-1.0*abs(bestctfvalue['defocus1']*1.0e6),2))+ " microns" ) if params['uncorrected']: tmpname='temporaryCorrectedImage.mrc' imgarray = apDBImage.correctImage(imgdata) imgpath = os.path.join(params['rundir'],tmpname) apImage.arrayToMrc(imgarray, imgpath) print "processing", imgpath else: imgpath = os.path.join(imgdata['session']['image path'], imgname+'.mrc') nominal = None if params['nominal'] is not None: nominal=params['nominal'] elif params['newnominal'] is True: bestctfvalue = ctfdb.getBestCtfByResolution(imgdata) nominal = bestctfvalue['defocus1'] if nominal is None: nominal = imgdata['scope']['defocus'] if nominal is None or nominal > 0 or nominal < -15e-6: apDisplay.printWarning("Nominal should be of the form nominal=-1.2e-6"+\ " for -1.2 microns NOT:"+str(nominal)) #Neil's Hack #if 'autosample' in params and params['autosample']: # x = abs(nominal*1.0e6) # val = 1.585 + 0.057587 * x - 0.044106 * x**2 + 0.010877 * x**3 # resamplefr_override = round(val,3) # print "resamplefr_override=",resamplefr_override # pymat.eval(matlab, "resamplefr="+str(resamplefr_override)+";") pymat.eval(matlab,("dforig = %e;" % nominal)) if params['stig'] == 0: plist = (imgpath, params['outtextfile'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/") acecmd = makeMatlabCmd("ctfparams = ace(",");",plist) else: plist = (imgname, imgpath, params['outtextfile'], params['opimagedir'], \ params['matdir'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/", params['resamplefr']) acecmd = makeMatlabCmd("ctfparams = measureAstigmatism(",");",plist) #print acecmd pymat.eval(matlab,acecmd) matfile = os.path.join(params['matdir'], imgname+".mrc.mat") if params['stig']==0: savematcmd = "save('"+matfile+"','ctfparams','scopeparams', 'dforig');" pymat.eval(matlab,savematcmd) ctfvalue = pymat.get(matlab, 'ctfparams') ctfvalue=ctfvalue[0] printResults(params, nominal, ctfvalue) return ctfvalue