コード例 #1
0
 def updatecolfile(self):
    if "xl" not in self.cf.titles:
       if "sc" in self.cf.titles:
          pks = self.cf.sc, self.cf.fc
       elif "xc" in self.cf.titles: 
          pks = self.cf.xc, self.cf.yc
       else:
          raise Exception("peaks file misses xc or sc")
       xl,yl,zl = transform.compute_xyz_lab( pks,
                                             **self.transformpars.parameters)
       self.cf.addcolumn(xl,"xl")
       self.cf.addcolumn(yl,"yl")
       self.cf.addcolumn(zl,"zl")
    peaks_xyz = np.array((self.cf.xl,self.cf.yl,self.cf.zl))
    om = self.cf.omega
    sign = self.transformpars.get("omegasign")
    tth, eta = transform.compute_tth_eta_from_xyz(
       peaks_xyz, om*sign,
       **self.transformpars.parameters)
    self.cf.addcolumn( tth, "tth", )
    self.cf.addcolumn( eta, "eta", )
    gx, gy, gz = transform.compute_g_vectors(
        tth, eta, om*sign,
        wvln  = self.transformpars.get("wavelength"),
        wedge = self.transformpars.get("wedge"),
        chi   = self.transformpars.get("chi") )
    self.cf.addcolumn(gx, "gx")
    self.cf.addcolumn(gy, "gy")
    self.cf.addcolumn(gz, "gz")           
    self.cf.addcolumn( np.sqrt( gx * gx + 
                                gy * gy + 
                                gz * gz ),
                       "modg")
コード例 #2
0
 def test_xyz_from_yaml(self):
     for p in parfiles:
         parfile = os.path.join(TEST, p)
         fltfile = os.path.join(TEST, "test.flt")
         ymlfile = os.path.join(
             os.path.split(general_geometry.__file__)[0], "data",
             "fable.yml")
         pars = parameters.read_par_file(parfile).parameters
         colf = columnfile.columnfile(fltfile)
         sc = colf.sc[:4]
         fc = colf.fc[:4]
         geometry = general_geometry.from_yml(
             pars,
             ymlfile,
             path=["Positioners", "Fable_detector"],
             noisy=False)
         # test old
         xyz1 = transform.compute_xyz_lab((sc, fc), **pars)
         # test new
         v = np.zeros((3, len(sc)))
         v[1] = fc
         v[2] = sc
         xyz2 = geometry((np.zeros(len(fc)), fc, sc))
         if not np.allclose(xyz1, xyz2):
             print("Geometry", geometry)
             print("Parfile:", p)
             for i in range(len(fc)):
                 print(xyz1[:, i])
                 print(xyz2[:, i])
                 print()
         assert np.allclose(xyz1, xyz2)
コード例 #3
0
ファイル: boxfit.py プロジェクト: Python3pkg/ImageD11
def update_det_pars( peakdata, pars ):
    """
    Update the xl, yl, zl columns
    peakdata = columnfile
    pars = ImageD11 parameters object
    """
    print("Update xl, yl, zl for current parameters")
    for label in ["xl","yl","zl"]:
        if label not in peakdata.titles:
            peakdata.titles.append(label)
    peakdata.xl,peakdata.yl,peakdata.zl = transform.compute_xyz_lab(
        [peakdata.sc, peakdata.fc],
        **pars.get_parameters() )
    # Imagine sample translates along +x. Detector is at x=+distance
    # To get the difference vector right we add samtx to xl for omega=0
    # Same for samty, yl and samtz, zl
    # when omega rotates to + 90 degrees (right handed)
    #   samtx is along +yl
    #   samty is along -xl
    rad = float(pars.parameters['omegasign'])*numpy.pi/180.0
    peakdata.sinomega = numpy.sin(peakdata.omega * rad) # == 0 at omega = 0
    peakdata.cosomega = numpy.cos(peakdata.omega * rad) # == 1 at omega = 0
    peakdata.xl += peakdata.samtx * peakdata.cosomega - \
                   peakdata.samty * peakdata.sinomega
    peakdata.yl += peakdata.samtx * peakdata.sinomega + \
                   peakdata.samty * peakdata.cosomega
    peakdata.zl += peakdata.samtz
    print("lab x shape",peakdata.xl.shape)
    return peakdata
