Exemplo n.º 1
0
 def rdubis(self, ubifile=None):
     from ImageD11 import indexing
     if ubifile == None:
         ubifile = tkinter.filedialog.askopenfilename(
             initialdir=os.getcwd())
     self.ubisread = indexing.readubis(ubifile)
     print("Read into self.ubisread", self.ubisread)
Exemplo n.º 2
0
def generate_gve(uf, nh=6):
    """ uf is a ubi filename"""
    h = generate_hkls(nh)
    g = []
    i = 0
    for u in indexing.readubis(uf):
        r = np.dot(np.linalg.inv(u), h).T
        g.append(r)
        i += 1
    return np.array(g).reshape((h.shape[1] * i, 3))
Exemplo n.º 3
0
from ImageD11 import cImageD11, indexing, transformer

# open up a set of ubi files

parfilename = sys.argv[1]

ubifl = glob.glob(sys.argv[2])

#for a in glob.glob(sys.argv[3:]):
#   ubifl += glob.glob(a)

ubi_all = {}
for fname in ubifl:
    print fname
    ubi_all[fname] = indexing.readubis(fname)
print "OK"

# Now try to make these into a unique set.
#
# For each ubi:
#     compute the reciprocal peak positions of central lattice
#     see if these match a previous one.

pks = [(0, 0, 1), (0, 1, 0), (1, 0, 0), (0, 0, -1), (0, -1, 0), (-1, 0, 0),
       (0, 1, 1), (1, 1, 0), (1, 0, 1), (0, -1, 1), (1, -1, 0), (-1, 0, 1),
       (0, 1, -1), (-1, 1, 0), (1, 0, -1), (0, -1, -1), (-1, -1, 0),
       (-1, 0, -1), (1, 1, 1), (-1, 1, 1), (1, -1, 1), (1, 1, -1), (-1, -1, 1),
       (-1, 1, -1), (1, -1, -1), (-1, -1, -1)]

hkl = np.array(pks, float).T
Exemplo n.º 4
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


if __name__ == "__main__":
    flt = sys.argv[1]
    par = sys.argv[2]
    grains = sys.argv[3]

    ul = indexing.readubis(grains)

    po = parameters.parameters()
    po.loadparameters(par)
    pars = po.get_parameters()

    dcen = float(pars["distance"])
    zcen = float(pars["z_center"])
    ycen = float(pars["y_center"])
    f = open("parmap", "a")
    for dist in [dcen * 0.99, dcen, dcen * 1.01]:
        pars["distance"] = dist
        for yc in [ycen - 1, ycen, ycen + 1]:
            pars["y_center"] = yc
            for zc in [zcen - 1, zcen, zcen + 1]:
                pars["z_center"] = zc
Exemplo n.º 5
0
def main():
    """
    A user interface
    """
    import sys, time, os, logging
    start = time.time()

    root = logging.getLogger('')
    root.setLevel(logging.WARNING)

    try:
        from optparse import OptionParser
        parser = OptionParser()
        parser = get_options(parser)
        options, args = parser.parse_args()
    except SystemExit:
        raise
    except:
        parser.print_help()
        print("\nProblem with your options:")
        raise

    if options.output is None:
        print("You must supply an output file (-o vol.h5)")
        sys.exit()

    if os.path.exists(options.output):
        print("I would overwrite your output file", options.output)
        print("If you really want that then delete it first and re-run")
        sys.exit()

    try:
        if options.pars is None:
            print("You must supply a parameter file, -p file.pars")
            sys.exit()
        pars = parameters.parameters()
        pars.loadparameters(options.pars)
        print("Got parameters from", options.pars)
        pd = pars.get_parameters()
        names = list(pd.keys())
        names.sort()
        for name in names:
            print("%30s   %s" % (name, pd[name]))
    except:
        print("Problem with parameters:", options.pars)
        raise

    try:
        if options.ubifile is None:
            print("You must supply an input ubifile")
        ubi = indexing.readubis(options.ubifile)[0]
        print("UBI:\n", ubi)
        print("Cell parameters:")
        print("%.5f %.5f %.5f %.4f %.4f %.4f" % \
              indexing.ubitocellpars(ubi))
    except:
        print("Problem with ubi file:", options.ubifile)
        raise

    if options.maskfilename is not None:
        from fabio.openimage import openimage
        try:
            mask = (openimage(options.maskfilename).data == 0)
        except:
            print("Problem with your mask image", options.maskfilename)
            raise
        print("Using a mask from", options.maskfilename)
        print("percent of image used %.3f" %
              (100.0 * mask.sum() / mask.shape[0] / mask.shape[1]))
    else:
        mask = None

    first_image = True
    nimage = 0

    imagefiles = ImageD11_file_series.get_series_from_options(options, args)

    print("Subslicing by", options.subslice)

    try:
        for fim in imagefiles:

            if first_image:  # allocate volume, compute k etc

                first_image = False

                mapper = rsv_mapper(fim.data.shape,
                                    pars,
                                    ubi,
                                    options.spline,
                                    np=options.npixels,
                                    border=options.border,
                                    maxpix=options.maxpix,
                                    mask=mask
                                    # FIXME omegarange
                                    )

                logging.info("Setting up time %.4f s" % (time.time() - start))

            ltp = time.time()
            om = float(fim.header['Omega'])
            oms = float(fim.header['OmegaStep'])
            for i in range(options.subslice):
                print(".", end=' ')
                omv = om + i * oms / options.subslice
                # ==1 : 0*s/1
                # ==2 : 0*s/2 , 1*s/2
                # ==3 : 0*s/3 , 1*s/3, 2*s/3 etc
                mapper.add_image(omv, fim.data)

            nimage = nimage + 1

            print("  %d %.3f %.4f s, %.4f s" %
                  (nimage, om, time.time() - ltp, time.time() - start))
            if options.images is not None:
                if nimage >= options.images:
                    break

    except KeyboardInterrupt:
        print("\nCaught a control-c")
        if nimage > 0:
            print("Problem, trying to save volume so far to:", options.output)
            mapper.writevol(options.output)
            print("Saved what I had")
        sys.exit()
    except:
        print("\nAn error occured")
        if nimage > 0:
            print("Problem, trying to save volume so far to:", options.output)
            mapper.writevol(options.output)
            print("Saved what I had")
        raise

    if nimage > 0:
        mapper.writevol(options.output)
