示例#1
0
def main():
    import sys, time
    c = columnfile(sys.argv[1])
    p = read_par_file(sys.argv[2])
    u = unitcell_from_parameters(p)
    gl = read_grain_file(sys.argv[3])
    if gl[0].translation is None:
        gl[0].translation = np.array((0., 0., 0.))
    start = time.time()
    # Setup and assign hkls
    w = p.get("wavelength")
    peaks_Cxyz, beam_Cxyz = getCxyz(c, p)
    t = gl[0].translation.copy()
    ub = gl[0].ub.copy()
    ubi = gl[0].ubi.copy()
    gve = compute_Cgve(t, peaks_Cxyz, beam_Cxyz, w)
    hi = np.round(np.dot(ubi, gve))
    lastgof = 1e9
    ubn, tn = fit_ub_t(ub, t, hi, peaks_Cxyz, beam_Cxyz, w)
    print("Before\nt=", gl[0].translation)
    print("UB=", gl[0].ub)
    gl[0].set_ubi(np.linalg.inv(ubn))
    gl[0].translation = tn
    dt = time.time() - start
    print("time calculating", dt, "gps", 1 / dt)
    print("After\nt=", gl[0].translation)
    print("UB=", gl[0].ub)
    write_grain_file(sys.argv[4], gl)
示例#2
0
def fit_hkl(c, pi, pj, tth, eta, stem):
    u = unitcell.unitcell_from_parameters(c.parameters)
    u.makerings(c.ds.max() * 1.1, tol=0.001)
    w = c.parameters.get("wavelength")
    tthv = [tth_ds(ds, w) for ds in u.ringds]
    print("(h, k, l)  tthcalc  <tthobs>  Gradient_sin2p Intercept_sin2p")
    for tth0, d in zip(tthv[:46], u.ringds):
        print(u.ringhkls[d][0], end=" ")
        m = abs(tth - tth0) < 0.025  # tolerance in tth
        try:
            s, th0, p, sc, s2e = strain(tth[m], eta[m])
            print(tth0, np.degrees(th0 * 2), p[0], p[1])
            sys.stdout.flush()
        except:
            print()
            continue
        try:
            f = pl.figure(2, dpi=200, figsize=(20, 15))
            f.clf()
            f.add_subplot(2, 3, 1)
            #pl.subplot(231)
            pl.plot(eta[m], tth[m], "+")
            pl.ylabel("tth")
            f.add_subplot(2, 3, 2)
            #pl.subplot(23)
            pl.plot(eta[m], d_tth(tth[m], w), "+")
            pl.ylabel("d-spacing")
            #pl.subplot(233)
            f.add_subplot(2, 3, 3)
            pl.plot(eta[m], s, "+")
            pl.plot(eta[m], sc, "x")
            #pl.subplot(234)
            f.add_subplot(2, 3, 4)
            pl.plot(s2e, tth[m], "+")
            pl.ylabel("tth")
            #pl.subplot(235)
            f.add_subplot(2, 3, 5)
            pl.plot(s2e, d_tth(tth[m], w), "+")
            pl.ylabel("d-spacing")
            f.add_subplot(2, 3, 6)
            pl.plot(s2e, s, "+")
            pl.plot(s2e, sc, "x")
            pl.ylabel("strain")
            hkl = "_%d_%d_%d.png" % (tuple(u.ringhkls[d][0]))
            f.savefig(stem + hkl)


#            pl.show()

        except:
            print("Fail")
            raise
示例#3
0
def initgrid(fltfile, parfile, tmp, gridpars):
    """
    Sets up a grid indexing by preparing the unitcell for indexing
    and checking the columns we want are in the colfile
    """
    mytransformer = transformer.transformer()
    mytransformer.loadfiltered(fltfile)
    mytransformer.loadfileparameters(parfile)
    gridpars['UC'] = unitcell.unitcell_from_parameters(
        mytransformer.parameterobj)
    col = mytransformer.colfile
    if not "drlv2" in col.titles:
        col.addcolumn(np.ones(col.nrows, float), "drlv2")
    if not "labels" in col.titles:
        col.addcolumn(np.ones(col.nrows, float) - 2, "labels")
    if not "sc" in col.titles:
        assert "xc" in col.titles
        col.addcolumn(col.xc.copy(), "sc")
    if not "fc" in col.titles:
        assert "yc" in col.titles
        col.addcolumn(col.yc.copy(), "fc")
    mytransformer.colfile.writefile("%s.flt" % (tmp))
    return gridpars
