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
Пример #2
0
 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)
        untilt = numpy.array((
                (585,444),(603,473),(573,525),(676,1032),(613,963),
                (897,905),(972,936),(1044,876),(370,1319),(505,1121),
                (533,1103),(109,353),(149,321),(199,283),(265,314),
                (76,335),(298,390),(391,437),(52,647),(85,639),
                (15,653),(295,477),(310,447),(139,1052),(176,1091),
                (231,1110),(210,670),(265,680),(316,679),
        ))
        tilt = numpy.array((
                (483,180),(492,208),(469,261),(524,761),(480,694),
                (750,647),(697,619),(801,583),(286,1064),(391,856),
                (415,840),(134,122),(166,87),(205,43),(253,72),
                (106,103),(272,146),(337,185),(78,414),(102,405),
                (52,425),(267,234),(277,202),(122,817),(150,850),
                (193,864),(196,428),(236,439),(273,430),
        ))

        #print "untilt=",untilt
        #print "tilt=  ",tilt
        u = mem.used()
        for i in range(1):
                #sys.stderr.write(".")
                e = radermacher.tiltang(untilt,tilt,1.0)
                print e
                f = radermacher.willsq(untilt,tilt,e['wtheta'],0.0,0.0)
                print f
        print "mem=",mem.used()-u,"\n"
        print "done"
        #sys.exit(1)

        (205, 43),
        (253, 72),
        (106, 103),
        (272, 146),
        (337, 185),
        (78, 414),
        (102, 405),
        (52, 425),
        (267, 234),
        (277, 202),
        (122, 817),
        (150, 850),
        (193, 864),
        (196, 428),
        (236, 439),
        (273, 430),
    ))

    #print "untilt=",untilt
    #print "tilt=  ",tilt
    u = mem.used()
    for i in range(1):
        #sys.stderr.write(".")
        e = radermacher.tiltang(untilt, tilt, 1.0)
        print e
        f = radermacher.willsq(untilt, tilt, e['wtheta'], 0.0, 0.0)
        print f
    print "mem=", mem.used() - u, "\n"
    print "done"
    #sys.exit(1)