def runTestShift(img1name, img2name, imgpath, tiltdiff, coord): img1path = os.path.join(imgpath, img1name) img2path = os.path.join(imgpath, img2name) print img1path print img2path img1 = apImage.binImg(apImage.mrcToArray(img1path),4) img2 = apImage.binImg(apImage.mrcToArray(img2path),4) apImage.arrayToMrc(img1,"img1a-raw.mrc") apImage.arrayToMrc(img2,"img2a-raw.mrc") origin, newpart, snr = apTiltShift.getTiltedCoordinates(img1, img2, tiltdiff, coord) apImage.arrayToJpegPlusPeak(img1, "img1a-guess.jpg", (origin[1], origin[0])) apImage.arrayToJpegPlusPeak(img2, "img2a-guess.jpg", (newpart[1], newpart[0]))
def processTiltPair(self, imgfile1, imgfile2, picks1, picks2, tiltangle, outfile, pixdiam=20.0, tiltaxis=-7.0, msg=True): """ Inputs: imgfile1 imgfile2 picks1, 2xN numpy array picks2, 2xN numpy array tiltangle outfile Modifies: outfile Output: None, failed True, success """ ### pre-load particle picks if len(picks1) < 10 or len(picks2) < 10: if msg is True: apDisplay.printWarning("Not enough particles ot run program on image pair") return None ### setup tilt data self.data['theta'] = tiltangle self.data['shiftx'] = 0.0 self.data['shifty'] = 0.0 self.data['gamma'] = tiltaxis self.data['phi'] = tiltaxis self.data['scale'] = 1.0 self.data['pixdiam'] = pixdiam ### open image file 1 img1 = self.openImageFile(imgfile1) if img1 is None: apDisplay.printWarning("Could not read image: "+imgfile1) return None ### open tilt file 2 img2 = self.openImageFile(imgfile2) if img1 is None: apDisplay.printWarning("Could not read image: "+imgfile1) return None ### guess the shift t0 = time.time() if msg is True: apDisplay.printMsg("Refining tilt axis angles") origin, newpart, snr, bestang = apTiltShift.getTiltedCoordinates(img1, img2, tiltangle, picks1, True, tiltaxis, msg=msg) self.data['gamma'] = float(bestang) self.data['phi'] = float(bestang) if snr < 2.0: if msg is True: apDisplay.printWarning("Low confidence in initial shift") return None self.currentpicks1 = [origin] self.currentpicks2 = [newpart] ### search for the correct particles self.importPicks(picks1, picks2, tight=False, msg=msg) if len(self.currentpicks1) < 4: apDisplay.printWarning("Failed to find any particle matches") return None self.deleteFirstPick() self.printData(msg) for i in range(4): self.clearBadPicks(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning("Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.clearBadPicks(msg) self.clearBadPicks(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning("Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.clearBadPicks(msg) self.importPicks(picks1, picks2, tight=False, msg=msg) self.clearBadPicks(msg) self.printData(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning("Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.getOverlap(img1,img2,msg) if msg is True: apDisplay.printMsg("Completed alignment of "+str(len(self.currentpicks1)) +" particle pairs in "+apDisplay.timeString(time.time()-t0)) self.saveData(imgfile1, imgfile2, outfile) self.printData(msg) return True
def processTiltPair(self, imgfile1, imgfile2, picks1, picks2, tiltangle, outfile, pixdiam=20.0, tiltaxis=-7.0, msg=True): """ Inputs: imgfile1 imgfile2 picks1, 2xN numpy array picks2, 2xN numpy array tiltangle outfile Modifies: outfile Output: None, failed True, success """ ### pre-load particle picks if len(picks1) < 10 or len(picks2) < 10: if msg is True: apDisplay.printWarning( "Not enough particles ot run program on image pair") return None ### setup tilt data self.data['theta'] = tiltangle self.data['shiftx'] = 0.0 self.data['shifty'] = 0.0 self.data['gamma'] = tiltaxis self.data['phi'] = tiltaxis self.data['scale'] = 1.0 self.data['pixdiam'] = pixdiam ### open image file 1 img1 = self.openImageFile(imgfile1) if img1 is None: apDisplay.printWarning("Could not read image: " + imgfile1) return None ### open tilt file 2 img2 = self.openImageFile(imgfile2) if img1 is None: apDisplay.printWarning("Could not read image: " + imgfile1) return None ### guess the shift t0 = time.time() if msg is True: apDisplay.printMsg("Refining tilt axis angles") origin, newpart, snr, bestang = apTiltShift.getTiltedCoordinates( img1, img2, tiltangle, picks1, True, tiltaxis, msg=msg) self.data['gamma'] = float(bestang) self.data['phi'] = float(bestang) if snr < 2.0: if msg is True: apDisplay.printWarning("Low confidence in initial shift") return None self.currentpicks1 = [origin] self.currentpicks2 = [newpart] ### search for the correct particles self.importPicks(picks1, picks2, tight=False, msg=msg) if len(self.currentpicks1) < 4: apDisplay.printWarning("Failed to find any particle matches") return None self.deleteFirstPick() self.printData(msg) for i in range(4): self.clearBadPicks(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning( "Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.clearBadPicks(msg) self.clearBadPicks(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning( "Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.clearBadPicks(msg) self.importPicks(picks1, picks2, tight=False, msg=msg) self.clearBadPicks(msg) self.printData(msg) if len(self.currentpicks1) < 5 or len(self.currentpicks2) < 5: if msg is True: apDisplay.printWarning( "Not enough particles to optimize angles") return None self.optimizeAngles(msg) self.printData(msg) self.getOverlap(img1, img2, msg) if msg is True: apDisplay.printMsg("Completed alignment of " + str(len(self.currentpicks1)) + " particle pairs in " + apDisplay.timeString(time.time() - t0)) self.saveData(imgfile1, imgfile2, outfile) self.printData(msg) return True