예제 #1
1
파일: indexer.py 프로젝트: B-Rich/hexrd
def convertUToRotMat(Urows, U0, symTag='Oh', display=False):
    """
    Takes GrainSpotter gff ouput in rows

    U11 U12 U13 U21 U22 U23 U13 U23 U33

    and takes it into the hexrd/APS frame of reference

    Urows comes from grainspotter's gff output
    U0 comes from xrd.crystallography.latticeVectors.U0
    """

    numU, testDim = Urows.shape
    assert testDim == 9, "Your input must have 9 columns; yours has %d" % (testDim)

    qin  = quatOfRotMat(Urows.reshape(numU, 3, 3))
    qout = num.dot( quatProductMatrix( quatOfRotMat(fableSampCOB), mult='left' ), \
                    num.dot( quatProductMatrix( quatOfRotMat(U0.T), mult='right'),  \
                             qin ).squeeze() ).squeeze()
    if qout.ndim == 1:
        qout = toFundamentalRegion(qout.reshape(4, 1), crysSym=symTag, sampSym=None)
    else:
        qout = toFundamentalRegion(qout, crysSym=symTag, sampSym=None)
    if display:
        print "quaternions in (Fable convention):"
        print qin.T
        print "quaternions out (hexrd convention, symmetrically reduced)"
        print qout.T
        pass
    Uout = rotMatOfQuat(qout)
    return Uout
예제 #2
0
파일: indexer.py 프로젝트: B-Rich/hexrd
def convertRotMatToFableU(rMats, U0=num.eye(3), symTag='Oh', display=False):
    """
    Makes GrainSpotter gff ouput

    U11 U12 U13 U21 U22 U23 U13 U23 U33

    and takes it into the hexrd/APS frame of reference

    Urows comes from grainspotter's gff output
    U0 comes from xrd.crystallography.latticeVectors.U0
    """
    numU = num.shape(num.atleast_3d(rMats))[0]

    qin  = quatOfRotMat(num.atleast_3d(rMats))
    qout = num.dot( quatProductMatrix( quatOfRotMat(fableSampCOB.T), mult='left' ), \
                    num.dot( quatProductMatrix( quatOfRotMat(U0), mult='right'),  \
                             qin ).squeeze() ).squeeze()
    if qout.ndim == 1:
        qout = toFundamentalRegion(qout.reshape(4, 1), crysSym=symTag, sampSym=None)
    else:
        qout = toFundamentalRegion(qout, crysSym=symTag, sampSym=None)
    if display:
        print "quaternions in (hexrd convention):"
        print qin.T
        print "quaternions out (Fable convention, symmetrically reduced)"
        print qout.T
        pass
    Uout = rotMatOfQuat(qout)
    return Uout
예제 #3
0
def convertRotMatToFableU(rMats, U0=num.eye(3), symTag='Oh', display=False):
    """
    Makes GrainSpotter gff ouput

    U11 U12 U13 U21 U22 U23 U13 U23 U33

    and takes it into the hexrd/APS frame of reference

    Urows comes from grainspotter's gff output
    U0 comes from xrd.crystallography.latticeVectors.U0
    """
    numU = num.shape(num.atleast_3d(rMats))[0]

    qin = quatOfRotMat(num.atleast_3d(rMats))
    qout = num.dot( quatProductMatrix( quatOfRotMat(fableSampCOB.T), mult='left' ), \
                    num.dot( quatProductMatrix( quatOfRotMat(U0), mult='right'),  \
                             qin ).squeeze() ).squeeze()
    if qout.ndim == 1:
        qout = toFundamentalRegion(qout.reshape(4, 1),
                                   crysSym=symTag,
                                   sampSym=None)
    else:
        qout = toFundamentalRegion(qout, crysSym=symTag, sampSym=None)
    if display:
        print "quaternions in (hexrd convention):"
        print qin.T
        print "quaternions out (Fable convention, symmetrically reduced)"
        print qout.T
        pass
    Uout = rotMatOfQuat(qout)
    return Uout
예제 #4
0
def convertUToRotMat(Urows, U0, symTag='Oh', display=False):
    """
    Takes GrainSpotter gff ouput in rows

    U11 U12 U13 U21 U22 U23 U13 U23 U33

    and takes it into the hexrd/APS frame of reference

    Urows comes from grainspotter's gff output
    U0 comes from xrd.crystallography.latticeVectors.U0
    """

    numU, testDim = Urows.shape
    assert testDim == 9, "Your input must have 9 columns; yours has %d" % (
        testDim)

    qin = quatOfRotMat(Urows.reshape(numU, 3, 3))
    qout = num.dot( quatProductMatrix( quatOfRotMat(fableSampCOB), mult='left' ), \
                    num.dot( quatProductMatrix( quatOfRotMat(U0.T), mult='right'),  \
                             qin ).squeeze() ).squeeze()
    if qout.ndim == 1:
        qout = toFundamentalRegion(qout.reshape(4, 1),
                                   crysSym=symTag,
                                   sampSym=None)
    else:
        qout = toFundamentalRegion(qout, crysSym=symTag, sampSym=None)
    if display:
        print "quaternions in (Fable convention):"
        print qin.T
        print "quaternions out (hexrd convention, symmetrically reduced)"
        print qout.T
        pass
    Uout = rotMatOfQuat(qout)
    return Uout
예제 #5
0
def quaternion_ball(qref, radius, num=500):
    """
    Makes a ball of randomly sampled quaternions within the specified misorientation of the supplied reference.

    Parameters
    ----------
    qref : array_like, (4,)
        Unit quaternion defining the reference orientation.
    radius : scalar
        Maximum misorientation in degrees.
    num : int, optional
        The number of orientations to generate. The default is 500.

    Returns
    -------
    The (4, num) array of quaternions around qref.

    """
    # make random angle/axis pairs
    rand_angs = np.radians(radius) * np.random.rand(num)
    rand_axes = mutil.unitVector(np.random.randn(3, num))

    # form quats
    qball = rot.quatOfAngleAxis(rand_angs, rand_axes)

    # recenter around reference orientation
    qref_mat = rot.quatProductMatrix(np.atleast_1d(qref).reshape(4, 1),
                                     mult='right').squeeze()

    return np.dot(qref_mat, qball)