コード例 #1
0
 def makemap(self):
     """
     Generate a map fit versus position - no args?
     """
     for m in self.ubisread:
         g = grain(m)
         self.scandata=self.allscandata.copy()
         self.compute_gv(g)
         h=np.dot(g.ubi,np.transpose(self.gv))
         hint=np.floor(h+0.5).astype(np.int) # rounds down
         diff=h-hint
         drlv=np.sqrt(np.sum(diff*diff,0))
         indices = np.compress(drlv < 0.05,
                                    list(range(self.scandata.shape[0])))
         print(indices.shape,"hello")
         self.scandata = self.allscandata[indices]
         npts = 10
         for i in range(npts):
             for j in range(npts):
                 x=(i-npts*0.5)*1000/npts
                 y=(j-npts*0.5)*1000/npts
                 g.translation[0]=x
                 g.translation[1]=y
                 self.compute_gv(g)
                 for tol in [ 0.1]:
                     mat = g.ubi.copy()
                     npks = closest.score_and_refine(mat, self.gv, tol)
                     # 2nd time with refined
                     npks = closest.score_and_refine(mat, self.gv, tol)
                     h=np.dot(mat,np.transpose(self.gv))
                     hint=np.floor(h+0.5).astype(np.int)
                     # rounds down
                     diff=h-hint
                     drlv=np.sqrt(np.sum(diff*diff,0))
                     tthscore = np.sum(np.sum(hint*diff) *
                                       np.sum(hint*diff) /
                                       np.sum(h*h))
                     print(x,y, tol, "%5d"%(npks),sum(drlv)/drlv.shape[0],\
                     tthscore/drlv.shape[0],indexing.ubitocellpars(mat), end=' ')
                 print()
             sys.stdout.flush()
         print()
         print()
         print()
コード例 #2
0
ファイル: refinegrains.py プロジェクト: Python3pkg/ImageD11
    def refine(self, ubi, quiet=True):
        """
        Fit the matrix without changing the peak assignments

        """
        mat = ubi.copy()
        # print "In refine",self.tolerance, self.gv.shape
        # First time fits the mat
        self.npks, self.avg_drlv2 = closest.score_and_refine(
            mat, self.gv, self.tolerance)
        # apply symmetry to mat:
        if self.latticesymmetry is not triclinic:
            cp = xfab.tools.ubi_to_cell(mat)
            U = xfab.tools.ubi_to_u(mat)
            mat = xfab.tools.u_to_ubi(U, self.latticesymmetry(cp))

        # Second time updates the score with the new mat
        self.npks, self.avg_drlv2 = closest.score_and_refine(
            mat, self.gv, self.tolerance)
        # apply symmetry to mat:
        if self.latticesymmetry is not triclinic:
            cp = xfab.tools.ubi_to_cell(mat)
            U = xfab.tools.ubi_to_u(mat)
            mat = xfab.tools.u_to_ubi(U, self.latticesymmetry(cp))

        if not quiet:
            import math
            try:
                print("%-8d %.6f" % (self.npks, math.sqrt(self.avg_drlv2)))
            except:
                print(self.npks, self.avg_drlv2, mat, self.gv.shape,
                      self.tolerance)
#                raise

#print self.tolerance
#        self.npks, self.avg_drlv2 = closest.score_and_refine(mat, self.gv,
#                                                             self.tolerance)
#tm = indexing.refine(ubi,self.gv,self.tolerance,quiet=quiet)
#print ubi, tm,ubi-tm,mat-tm

        return mat
コード例 #3
0
    def compute_gv(self, thisgrain, update_columns=False):
        """
        Makes self.gv refer be g-vectors computed for this grain in this scan
        """
        peaks_xyz = thisgrain.peaks_xyz
        om = thisgrain.om
        try:
            sign = self.parameterobj.parameters['omegasign']
        except:
            sign = 1.0
        # translation should match grain translation here...
        self.tth, self.eta = transform.compute_tth_eta_from_xyz(
            peaks_xyz, omega=om * sign, **self.parameterobj.parameters)

        gv = transform.compute_g_vectors(
            self.tth, self.eta, om * sign,
            float(self.parameterobj.parameters['wavelength']),
            self.parameterobj.parameters['wedge'],
            self.parameterobj.parameters['chi'])
        # update tth_per_grain and eta_per_grain
        if update_columns:
            name = thisgrain.name.split(":")[1]
            numpy.put(self.scandata[name].tth_per_grain, thisgrain.ind,
                      self.tth)
            numpy.put(self.scandata[name].eta_per_grain, thisgrain.ind,
                      self.eta)

        if not self.OMEGA_FLOAT:
            self.gv = gv.T
        if self.OMEGA_FLOAT:
            mat = thisgrain.ubi.copy()
            junk = closest.score_and_refine(mat, gv.T, self.tolerance)
            hklf = numpy.dot(mat, gv)
            hkli = numpy.floor(hklf + 0.5)

            gcalc = numpy.dot(numpy.linalg.inv(mat), hkli)
            tth, [eta1,
                  eta2], [omega1, omega2] = transform.uncompute_g_vectors(
                      gcalc, float(self.parameterobj.parameters['wavelength']),
                      self.parameterobj.parameters['wedge'],
                      self.parameterobj.parameters['chi'])

            e1e = numpy.abs(eta1 - self.eta)
            e2e = numpy.abs(eta2 - self.eta)
            try:
                eta_err = numpy.array([e1e, e2e])
            except:
                print e1e.shape, e2e.shape, e1e

                raise

            best_fitting = numpy.argmin(eta_err, axis=0)

            # These are always 1 or zero
            # pick the right omega (confuddled by take here)
            omega_calc = best_fitting * omega2 + (1 - best_fitting) * omega1
            # Take a weighted average within the omega error of the observed
            omerr = (om * sign - omega_calc)
            # print omerr[0:5]
            omega_calc = om * sign - numpy.clip(omerr, -self.slop, self.slop)
            # print omega_calc[0], om[0]

            # Now recompute with improved omegas... (tth, eta do not change much)
            #self.tth, self.eta = transform.compute_tth_eta(
            #    numpy.array([x, y]),
            #    omega = omega_calc,
            #    **self.parameterobj.parameters)
            self.tth, self.eta = transform.compute_tth_eta_from_xyz(
                peaks_xyz, omega=om * sign, **self.parameterobj.parameters)

            gv = transform.compute_g_vectors(
                self.tth, self.eta, omega_calc,
                float(self.parameterobj.parameters['wavelength']),
                self.parameterobj.parameters['wedge'],
                self.parameterobj.parameters['chi'])
            self.gv = gv.T
        return