示例#4
0
from __future__ import print_function

from ImageD11 import unitcell, parameters, transform
import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D
import sys

pars = parameters.read_par_file(sys.argv[1])

# Input unit cell from par file
u = unitcell.unitcell_from_parameters(pars)

# Generate diffraction spots for unit cell:
u.makerings(0.7)
hkls = []
for d in u.ringds:
    hkls += u.ringhkls[d]
hkls = np.array(hkls).T

# A grain orientation
U0 = transform.detector_rotation_matrix(0.1, 0.2, 0.3)
UB0 = np.dot(U0, u.B)

# Ideal diffraction vectors:
gve = np.dot(UB0, hkls)
modg = np.sqrt((gve * gve).sum(axis=0))

# print scattering vectors in order
order = np.argsort(modg)
for i in order[10::-1]:
示例#5
0
translations = [(t_x, t_y, t_z) for t_x in range(-500, 501, 200)
                for t_y in range(-500, 501, 200)
                for t_z in range(-500, 501, 200)]
# Cylinder:
# filter( lambda x,y,z : (x*x+y*y)< 500*500, translations )
random.seed(42)  # reproducible
random.shuffle(translations)

# printing or quiet:
if 1:
    NUL = open("/dev/null", "w")
else:
    NUL = sys.stdout

# Get the unit cell
UC = unitcell.unitcell_from_parameters(mytransformer.parameterobj)

col = mytransformer.colfile
if not "drlv2" in col.titles:
    col.addcolumn(np.ones(col.nrows, float), "drlv2")
if not "labels" in col.titles:
    col.addcolumn(np.ones(col.nrows, float) - 2, "labels")
if not "sc" in col.titles:
    assert "xc" in col.titles
    col.addcolumn(col.xc.copy(), "sc")
if not "fc" in col.titles:
    assert "yc" in col.titles
    col.addcolumn(col.yc.copy(), "fc")


class tick:
示例#6
0
    


 
if __name__=="__main__":
    flt  = columnfile.columnfile( sys.argv[1] )

    flt.filter( flt.Number_of_pixels > 4 )
    flt.filter( flt.tth < 20 )
    
    
    flt.addcolumn(np.zeros(flt.nrows)-1,"labels")
    flt.addcolumn(np.zeros(flt.nrows)-1,"drlv2")
    pars = parameters.read_par_file( sys.argv[2] )
    
    gridpars[ 'UC' ] = unitcell.unitcell_from_parameters( pars )

    wvln = pars.get("wavelength")
    pars.stepsizes['t_x']=1
    pars.stepsizes['t_y']=1
    pars.stepsizes['t_z']=1
    xy = []
    


    for x in np.arange(-0.31, 0.3101, 0.001):
        for y in np.arange(-0.31, 0.3101, 0.001):
            if x*x + y*y > 0.31*0.31:
                continue
            xy.append( (x,y) )
示例#7
0
from ImageD11.parameters import read_par_file
from ImageD11.transform import compute_tth_eta
import numpy as np
import pylab as pl

# put parfile, npeaks and tol and this would be general purpose!
c = columnfile(sys.argv[1])
p = read_par_file(sys.argv[2])
tol = float(sys.argv[3])
tthmax = float(sys.argv[4])
outfile = sys.argv[5]
npx = int(sys.argv[6])
top = int(sys.argv[7])
c.filter(c.Number_of_pixels > npx)

u = unitcell_from_parameters(p)
w = p.get("wavelength")

tth, eta = compute_tth_eta((c.sc, c.fc), **p.parameters)

dsmax = 2 * np.sin(1.03 * tth.max() * np.pi / 360) / w
u.makerings(dsmax)

mask = np.zeros(c.nrows, dtype=np.bool)
for d in u.ringds:
    tthc = np.arcsin(w * d / 2) * 360 / np.pi
    M = len(u.ringhkls[d])
    print("hkl", u.ringhkls[d][-1], M, end=" ")
    sel = abs(tth - tthc) < tol
    nring = sel.sum()
    print(nring, end=" ")