Module: xrd.transforms

22 Functions

hexrd.xrd.transforms.makeGVector(hkl, bMat)[source]

take a CRYSTAL RELATIVE B matrix onto a list of hkls to output unit reciprocal lattice vectors (a.k.a. lattice plane normals)

Required Arguments: hkls – (3, n) ndarray of n hstacked reciprocal lattice vector component

triplets
bMat – (3, 3) ndarray representing the matirix taking reciprocal lattice
vectors to the crystal reference frame

Output: gVecs – (3, n) ndarray of n unit reciprocal lattice vectors

(a.k.a. lattice plane normals)

To Do: * might benefit from some assert statements to catch improperly shaped

input.
hexrd.xrd.transforms.anglesToGVec(angs, bHat_l, eHat_l, rMat_s=None, rMat_c=None)[source]

from ‘eta’ frame out to lab (with handy kwargs to go to crystal or sample)

gvecToDetectorXY(gVec_c, rMat_d, rMat_s, rMat_c, tVec_d, tVec_s, tVec_c, beamVec=array([[-0.],
[-0.],
[-1.]]))

Takes a list of unit reciprocal lattice vectors in crystal frame to the specified detector-relative frame, subject to the conditions:

  1. the reciprocal lattice vector must be able to satisfy a bragg condition
  2. the associated diffracted beam must intersect the detector plane

Required Arguments: gVec_c – (3, n) ndarray of n reciprocal lattice vectors in the CRYSTAL FRAME rMat_d – (3, 3) ndarray, the COB taking DETECTOR FRAME components to LAB FRAME rMat_s – (3, 3) ndarray, the COB taking SAMPLE FRAME components to LAB FRAME rMat_c – (3, 3) ndarray, the COB taking CRYSTAL FRAME components to SAMPLE FRAME tVec_d – (3, 1) ndarray, the translation vector connecting LAB to DETECTOR tVec_s – (3, 1) ndarray, the translation vector connecting LAB to SAMPLE tVec_c – (3, 1) ndarray, the translation vector connecting SAMPLE to CRYSTAL

Outputs: (3, m) ndarray containing the intersections of m <= n diffracted beams associated with gVecs

detectorXYToGvec(xy_det, rMat_d, rMat_s, tVec_d, tVec_s, tVec_c, distortion=(<function GE_41RT at 0x7fb4870bf410>, [0.0, 0.0, 0.0, 2.0, 2.0, 2]), beamVec=array([[-0.],
[-0.],
[-1.]]), etaVec=array([[ 1.],
[ 0.],
[ 0.]]))

Takes a list cartesian (x, y) pairs in the detector coordinates and calculates the associated reciprocal lattice (G) vectors and (bragg angle, azimuth) pairs with respect to the specified beam and azimth (eta) reference directions

Required Arguments: xy_det – (n, 2) ndarray or list-like input of n detector (x, y) points rMat_d – (3, 3) ndarray, the COB taking DETECTOR FRAME components to LAB FRAME rMat_s – (3, 3) ndarray, the COB taking SAMPLE FRAME components to LAB FRAME tVec_d – (3, 1) ndarray, the translation vector connecting LAB to DETECTOR tVec_s – (3, 1) ndarray, the translation vector connecting LAB to SAMPLE tVec_c – (3, 1) ndarray, the translation vector connecting SAMPLE to CRYSTAL

Optional Keyword Arguments: beamVec – (3, 1) mdarray containing the incident beam direction components in the LAB FRAME etaVec – (3, 1) mdarray containing the reference azimuth direction components in the LAB FRAME

Outputs: (n, 2) ndarray containing the (tTh, eta) pairs associated with each (x, y) (3, n) ndarray containing the associated G vector directions in the LAB FRAME associated with gVecs

oscillAnglesOfHKLs(hkls, chi, rMat_c, bMat, wavelength, vInv=array([[ 1.],
[ 1.],
[ 1.],
[ 0.],
[ 0.],
[ 0.]]), beamVec=array([[-0.],
[-0.],
[-1.]]), etaVec=array([[ 1.],
[ 0.],
[ 0.]]))

Takes a list of unit reciprocal lattice vectors in crystal frame to the specified detector-relative frame, subject to the conditions:

  1. the reciprocal lattice vector must be able to satisfy a bragg condition
  2. the associated diffracted beam must intersect the detector plane

Required Arguments: hkls – (3, n) ndarray of n reciprocal lattice vectors in the CRYSTAL FRAME chi – float representing the inclination angle of the oscillation axis (std coords) rMat_c – (3, 3) ndarray, the COB taking CRYSTAL FRAME components to SAMPLE FRAME bMat – (3, 3) ndarray, the COB taking RECIPROCAL LATTICE components to CRYSTAL FRAME wavelength – float representing the x-ray wavelength in Angstroms

Optional Keyword Arguments: beamVec – (3, 1) ndarray containing the incident beam direction components in the LAB FRAME etaVec – (3, 1) ndarray containing the reference azimuth direction components in the LAB FRAME vInv – (6, 1) ndarray containing the indep. components of the inverse left stretch tensor

in the SAMPLE FRAME in the Mandel-Voigt notation

Outputs: ome0 – (3, n) ndarray containing the feasible (tTh, eta, ome) triplets for each input hkl (first solution) ome1 – (3, n) ndarray containing the feasible (tTh, eta, ome) triplets for each input hkl (second solution)

The reciprocal lattice vector, G, will satisfy the the Bragg condition when:

b.T * G / ||G|| = -sin(theta)

where b is the incident beam direction (k_i) and theta is the Bragg angle consistent with G and the specified wavelength. The components of G in the lab frame in this case are obtained using the crystal orientation, Rc, and the single-parameter oscillation matrix, Rs(ome):

