示例#1
0
 def assignlabels(self):
     self.resetlabels()
     nr = self.nrows
     pks_xyz = np.empty((nr, 3), float)
     pks_xyz[:, 0] = self.colf.xl
     pks_xyz[:, 1] = self.colf.yl
     pks_xyz[:, 2] = self.colf.zl
     #print(self.gvecs.shape, pks_xyz.shape)
     for i, g in enumerate(self.grains):
         if g.translation is None:
             t = np.array((0, 0, 0), float)
         else:
             t = np.array(
                 (g.translation[0], g.translation[1], g.translation[2]),
                 float)
         cImageD11.compute_gv(pks_xyz, self.colf.omega,
                              self.colf.parameters.get('omegasign'),
                              self.colf.parameters.get('wavelength'),
                              self.colf.parameters.get('wedge'),
                              self.colf.parameters.get('chi'), t,
                              self.gvecs)
         cImageD11.score_and_assign(g.ubi, self.gvecs, self.tol, self.drlv2,
                                    self.labels, i)
     self.colf.labels[:] = self.labels
     self.colf.drlv2[:] = self.drlv2
示例#2
0
    def assignlabels(self, quiet=False):
        """
        Fill out the appropriate labels for the spots
        """
        if not quiet:
            print("Assigning labels with XLYLZL")
        import time
        start = time.time()
        for s in self.scannames:
            self.scandata[s].labels = self.scandata[s].labels * 0 - 2  # == -1
            drlv2 = numpy.zeros(len(self.scandata[s].drlv2), numpy.float) + 1
            nr = self.scandata[s].nrows
            sc = self.scandata[s].sc
            fc = self.scandata[s].fc
            om = self.scandata[s].omega
            # Looks like this in one dataset only
            ng = len(self.grainnames)
            int_tmp = numpy.zeros(nr, numpy.int32) - 1
            tmp = transform.compute_xyz_lab(
                [self.scandata[s].sc, self.scandata[s].fc],
                **self.parameterobj.parameters)
            peaks_xyz = tmp.T.copy()
            if not quiet:
                print("Start first grain loop", time.time() - start)
            start = time.time()
            gv = numpy.zeros((nr, 3), numpy.float)
            wedge = self.parameterobj.parameters['wedge']
            omegasign = self.parameterobj.parameters['omegasign']
            chi = self.parameterobj.parameters['chi']
            wvln = self.parameterobj.parameters['wavelength']
            first_loop = time.time()
            drlv2 = (self.scandata[s].drlv2 * 0 + 1).astype(float)  # == 1
            int_tmp = numpy.zeros(nr, numpy.int32) - 1
            for ig, g in enumerate(self.grainnames):
                gr = self.grains[(g, s)]
                self.set_translation(g, s)
                cImageD11.compute_gv(peaks_xyz, self.scandata[s].omega,
                                     omegasign, wvln, wedge, chi,
                                     gr.translation, gv)
                cImageD11.score_and_assign(gr.ubi, gv, self.tolerance, drlv2,
                                           int_tmp, int(g))
            if not quiet:
                print(time.time() - first_loop, "First loop")

            self.gv = gv.copy()
            # Second loop after checking all grains
            if not quiet:
                print("End first grain loop", time.time() - start)
            start = time.time()

            if not quiet:
                print(self.scandata[s].labels.shape, \
                      numpy.minimum.reduce(self.scandata[s].labels),\
                        numpy.maximum.reduce(self.scandata[s].labels))

            self.scandata[s].addcolumn(int_tmp, "labels")
            self.scandata[s].addcolumn(drlv2, "drlv2")
            if not quiet:
                print(self.scandata[s].labels.shape, \
                      numpy.minimum.reduce(self.scandata[s].labels),\
                      numpy.maximum.reduce(self.scandata[s].labels))

            tth = numpy.zeros(nr, numpy.float32) - 1
            eta = numpy.zeros(nr, numpy.float32)

            self.scandata[s].addcolumn(tth, "tth_per_grain")
            self.scandata[s].addcolumn(eta, "eta_per_grain")
            self.scandata[s].addcolumn(om * 0, "omegacalc_per_grain")
            self.scandata[s].addcolumn(self.gv[:, 0], "gx")
            self.scandata[s].addcolumn(self.gv[:, 1], "gy")
            self.scandata[s].addcolumn(self.gv[:, 2], "gz")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "hr")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "kr")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "lr")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "h")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "k")
            self.scandata[s].addcolumn(numpy.zeros(nr, numpy.float32), "l")

            if not quiet:
                print("Start second grain loop", time.time() - start)
            start = time.time()

            # We have the labels set in self.scandata!!!
            for g in self.grainnames:
                gr = self.grains[(g, s)]

                ind = numpy.compress(int_tmp == g, numpy.arange(nr))
                #print 'x',gr.x[:10]
                #print 'ind',ind[:10]
                gr.ind = ind  # use this to push back h,k,l later
                gr.peaks_xyz = numpy.take(peaks_xyz, ind, axis=0)
                gr.sc = numpy.take(sc, ind)
                gr.fc = numpy.take(fc, ind)
                gr.om = numpy.take(self.scandata[s].omega, ind)
                gr.omega_calc = gr.om.copy()
                gr.npks = len(gr.ind)
                self.set_translation(g, s)
                try:
                    sign = self.parameterobj.parameters['omegasign']
                except:
                    sign = 1.0

                tth, eta = transform.compute_tth_eta_from_xyz(
                    gr.peaks_xyz.T,
                    omega=gr.om * sign,
                    **self.parameterobj.parameters)

                self.scandata[s].tth_per_grain[ind] = tth
                self.scandata[s].eta_per_grain[ind] = eta
                #                self.scandata[s].omegacalc_per_grain[ind] = gr.omega_calc
                self.grains[(g, s)] = gr
                if not quiet:
                    print("Grain", g, "Scan", s, "npks=", len(ind))
                #print 'x',gr.x[:10]
            # Compute the total integrated intensity if we have enough
            # information available
            compute_lp_factor(self.scandata[s])
            for g in self.grainnames:
                gr = self.grains[(g, s)]
                gr.intensity_info = compute_total_intensity(
                    self.scandata[s],
                    gr.ind,
                    self.intensity_tth_range,
                    quiet=quiet)

            if not quiet:
                print("End second grain loop", time.time() - start)
                print()
            start = time.time()
示例#3
0
ubis = (np.random.random(9*20).reshape((20,3,3))-0.5)*10

gvf= np.array( testvecs.T,  order='F')

tim = time.time

for tol in [0.01, 0.1, 0.2, 0.5]:
    int_tmpf = np.zeros( NPK, np.int32 )
    drlv2f = np.zeros( NPK, np.float)

    start = tim()
    for i, gr in enumerate(ubis):
        fImageD11.assign( gr, gvf , tol, drlv2f, int_tmpf, i )
    end = tim() 
    fortrantime = end -start

    int_tmpc = np.zeros( NPK, np.int32 )
    drlv2c = np.zeros( NPK, np.float)

    start = tim()


    for i, gr in enumerate(ubis):
        cImageD11.score_and_assign( gr, testvecs , tol, drlv2c, int_tmpc, i )
    end = tim()
    ctime = end - start
    print "tol","fortrantime",fortrantime,"ctime",ctime

    assert  np.allclose( drlv2c, drlv2f )
    assert  (int_tmpc == int_tmpf).all()