コード例 #4
0
 def compute_XLYLZL(self):
     self.peaks_xyz = transform.compute_xyz_lab(
         [self.colfile.sc, self.colfile.fc], **self.pars.parameters)
     # These are the peak positions in the laboratory frame
     #
     # Now get the beam and peaks in the crystal frame
     wedge = float(self.pars.get('wedge'))
     chi = float(self.pars.get('chi'))
     omega = self.colfile.omega
     beam = np.zeros((3, len(omega)))
     beam[0, :] = 1
     self.XB = k_to_g(beam, omega, wedge, chi)
     self.XS = k_to_g(self.peaks_xyz, omega, wedge, chi)
コード例 #5
0
def getCxyz(colf, pars):
    """
    Find spot positions in crystal frame
    colf = columnfile (or other object) holding .sc, .fc, .omega
    pars = parameters for ImageD11 transform module
    """
    wedge = pars.get("wedge")
    chi = pars.get("chi")
    peaks_xyz = transform.compute_xyz_lab([colf.sc, colf.fc],
                                          **pars.parameters)
    fun = transform.compute_g_from_k
    peaks_Cxyz = fun(peaks_xyz, colf.omega, wedge=wedge, chi=chi)
    b = np.zeros(peaks_Cxyz.shape)
    b[0, :] = 1.0 / pars.get("wavelength")
    beam_Cxyz = fun(b, colf.omega, wedge=wedge, chi=chi)
    return peaks_Cxyz, beam_Cxyz
コード例 #6
0
def gridgrains(
    ul,
    flt,
    pars,
    minx=-750,
    maxx=750,
    stepx=25,
    miny=-750,
    maxy=750,
    stepy=25,
    tol=0.05,
):
    trn = transformer.transformer()
    trn.loadfiltered(flt)
    trn.parameterobj = parameters.parameters(**pars)

    peaks = [trn.getcolumn(trn.xname), trn.getcolumn(trn.yname)]
    peaks_xyz = transform.compute_xyz_lab(peaks,
                                          **trn.parameterobj.get_parameters())

    omega = trn.getcolumn(trn.omeganame)
    trn.updateparameters()
    tx = minx - stepx
    n = 0
    sys.stderr.write("Using tol = %f\n" % (tol))
    while tx <= maxx:
        tx = tx + stepx
        ty = miny - stepy
        while ty <= maxy:
            ty = ty + stepy
            trn.parameterobj.set_parameters({'t_x': tx, 't_y': ty})
            pars = trn.parameterobj.get_parameters()
            tth, eta = transform.compute_tth_eta_from_xyz(
                peaks_xyz, omega, **pars)
            if 'omegasign' in pars:
                om_sgn = float(pars["omegasign"])
            else:
                om_sgn = 1.0

            gv = transform.compute_g_vectors(tth, eta, omega * om_sgn, **pars)
            print(tx, ty, end=' ')
            for ubi in ul:
                ns = score(ubi, gv.T, tol)
                print(ns, end=' ')
                n += ns
            print()
    return n
コード例 #7
0
ファイル: fittrans2.py プロジェクト: jadball/ImageD11
 def compute_XLYLZL(self):
     self.peaks_xyz = transform.compute_xyz_lab(
         [self.colfile.sc, self.colfile.fc],
         **self.colfile.parameters.parameters)
     # These are the peak positions in the laboratory frame
     #
     # Now get the beam and peaks in the crystal frame
     wedge = float(self.colfile.parameters.get('wedge'))
     chi = float(self.colfile.parameters.get('chi'))
     self.chiwedge = gv_general.chiwedge(chi, wedge)
     omega = np.radians(self.colfile.omega)
     cosomega = np.cos(omega)
     sinomega = np.sin(omega)
     beam = np.zeros((3, len(omega)), float)
     beam[0, :] = 1.
     self.XB = k_to_g(beam, cosomega, sinomega, self.chiwedge)
     self.XS = k_to_g(self.peaks_xyz, cosomega, sinomega, self.chiwedge)