Rs(ome) * Rc * G / ||G||

The equation above can be rearranged to yeild an expression of the form:

a*sin(ome) + b*cos(ome) = c

which is solved using the relation:

a*sin(x) + b*cos(x) = sqrt(a**2 + b**2) * sin(x + alpha)

—> sin(x + alpha) = c / sqrt(a**2 + b**2)

where:

alpha = arctan2(b, a)

The solutions are:

/ | arcsin(c / sqrt(a**2 + b**2)) - alpha
x = <
pi - arcsin(c / sqrt(a**2 + b**2)) - alpha

There is a double root in the case the reflection is tangent to the Debye-Scherrer cone (c**2 = a**2 + b**2), and no solution if the Laue condition cannot be satisfied (filled with NaNs in the results array here)

polarRebin(thisFrame, npdiv=2, mmPerPixel=(0.2, 0.2), convertToTTh=False, rMat_d=array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]]), tVec_d=array([ 0., 0., -1000.]), beamVec=array([[-0.],
[-0.],
[-1.]]), etaVec=array([[ 1.],
[ 0.],
[ 0.]]), rhoRange=array([ 20, 200]), numRho=1000, etaRange=array([-0.08726646, 6.19591884]), numEta=36, verbose=True, log=None)

Caking algorithm

INPUTS

thisFrame npdiv=2, pixel subdivision (n x n) to determine bin membership rhoRange=[100, 1000] - radial range in pixels numRho=1200 - number of radial bins etaRange=np.pi*np.r_[-5, 355]/180. – range of eta numEta=36 - number of eta subdivisions ROI=None - region of interest (four vector) corrected=False - uses 2-theta instead of rho verbose=True,

hexrd.xrd.transforms.arccosSafe(temp)[source]

Protect against numbers slightly larger than 1 in magnitude due to round-off

hexrd.xrd.transforms.angularDifference(angList0, angList1, units='radians')[source]

Do the proper (acute) angular difference in the context of a branch cut.

*) Default angular range is [-pi, pi]

hexrd.xrd.transforms.mapAngle(ang, *args, **kwargs)[source]

Utility routine to map an angle into a specified period

hexrd.xrd.transforms.reg_grid_indices(edges, points_1d)[source]

get indices in a 1-d regular grid.

edges are just that:

point: x (2.5)

edges: |1 |2 |3 |4 |5
indices: | 0 | 1 | 2 | 3 |

above the deltas are + and the index for the point is 1

point: x (2.5)

edges: |5 |4 |3 |2 |1
indices: | 0 | 1 | 2 | 3 |

here the deltas are - and the index for the point is 2

  • can handle grids with +/- deltas
  • be careful when using with a cyclical angular array! edges and points must be mapped to the same branch cut, and abs(edges[0] - edges[-1]) = 2*pi
hexrd.xrd.transforms.columnNorm(a)[source]

normalize array of column vectors (hstacked, axis = 0)

hexrd.xrd.transforms.rowNorm(a)[source]

normalize array of row vectors (vstacked, axis = 1)

hexrd.xrd.transforms.unitVector(a)[source]

normalize array of column vectors (hstacked, axis = 0)

hexrd.xrd.transforms.makeDetectorRotMat(tiltAngles)[source]

Form the (3, 3) tilt rotations from the tilt angle list:

tiltAngles = [gamma_Xl, gamma_Yl, gamma_Zl] in radians

hexrd.xrd.transforms.makeOscillRotMat(oscillAngles)[source]

oscillAngles = [chi, ome]

hexrd.xrd.transforms.makeRotMatOfExpMap(expMap)[source]
hexrd.xrd.transforms.makeBinaryRotMat(axis)[source]
hexrd.xrd.transforms.makeEtaFrameRotMat(bHat_l, eHat_l)[source]

make eta basis COB matrix with beam antiparallel with Z

takes components from ETA frame to LAB

hexrd.xrd.transforms.validateAngleRanges(angList, startAngs, stopAngs, ccw=True)[source]

A better way to go. find out if an angle is in the range CCW or CW from start to stop

There is, of course, an ambigutiy if the start and stop angle are the same; we treat them as implying 2*pi having been mapped

hexrd.xrd.transforms.rotate_vecs_about_axis(angle, axis, vecs)[source]

Rotate vectors about an axis

INPUTS angle - array of angles (len == 1 or n) axis - array of unit vectors (shape == (3, 1) or (3, n)) vec - array of vectors to be rotated (shape = (3, n))

Quaternion formula: if we split v into parallel and perpedicular components w.r.t. the axis of quaternion q,

v = a + n

then the action of rotating the vector dot(R(q), v) becomes

v_rot = (q0**2 - |q|**2)(a + n) + 2*dot(q, a)*q + 2*q0*cross(q, n)
hexrd.xrd.transforms.quat_product_matrix(q, mult='right')[source]

Form 4 x 4 array to perform the quaternion product

USAGE
qmat = quatProductMatrix(q, mult=’right’)
INPUTS
  1. quats is (4,), an iterable representing a unit quaternion horizontally concatenated

  2. mult is a keyword arg, either ‘left’ or ‘right’, denoting the sense of the multiplication:

    / quatProductMatrix(h, mult=’right’) * q

    q * h –> <

    quatProductMatrix(q, mult=’left’) * h

OUTPUTS
  1. qmat is (4, 4), the left or right quaternion product operator
NOTES
*) This function is intended to replace a cross-product based
routine for products of quaternions with large arrays of quaternions (e.g. applying symmetries to a large set of orientations).
hexrd.xrd.transforms.quat_distance(q1, q2, qsym)[source]