def optimizeAngles(self, msg=True): t0 = time.time() ### run find theta na1 = numpy.array(self.currentpicks1, dtype=numpy.int32) na2 = numpy.array(self.currentpicks2, dtype=numpy.int32) fittheta = radermacher.tiltang(na1, na2) if not fittheta or not 'wtheta' in fittheta: return theta = fittheta['wtheta'] thetadev = fittheta['wthetadev'] if msg is True: thetastr = ("%3.3f +/- %2.2f" % (theta, thetadev)) tristr = apDisplay.orderOfMag(fittheta['numtri'])+" of "+apDisplay.orderOfMag(fittheta['tottri']) tristr = (" (%3.1f " % (100.0 * fittheta['numtri'] / float(fittheta['tottri'])))+"%) " apDisplay.printMsg("Tilt angle "+thetastr+tristr) self.data['theta'] = fittheta['wtheta'] ### run optimize angles lastiter = [80,80,80] count = 0 totaliter = 0 while max(lastiter) > 75 and count < 30: count += 1 lsfit = self.runLeastSquares() lastiter[2] = lastiter[1] lastiter[1] = lastiter[0] lastiter[0] = lsfit['iter'] totaliter += lsfit['iter'] if msg is True: apDisplay.printMsg("Least Squares: "+str(count)+" rounds, "+str(totaliter) +" iters, rmsd of "+str(round(lsfit['rmsd'],4))+" pixels in "+apDisplay.timeString(time.time()-t0)) return
def onRunTiltAng(self, evt): arealim = self.arealimit.GetValue() self.parent.data['arealim'] = arealim targets1 = self.parent.panel1.getTargets('Picked') a1 = self.parent.targetsToArray(targets1) targets2 = self.parent.panel2.getTargets('Picked') a2 = self.parent.targetsToArray(targets2) na1 = numpy.array(a1, dtype=numpy.int32) na2 = numpy.array(a2, dtype=numpy.int32) self.fittheta = radermacher.tiltang(na1, na2, arealim) #pprint.pprint(self.fittheta) if self.fittheta and 'wtheta' in self.fittheta: self.fittheta['point1'], self.fittheta['point2'] = \ apTiltTransform.getPointsFromArrays(a1, a2, self.parent.data['shiftx'], self.parent.data['shifty']) self.theta = self.fittheta['wtheta'] self.thetadev = self.fittheta['wthetadev'] thetastr = ("%3.3f +/- %2.2f" % (self.theta, self.thetadev)) self.tiltvalue.SetLabel(label=thetastr) tristr = apDisplay.orderOfMag( self.fittheta['numtri']) + " of " + apDisplay.orderOfMag( self.fittheta['tottri']) self.trilabel1.SetLabel(label=tristr) percent = str("%") tristr = (" (%3.1f " % (100.0 * self.fittheta['numtri'] / float(self.fittheta['tottri']))) + "%) " self.trilabel2.SetLabel(label=tristr)
def optimizeAngles(self, msg=True): t0 = time.time() ### run find theta na1 = numpy.array(self.currentpicks1, dtype=numpy.int32) na2 = numpy.array(self.currentpicks2, dtype=numpy.int32) # minimum area for a triangle to be valid arealim = 100.0 fittheta = radermacher.tiltang(na1, na2, arealim) if not fittheta or not 'wtheta' in fittheta: return theta = fittheta['wtheta'] thetadev = fittheta['wthetadev'] if msg is True: thetastr = ("%3.3f +/- %2.2f" % (theta, thetadev)) tristr = apDisplay.orderOfMag( fittheta['numtri']) + " of " + apDisplay.orderOfMag( fittheta['tottri']) tristr = (" (%3.1f " % (100.0 * fittheta['numtri'] / float(fittheta['tottri']))) + "%) " apDisplay.printMsg("Tilt angle " + thetastr + tristr) self.data['theta'] = fittheta['wtheta'] ### run optimize angles lastiter = [80, 80, 80] count = 0 totaliter = 0 while max(lastiter) > 75 and count < 30: count += 1 lsfit = self.runLeastSquares() lastiter[2] = lastiter[1] lastiter[1] = lastiter[0] lastiter[0] = lsfit['iter'] totaliter += lsfit['iter'] if msg is True: apDisplay.printMsg("Least Squares: " + str(count) + " rounds, " + str(totaliter) + " iters, rmsd of " + str(round(lsfit['rmsd'], 4)) + " pixels in " + apDisplay.timeString(time.time() - t0)) return
def onRunTiltAng(self, evt): arealim = self.arealimit.GetValue() self.parent.data['arealim'] = arealim targets1 = self.parent.panel1.getTargets('Picked') a1 = self.parent.targetsToArray(targets1) targets2 = self.parent.panel2.getTargets('Picked') a2 = self.parent.targetsToArray(targets2) na1 = numpy.array(a1, dtype=numpy.int32) na2 = numpy.array(a2, dtype=numpy.int32) self.fittheta = radermacher.tiltang(na1, na2, arealim) #pprint.pprint(self.fittheta) if self.fittheta and 'wtheta' in self.fittheta: self.fittheta['point1'], self.fittheta['point2'] = \ apTiltTransform.getPointsFromArrays(a1, a2, self.parent.data['shiftx'], self.parent.data['shifty']) self.theta = self.fittheta['wtheta'] self.thetadev = self.fittheta['wthetadev'] thetastr = ("%3.3f +/- %2.2f" % (self.theta, self.thetadev)) self.tiltvalue.SetLabel(label=thetastr) tristr = apDisplay.orderOfMag(self.fittheta['numtri'])+" of "+apDisplay.orderOfMag(self.fittheta['tottri']) self.trilabel1.SetLabel(label=tristr) percent = str("%") tristr = (" (%3.1f " % (100.0 * self.fittheta['numtri'] / float(self.fittheta['tottri'])))+"%) " self.trilabel2.SetLabel(label=tristr)