コード例 #8
0
ファイル: transformer.py プロジェクト: Python3pkg/ImageD11
 def compute_tth_eta(self):
     """ Compute the twotheta and eta for peaks previous read in """
     if None in [self.xname, self.yname]:
         raise Exception("No peaks loaded")
     peaks = [self.getcolumn(self.xname), self.getcolumn(self.yname)]
     peaks_xyz = transform.compute_xyz_lab(
         peaks, **self.parameterobj.get_parameters())
     # Store these in the columnfile
     self.addcolumn(peaks_xyz[0], "xl")
     self.addcolumn(peaks_xyz[1], "yl")
     self.addcolumn(peaks_xyz[2], "zl")
     # Get the Omega name?
     omega = self.getcolumn(self.omeganame)
     tth, eta = transform.compute_tth_eta_from_xyz(
         peaks_xyz, omega, **self.parameterobj.get_parameters())
     self.addcolumn(tth, "tth")
     self.addcolumn(eta, "eta")
     return tth, eta
コード例 #9
0
ファイル: refinegrains.py プロジェクト: junyuewang/ImageD11
    def gof(self,args):
        """
        <drlv> for all of the grains in all of the scans
        """
        self.applyargs(args)
        diffs = 0.
        contribs = 0.

        # defaulting to fitting all grains
        for key in self.grains_to_refine:

            g = self.grains[key]

###            rotdex.fitagrain( gr, self.parameterobj )

            grainname = key[0]
            scanname = key[1]

            # Compute gv using current parameters
            # Keep labels fixed
            if self.recompute_xlylzl:
                g.peaks_xyz = transform.compute_xyz_lab([ g.sc,
                                                          g.fc ],
                                                        **self.parameterobj.parameters).T

            self.compute_gv( g )
            #print self.gv.shape
            #print self.gv[0:10,i:]

            # For stability, always start refining the read in one
            g.set_ubi( self.refine( self.ubisread[grainname] ) )
            #print self.npks,self.avg_drlv2 # number of peaks it got

            #print self.gv.shape



            diffs +=  self.npks*self.avg_drlv2
            contribs+= self.npks
        if contribs > 0:
            return 1e6*diffs/contribs
        else:
            print("No contribs???", self.grains_to_refine)
            return 1e6
コード例 #10
0
 def updateGeometry(self, pars=None):
     """
     changing or not the parameters it (re)-computes:
        xl,yl,zl = ImageD11.transform.compute_xyz_lab
        tth, eta = ImageD11.transform.compute_tth_eta
        gx,gy,gz = ImageD11.transform.compute_g_vectors
     """
     if pars is not None:
         self.setparameters(pars)
     pars = self.parameters
     if "sc" in self.titles and "fc" in self.titles:
         pks = self.sc, self.fc
     elif "xc" in self.titles and "yc" in self.titles:
         pks = self.xc, self.yc
     else:
         raise Exception("columnfile file misses xc/yc or sc/fc")
     xl, yl, zl = transform.compute_xyz_lab(pks, **pars.parameters)
     peaks_xyz = np.array((xl, yl, zl))
     assert "omega" in self.titles, "No omega column"
     om = self.omega * float(pars.get("omegasign"))
     tth, eta = transform.compute_tth_eta_from_xyz(peaks_xyz, om,
                                                   **pars.parameters)
     gx, gy, gz = transform.compute_g_vectors(tth,
                                              eta,
                                              om,
                                              wvln=pars.get("wavelength"),
                                              wedge=pars.get("wedge"),
                                              chi=pars.get("chi"))
     modg = np.sqrt(gx * gx + gy * gy + gz * gz)
     self.addcolumn(xl, "xl")
     self.addcolumn(yl, "yl")
     self.addcolumn(zl, "zl")
     self.addcolumn(
         tth,
         "tth",
     )
     self.addcolumn(
         eta,
         "eta",
     )
     self.addcolumn(gx, "gx")
     self.addcolumn(gy, "gy")
     self.addcolumn(gz, "gz")
     self.addcolumn(modg, "ds")  # dstar
