def runTest(self): tth, eta = transform.compute_tth_eta_from_xyz(self.XLYLZL, self.omega * self.omegasign, t_x=self.t_x, t_y=self.t_y, t_z=self.t_z, wedge=self.wedge, chi=self.chi) gve1 = transform.compute_g_vectors(tth, eta, self.omega * self.omegasign, self.wvln, wedge=self.wedge, chi=self.chi) t = np.array((self.t_x, self.t_y, self.t_z)) gve2 = np.empty((len(tth), 3), np.float) cImageD11.compute_gv(self.XLYLZLT, self.omega, self.omegasign, self.wvln, self.wedge, self.chi, t, gve2) # print t, self.wedge,self.chi # for i in range( len(tth)): # print i, gve1[:,i],gve1[:,i]-gve2[i],gve1[:,i]-gve3[:,i] # print "Test C" self.assertTrue(np.allclose(gve1, gve2.T)) # print "Test Fortran" if TEST_FORTRAN: gve3 = np.empty((3, len(tth)), np.float, order='F') fImageD11.compute_gv(self.XLYLZL, self.omega, self.omegasign, self.wvln, self.wedge, self.chi, t, gve3)
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
def gof( self, p, *args ): self.NC += 1 try: hkls, inds, peaks_xyzT, gobs, omega = args except: print(args, len(args)) raise p.shape = 4,3 ub = p[:3] t = p[3] gcalc = np.dot( ub, hkls ) cImageD11.compute_gv( peaks_xyzT, omega, self.transformpars.get('omegasign'), self.transformpars.get('wavelength'), self.transformpars.get('wedge'), self.transformpars.get('chi'), t, gobs) #print gobs #print gcalc #print (gobs-gcalc).ravel() #1/0 e = (gcalc - gobs.T).ravel() p.shape = 12, # print p-0.1,(e*e).sum() return e#(e*e).sum()
def xyz2gv(self, xyz, omega, tx=0, ty=0, tz=0, out=None): assert len(omega) == len(xyz) if out is None: out = np.empty((len(xyz), 3), float) cImageD11.compute_gv(xyz, omega, self.pars['omegasign'], self.pars['wavelength'], self.pars['wedge'], self.pars['chi'], np.array((tx, ty, tz)), out) return out
def assign(self, ubi, translation, tol): gv = np.zeros(self.peaks_xyzT.shape, np.float) cImageD11.compute_gv(self.peaks_xyzT, self.cf.omega, self.transformpars.get('omegasign'), self.transformpars.get('wavelength'), self.transformpars.get('wedge'), self.transformpars.get('chi'), translation, gv) hkl = np.dot(ubi, gv.T) hkli = np.floor(hkl + 0.5) e = (hkl - hkli) e = (e * e).sum(axis=0) inds = np.compress(e < tol * tol, np.arange(len(hkl[0]))) return inds, hkli[:, inds]
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()