Exemplo n.º 6
0
# open up a set of ubi files

ubifl = glob.glob(sys.argv[1] + "/*.ubi")

ubi_all = {}

#print "Make cubic point group"
c = sym_u.cubic()
c.makegroup()

for fname in ubifl:
    #print fname

    # Flip to standard setting
    ubi_all[fname] = [
        sym_u.find_uniq_u(ubi, c) for ubi in indexing.readubis(fname)
    ]

# Now try to make these into a unique set.
#
# For each ubi:
#     compute the reciprocal peak positions of central lattice
#     see if these match a previous one.

pks = [
    (5, 3, -1),
    (5, -3, 1),
    (-5, 3, 1),
    (-5, -3, 1),
    (-5, 3, -1),
    (5, -3, -1),
Exemplo n.º 7
0
                while ts[0] < best[0]:
                    # print "got better"
                    best = ts
                    # print "new best",best
                    tv = ts[1] + u[j]*sign
                    ts = norm2(tv),tv
        u[i] = best[1]
    #print "returning",u
    return u
            


for ubifile in sys.argv[1:]:
    print("Reading",ubifile, end=' ')
    try:
        ul = indexing.readubis(ubifile)
    except:
        print("error")
        continue
    print() 
    print("i    a       b       c     alpha    beta     gamma    volume")
    cell_all = []
    volume = []
    for u,i  in zip(ul,list(range(len(ul)))):
        print(i, end=' ') 
        cell = indexing.ubitocellpars(u)
        vol = cell[0]*cell[1]*cell[2]*numpy.sin(cell[3]*numpy.pi/180.)*numpy.sin(cell[4]*numpy.pi/180.)*numpy.sin(cell[5]*numpy.pi/180.)
        print("%.5f "*6 % cell + "%.5f" %vol)
        cell_all.append(cell)
        volume.append(vol)
        continue
Exemplo n.º 8
0
from __future__ import print_function
from ImageD11.indexing import readubis
from ImageD11.transform import uncompute_g_vectors
from ImageD11 import unitcell
import numpy as np

ul = readubis("test.ubi")
ui = [ np.linalg.inv(ubi) for ubi in ul ]

r = range(-4,5)
hkls = np.array([ (h,k,l) for h in r for k in r for l in r ])


gcalc = [ np.dot( ub, hkls.T).T for ub in ui]

# 30 keV
energy = 30
wvln = 12.3985 / energy
ng = 0
for g, ubi in zip(gcalc, ul):
    ng +=1
    print ("# Grain",ng, "\n# Energy",energy,"keV, wavelength %.5f"%(wvln))
    tth, eta, omega = uncompute_g_vectors( g.T, wvln )
    order = np.argsort(tth)
    # hkls = np.dot( ubi, g.T).T
    print ("#   h    k    l   tth     eta    omega")
    for j in range(len(order)):
        i = order[j]
        for s in (0,1):
            h,k,l = [int(v) for v in hkls[i]]
            if tth[i]>0  and tth[i] < 20 and \
Exemplo n.º 9
0
 def readubis(self,ubis):
     from ImageD11 import indexing
     return indexing.readubis(ubis)