コード例 #11
0
    def test1(self):
        pks = self.sc, self.fc
        p = self.pars
        testtilts = [-0.5, 0., 0.24]
        tilts = [(x, y, z) for x in testtilts for y in testtilts
                 for z in testtilts]
        pars = np.array((p.get("z_center"), p.get("y_center"), p.get("z_size"),
                         p.get("y_size")))
        dist = np.array((p.get("distance"), 0., 0.))
        ok = 0
        for o11, o12, o21, o22 in [[1, 0, 0, 1], [-1, 0, 0, 1], [-1, 0, 0, -1],
                                   [1, 0, 0, -1], [0, 1, 1, 0], [0, -1, 1, 0],
                                   [0, -1, -1, 0], [0, 1, -1, 0]]:
            for tx, ty, tz in tilts:
                p.parameters['tilt_x'] = tx
                p.parameters['tilt_y'] = ty
                p.parameters['tilt_z'] = tz
                p.parameters['o11'] = o11
                p.parameters['o12'] = o12
                p.parameters['o21'] = o21
                p.parameters['o22'] = o22

                xlylzl = transform.compute_xyz_lab(pks, **p.parameters)

                dmat = transform.detector_rotation_matrix(
                    p.get('tilt_x'), p.get('tilt_y'), p.get('tilt_z'))
                fmat = np.array([[1, 0, 0], [0, p.get('o22'),
                                             p.get('o21')],
                                 [0, p.get('o12'),
                                  p.get('o11')]])
                r = np.dot(dmat, fmat)

                outxyz = np.zeros((len(self.sc), 3), np.float)
                cImageD11.compute_xlylzl(self.sc, self.fc, pars, r.ravel(),
                                         dist, outxyz)
                error = np.abs(outxyz - xlylzl.T)
                self.assertTrue(error.max() < 1e-6)
                ok += 1
        print("tested xlylzl %d times" % (ok))
コード例 #12
0
 def compute_XLYLZL(self):
     self.peaks_xyz = transform.compute_xyz_lab( [self.colfile.sc,
                                                 self.colfile.fc],
                                               **self.pars.parameters)
     self.colfile.addcolumn( self.peaks_xyz[0], 'XL')
     self.colfile.addcolumn( self.peaks_xyz[1], 'YL')
     self.colfile.addcolumn( self.peaks_xyz[2], 'ZL')
     # These are the peak positions in the laboratory frame
     #
     # Now get the beam and peaks in the crystal frame
     wedge = float(self.pars.get('wedge'))
     chi   = float(self.pars.get('chi'))
     omega = self.colfile.omega
     beam = np.zeros( (3,len(omega)))
     beam[0,:] = 1
     self.XB = k_to_g( beam, omega, wedge, chi)
     #print "XB",XB
     self.colfile.addcolumn( self.XB[0], 'XB')
     self.colfile.addcolumn( self.XB[1], 'YB')
     self.colfile.addcolumn( self.XB[2], 'ZB')
     self.XS = k_to_g( self.peaks_xyz, omega, wedge, chi )
     self.colfile.addcolumn( self.XS[0], 'XS')
     self.colfile.addcolumn( self.XS[1], 'YS')
     self.colfile.addcolumn( self.XS[2], 'ZS')
コード例 #13
0
 def test_xyz(self):
     for p in parfiles:
         parfile = os.path.join(TEST, p)
         fltfile = os.path.join(TEST, "test.flt")
         pars = parameters.read_par_file(parfile).parameters
         colf = columnfile.columnfile(fltfile)
         sc = colf.sc
         fc = colf.fc
         geometry = general_geometry.fable_detector(pars, noisy=False)
         # test old
         xyz1 = transform.compute_xyz_lab((sc, fc), **pars)
         # test new
         v = np.zeros((3, len(sc)))
         v[1] = fc
         v[2] = sc
         xyz2 = geometry((np.zeros(len(fc)), fc, sc))
         if not np.allclose(xyz1, xyz2):
             print("Geometry", geometry)
             print("Parfile:", p)
             for i in range(len(fc)):
                 print(xyz1[:, i])
                 print(xyz2[:, i])
                 print()
         assert np.allclose(xyz1, xyz2)
コード例 #14
0
    mm = float(sys.argv[4])
except:
    pixv = 2048.
    pixh = 2048.
    mm = 1
v = (pixv - 1) / 2.
h = (pixh - 1) / 2.

print("Getting parameters from", parfile)

p = parameters.parameters()
p.loadparameters(parfile)

pars = p.get_parameters()

xyz = np.transpose(transform.compute_xyz_lab([[v], [h]], **pars))

ks = list(pars.keys())
ks.sort()
for k in ks:
    print(k, pars[k])
print()
print("central pixel position")
print("detector vertical", v, "horizontal", h)
print("real space x, y, z = ", xyz)

print("\n")
print("detector %i %i %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f stem format %i %i %i %i" % \
    (pixv,
     pixh,
     mm*pars['y_size'],
コード例 #15
0
ファイル: cyfit.py プロジェクト: jonwright/wripaca
 def setscfc(self, sc, fc):
     self.sc = sc
     self.fc = fc
     self.XL = transform.compute_xyz_lab( [sc, fc], 
             **self.pars.parameters ).T.copy()
コード例 #16
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()
コード例 #17
0
ファイル: cdiffraction.py プロジェクト: yns11/tst
    parfile = sys.argv[3]

    pars = parameters()
    pars.loadparameters(parfile)

    wedge = np.radians(float(pars.get("wedge")))
    chi = np.radians(float(pars.get("chi")))
    wvln = float(pars.get("wavelength"))

    c = columnfile(colfile)
    c.nrows = 2
    c.bigarray = c.bigarray[:, :2]
    print c.bigarray.shape
    c.set_attributes()

    XL = flatfloat(compute_xyz_lab([c.sc, c.fc], **pars.parameters).T)
    om = flatfloat(np.radians(c.omega))

    #    XL[0,:]=[41,42,43]

    grains = read_grain_file(grainfile)
    UBIs = flatfloat([g.ubi for g in grains], shape=(len(grains), 3, 3))
    UBs = flatfloat([np.linalg.inv(g.ubi) for g in grains],
                    shape=(len(grains), 3, 3))
    Ts = flatfloat([g.translation for g in grains], shape=(len(grains), 3))

    labels = np.zeros(c.nrows, np.int32)
    hkls = np.zeros((c.nrows, 3), NPREAL)

    print XL.shape
    print om.shape
コード例 #18
0
    (p.get("z_center"), p.get("y_center"), p.get("z_size"), p.get("y_size")))
dist = np.array((p.get("distance"), 0., 0.))

for o11, o12, o21, o22 in [[1, 0, 0, 1], [-1, 0, 0, 1], [-1, 0, 0, -1],
                           [1, 0, 0, -1], [0, 1, 1, 0], [0, -1, 1, 0],
                           [0, -1, -1, 0], [0, 1, -1, 0]]:
    for tx, ty, tz in tilts:
        p.parameters['tilt_x'] = tx
        p.parameters['tilt_y'] = ty
        p.parameters['tilt_z'] = tz
        p.parameters['o11'] = o11
        p.parameters['o12'] = o12
        p.parameters['o21'] = o21
        p.parameters['o22'] = o22

        xlylzl = compute_xyz_lab(pks, **p.parameters)

        dmat = detector_rotation_matrix(p.get('tilt_x'), p.get('tilt_y'),
                                        p.get('tilt_z'))
        fmat = np.array([[1, 0, 0], [0, p.get('o22'),
                                     p.get('o21')],
                         [0, p.get('o12'), p.get('o11')]])
        r = np.dot(dmat, fmat)

        outxyz = np.zeros((c.nrows, 3), np.float32)
        cImageD11_wrap.compute_xlylzl_wrap(
            c.sc.astype(np.float32).copy(),
            c.fc.astype(np.float32).copy(), pars, r.ravel(), dist, outxyz)
        error = np.abs(outxyz - xlylzl.T) / np.abs(outxyz + 1)
        if error.mean() > 1e-5:
            print tx, ty, ty
コード例 #19
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
            # Looks like this in one dataset only
            ng = len(self.grainnames)
            int_tmp = numpy.zeros(nr, numpy.int32) - 1
            if 0:  # this is pretty slow
                tth_tmp = numpy.zeros((ng, nr), numpy.float32) - 1
                eta_tmp = numpy.zeros((ng, nr), numpy.float32)

            peaks_xyz = transform.compute_xyz_lab(
                [self.scandata[s].sc, self.scandata[s].fc],
                **self.parameterobj.parameters)
            if not quiet:
                print "Start first grain loop", time.time() - start
            start = time.time()
            gv = numpy.zeros(peaks_xyz.shape, numpy.float, order='F')
            wedge = self.parameterobj.parameters['wedge']
            omegasign = self.parameterobj.parameters['omegasign']
            chi = self.parameterobj.parameters['chi']
            wvln = self.parameterobj.parameters['wavelength']
            first_loop = time.time()
            import fImageD11
            drlv2_2 = self.scandata[s].drlv2 * 0 + 1  # == 1
            int_tmp_2 = numpy.zeros(nr, numpy.int32) - 1
            for g, ig in zip(self.grainnames, range(ng)):
                assert g == ig, "sorry - a bug in program"
                gr = self.grains[(g, s)]
                self.set_translation(g, s)
                gr.peaks_xyz = peaks_xyz
                gr.om = self.scandata[s].omega
                # self.compute_gv( gr )
                # print peaks_xyz.shape, self.scandata[s].omega.shape, gv.shape
                fImageD11.compute_gv(peaks_xyz, self.scandata[s].omega,
                                     omegasign, wvln, wedge, chi,
                                     gr.translation, gv)
                fImageD11.assign(gr.ubi, gv, self.tolerance, drlv2, int_tmp,
                                 int(g))
#                closest.score_and_assign( gr.ubi,
#                                          gv.T,
#                                          self.tolerance,
#                                          drlv2_2,
#                                          int_tmp_2,
#                                          int(g))
            if not quiet:
                print time.time() - first_loop, "First loop"


#                print "assigned"

            self.gv = gv.T.astype(numpy.float32).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(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, range(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=1)
                gr.sc = numpy.take(sc, ind)
                gr.fc = numpy.take(fc, ind)
                gr.om = numpy.take(self.scandata[s].omega, ind)
                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,
                    omega=gr.om * sign,
                    **self.parameterobj.parameters)

                self.scandata[s].tth_per_grain[ind] = tth
                self.scandata[s].eta_per_grain[ind] = eta
                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()
コード例 #20
0
ファイル: cdiffraction.py プロジェクト: jadball/ImageD11
    
    wedge = np.radians(float(pars.get("wedge")))
    chi   = np.radians(float(pars.get("chi")))
    wvln  = float(pars.get("wavelength"))
    
    c = columnfile( colfile )
    try:
        sf = c.sc,c.fc
    except:
        sf = c.xc,c.yc
#    c.nrows = 2
#    c.bigarray = c.bigarray[:,:2]
    print (c.bigarray.shape)
    c.set_attributes()

    XL = flatfloat( compute_xyz_lab( sf , **pars.parameters ).T )
    om = flatfloat( np.radians(c.omega ))


#    XL[0,:]=[41,42,43]

    grains = read_grain_file( grainfile )
    UBIs = flatfloat( [ g.ubi for g in grains ], shape=(len(grains),3,3) )
    UBs =  flatfloat( [ np.linalg.inv(g.ubi) for g in grains ], shape=(len(grains),3,3) )
    Ts  =  flatfloat( [ g.translation for g in grains ], shape=(len(grains),3))


    labels = np.zeros( c.nrows, np.int32 )
    hkls = np.zeros( ( c.nrows, 3 ), NPREAL )

    print( XL.shape)
コード例 #21
0
except:
    pixv=2048.
    pixh=2048.
    mm=1
v = (pixv-1)/2.
h = (pixh-1)/2.

print("Getting parameters from",parfile)

p = parameters.parameters()
p.loadparameters(parfile)

pars = p.get_parameters()

xyz = np.transpose(
    transform.compute_xyz_lab([[v],[h]],
                          **pars))

ks = list(pars.keys())
ks.sort()
for k in ks:
    print(k,pars[k])
print()
print("central pixel position")
print("detector vertical",v,"horizontal",h)
print("real space x, y, z = ", xyz)

print("\n")
print("detector %i %i %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f stem format %i %i %i %i" % \
    (pixv,
     pixh,
     mm*pars['y_size'],