Module: xrd.xrdutil

6 Classes

class hexrd.xrd.xrdutil.FormatEtaOme(etas, omes, A, T=False, debug=False)[source]

for plotting data as a matrix, with ijAsXY=True

__init__(etas, omes, A, T=False, debug=False)[source]
class hexrd.xrd.xrdutil.OmeEtaPfig(omeEdges, etaEdges, cmap=None, vMM=None, doRot=False, invertFromSouthern=True, netStyle=None, netNDiv=12, netAlpha=0.5, pointLists=, []drawColorbar=True)[source]

Bases: object

works with data from with CollapseOmeEta

__init__(omeEdges, etaEdges, cmap=None, vMM=None, doRot=False, invertFromSouthern=True, netStyle=None, netNDiv=12, netAlpha=0.5, pointLists=, []drawColorbar=True)[source]
clearLines()[source]

get rid of any existing lines and legends

display(data, tTh, nP=True, opacity=[None], rangeVV_w=None, winKWArgs={})[source]

if want to do interpolated results, matplotlib.delaunay has some triangulation and interpolation stuff, but have not sorted that out yet

drawLines(nP, rMat=None, pointLists=None)[source]

if specify a pointLists argument then it replaces self.pointLists

class hexrd.xrd.xrdutil.CollapseOmeEta(readerList, planeData, hklList, detectorGeom, strainMag=None, nEtaBins=480, mask=None, threshold=None, applyLorenz=True, nframesLump=1, debug=False, computeMeanTwoTheta=False)[source]

Bases: object

Can pass a mask to use in addition to whatever the readers are already set up to do; with frames set zero where mask is True

If pass pw: after plot is made, can do calls on self.pw to plot other things on top of the image

while this takes a list of readers, it is not yet really coded for disjoint omega ranges

__init__(readerList, planeData, hklList, detectorGeom, strainMag=None, nEtaBins=480, mask=None, threshold=None, applyLorenz=True, nframesLump=1, debug=False, computeMeanTwoTheta=False)[source]
display(iData=0, rangeVV=None, cmap=None, pw=None, debug=False, pfig=False, comment='', tTh=False, rangeVV_w=None, winKWArgs={}, pfigKWArgs={})[source]

iData is index into hklList passed on initialization, NOT into planeData

pointList, if specified is a list of tuples of the form (3xn ndarray, style) where style gets passed to plotwrap

can set tTh to ‘withOpacity’ if the 2-theta plot should be made with opacity (alpha) constructed from the intensity weights; so far this only works for pfig=False

etas = None

count frames

iEtaBin = None

protect against numerical silliness

indices = None

make valsThese into float so that do not overrun max int value

tThRanges = None

set up data

class hexrd.xrd.xrdutil.GrainPoles(omeEtaPfigs)[source]
__init__(omeEtaPfigs)[source]
class hexrd.xrd.xrdutil.MultiSlopeFunc(m1, m2, xcrit, power=0.2)[source]

function that transitions smoothly from slope of m1 to slope of m2 in the vacinity of xcrit, with the smoothness of the transition dictated by a specified power; for large values of power, might eventually want to put in code to protect against numerical overflow

__init__(m1, m2, xcrit, power=0.2)[source]
class hexrd.xrd.xrdutil.MultiSlopeFuncSmooth(m1, w1, p1, m2, xcrit, power=0.2)[source]

function that transitions smoothly from slope of m1 to slope of m2 in the vacinity of xcrit, with the smoothness of the transition dictated by a specified power;

__init__(m1, w1, p1, m2, xcrit, power=0.2)[source]

48 Functions

hexrd.xrd.xrdutil.fitLParm(data, detectorGeom, planeData, funcType='pv', lParm0=None, funcXVecList=None, quadr1d=8, debug=False)[source]

fit lattice parameters to data; using dataToFrame to map the data to a frame

input planeData is not changed

hexrd.xrd.xrdutil.fitDG(data, detectorGeom, planeData, funcType='pv', funcXVecList=None, quadr1d=8, debug=False)[source]

fit detector geometry parameters to data; using dataToFrame to map the data to a frame

pass funcXVecList as True or as something like detectorGeom.fitRingsFunc.getFuncXVecList() if want to just refine detector geometry and not the functional forms for the rings

input detectorGeom is used to guess parameters and is not modified – a new detectorGeom is returned

hexrd.xrd.xrdutil.fitDGX(data, detectorGeom, planeData, funcType='pv', quadr1d=8, debug=False, nGlIter=2, xFuncs=None, xDG=None)[source]

fit detector geometry parameters to data; using dataToFrame to map the data to a frame

uses a procedure that might end up being more robust than fitDG

input detectorGeom is used to guess parameters and is not modified – a new detectorGeom is returned

hexrd.xrd.xrdutil.textureToSpots(texture, planeData, detectorGeom, omeMM=None, etaMM=None, pVecs=None)[source]

take texture as returned from pyMps and make spots

hexrd.xrd.xrdutil.makeSynthSpots(rMats, pVecs, bMats, planeData, detectorGeom, omeMM=[-3.141592653589793, 3.141592653589793], etaMM=None, hklList=None, beamSize=None)[source]

make synthetic spots

hexrd.xrd.xrdutil.makePathVariantPoles(rMatRef, fromPhase, pathList, planeDataDict, hklID)[source]
hexrd.xrd.xrdutil.displayPathVariants(data, rMatRef, fromPhase, pathList, planeDataDict, detectorGeom, omeMin, omeMax, phaseForDfltPD=None, markerList=['D', 'o', 'p', 's', 'v', 'x', '+', '*', '<', '>', '1', '2', '3', '4', '^'], hklList=None, color=None, pointKWArgs={}, hklIDs=None, pw=None)[source]
hexrd.xrd.xrdutil.makeRMatList(pathList, fromPhase)[source]
hexrd.xrd.xrdutil.findGrainsNewSpots(grainList0, spots, doFitting=True, minCompleteness=None, pathList=, []eosDict=None, refPDDict=None, tK=300.0, debug=True, indepFitPVec=False, findByPixelDist=1, maxIterRefit=3, pVecTol=None)[source]

see if grains in grainList0 show up in spots; meant to be useful for taking existing grains from a load step and looking for them in a new load step; returns a new list of the same length, with None wherever a grain near the existing one was not found, and a list of grains for each path in pathList; grains in grainList0 are not modified; spots should be a Spots instance

hexrd.xrd.xrdutil.stretchToLV(V, fMat)[source]

from stretch V in crystal frame and fMat, compute new lattice parameters; fMat can be the ‘F’ from lparms.latticeVectors

V = B + I, where B is the Biot strain

hexrd.xrd.xrdutil.calculateBiotStrain(initLP, finalLP, display=False)[source]
hexrd.xrd.xrdutil.makeMNConn(m, n, tri=True)[source]

m and n are number of edges, so 1 more than number of zones

hexrd.xrd.xrdutil.makeNVecs(tth, etaIn, omeIn, asGrid=False)[source]
hexrd.xrd.xrdutil.omeEtaGridToNVecs(tTh, omegas, etas)[source]
hexrd.xrd.xrdutil.roty90(v)[source]
hexrd.xrd.xrdutil.makeMeasuredScatteringVectors(tTh, eta, ome, convention='hexrd', frame='sample')[source]

Construct scattering vectors from angles (2theta, eta, ome) will do HEXRD/APS and Fable frames, sample or lab.

for fable frame geomtery, see:

http://sourceforge.net/apps/trac/fable/attachment/wiki/WikiStart/Geometry_version_1.0.8.pdf

hexrd.xrd.xrdutil.doItMP(nSkip)[source]
hexrd.xrd.xrdutil.readFrameStack_multiproc(reader, func, nPerChunk=None, nCPUs=None, debug=False)[source]

read the full frame stack using multiprocessing, applying fund to each frame to obtain the result;

use makeNew for each chunk; if reader.dark is a shared memory array then it remains so

hexrd.xrd.xrdutil.thresholdStackDisplay(data, threshold, cmap=None, pw=None, detectorGeom=None, planeData=None, displayKWArgs={}, drawRingsKWArgs={})[source]

passes sumImg=num.maximum to dataToFrame so that if data is a reader then frame ends up being the maximum over the image stack

hexrd.xrd.xrdutil.grainPolesGUI(omeEtaPfigs)[source]

GUI with sliders for rotating a grain’s spots

execfile(‘examples/feSynthSpotsPfig.py’) gui = grainPolesGUI([pwSB])

hexrd.xrd.xrdutil.darkFromStack(reader, nFrames=0, nChunk=4, medianSize=None, medianRange=(-15, 15), cutMinFactor=None, checkIntensityResolution=False)[source]

If nFrames == 0, read all frames.

If medianSize is specified then a median filter of the given size is used to find dead pixels, with pixels outside of medianRange marked as dead.

hexrd.xrd.xrdutil.tryFromShelf(shelfFileName, thingName)[source]

try to pull the thing from the shelf and return None if it does not work

hexrd.xrd.xrdutil.putInShelf(shelfFileName, thingName, thing)[source]
hexrd.xrd.xrdutil.pullFromStack(reader, detectorGeom, tThMM, angWidth, angCen, threshold=20, distInAng=False, padSpot=True, mask3D=None, exitOnFail=False)[source]

angWidth is distance from angCen, so actually half-width

do not yet deal with wrap-around (eg, reader that spans 2*pi)

hexrd.xrd.xrdutil.grainSpotsFromStack(g, reader, detectorGeom, angWidth, threshold, **kwargs)[source]

wrapper around spotFromStack; takes a grain and returns a dictionary of spots for the grain, with keys (hklID, iThisHKL)

angWidth is for orientation spread; for 2-theta, g.planeData 2-theta ranges are used

can specify hklIDs to look for just a subset of spots

set distInAng=False if want the spots to have to contain the predicted angles, otherwise, the closest spots in the bounding boxes will be returned

hexrd.xrd.xrdutil.spotFromStack(reader, detectorGeom, tThMM, angWidth, angCen, threshold, fullBackground=False, asFrame=False, exitOnFail=True, distInAng=False, debug=True)[source]

if asFrame, then omegas come out as frame indices; note that angCen should still be specified as omega, not a frame index

hexrd.xrd.xrdutil.collapse(vAll, eta, ome, nOme=None, nEta=None, weightedList=, []averagedList=, []auxList=, []debug=False)[source]

Returns a sparse matrix, with zeros where no intensity falls;

pass nEta and nOme to control the number of eta and omega bins, otherwise they are determined automatically, with the omega binning assuming that omegas fall on frames at regular intervals with no gaps

for each entry in weightedList, also returns that data collapsed and weighted by vAll; similarly for averagedList

hexrd.xrd.xrdutil.displaySparse(a, vmin=None, vmax=None, cmap=None, fmt=None, markersize=3, colorUnder=None, ijNZ=None, **kwargs)[source]
hexrd.xrd.xrdutil.displayEtaOme(eta, ome, vAll, nEta=None, nOme=None, **kwargs)[source]
hexrd.xrd.xrdutil.getLorenz(detectorGeom, *args)[source]
hexrd.xrd.xrdutil.getEtaResolution(detectorGeom, tTh)[source]

angular resolution along eta

hexrd.xrd.xrdutil.getTThResolution(detectorGeom, tTh)[source]
hexrd.xrd.xrdutil.drEtaOme(angCen, dEta, dOme)[source]

compute true angular changes and dA corresponding to steps in eta and omega

hexrd.xrd.xrdutil.omeEtaGridToDA(tThNominal, etaEdges, omeEdges)[source]

get grid patch areas, in the sense of solid angle (pole figure) coverage;

hexrd.xrd.xrdutil.bboxIntersect3D(b1, b2)[source]

0-tolerance bounding box intersection in 3d

hexrd.xrd.xrdutil.pfigFromSpots(spots, iHKL, phaseID=None, nOme=None, nEta=None, tThTol=None, etaExcl=0.1, plot=False, plotPrefix=None, debug=False)[source]

probably want to have collected spots without discarding those at boundaries (discardAtBounds=False)

depending on the context, may need to have done something like iHKL = hklIDs.index(hklID)

if nEta is negative, it is treated as the target lumping of pixels

etaExcl is in radians – etas within this range of +-pi/2 degrees are left out; can set to None to turn this behavior off

can use tThTol to tighten down the two-theta tolerance

hexrd.xrd.xrdutil.mapAngCen(ang, angCen)[source]

map angle ang into equivalent value that is closest to angCen

hexrd.xrd.xrdutil.makeSynthFrames(spotParamsList, detectorGeom, omegas, intensityFunc=<hexrd.xrd.spotfinder.IntensityFuncGauss3D object at 0x7fb486d26d10>, asSparse=None, output=None, cutoffMult=4.0, debug=1)[source]

intensityFunc is an instance of a class that works as an intensity fuction.

spotParamsList should be a list with each entry being a list of arguments appropriate to the intensityFunc.constructParams function. For intensityFunc=spotfinder.IntensityFuncGauss3D(), each spotParamsList entry should be (center, fwhm, A), with center being the 3D spot center in angular coordinates (radians), fwhm being the (2-theta, eta, omega) widths in 3D, and A being an intensity scaling.

If output is specified as a string, then the frames with the given prefix are dumped to files instead of being accumulated in memory. If output is callable then frames are passed to output().

If asSparse is true then sparse matrices are used to reduce memory footprint. The asSparse option is currently not coded for the case of output having been specied.

cutoffMult is the multiplier on the FWHM to determine the angular cutoff range for evaluating intensity for each spot.

hexrd.xrd.xrdutil.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

hexrd.xrd.xrdutil.tVec_d_from_old_parfile(old_par, detOrigin)[source]
hexrd.xrd.xrdutil.objFun_tVec_d(tvd_xy, rMat_d, beamXYD, detOrigin, bHat_l)[source]
hexrd.xrd.xrdutil.beamXYD_from_tVec_d(rMat_d, tVec_d, bVec_ref, detOrigin)[source]
hexrd.xrd.xrdutil.write_old_parfile(filename, results)[source]
simulateOmeEtaMaps(omeEdges, etaEdges, planeData, expMaps, chi=0.0, etaTol=None, omeTol=None, etaRanges=None, omeRanges=None, bVec=array([[-0.],
[-0.],
[-1.]]), eVec=array([[ 1.],
[ 0.],
[ 0.]]), vInv=array([[ 1.],
[ 1.],
[ 1.],
[ 0.],
[ 0.],
[ 0.]]))

all angular info is entered in degrees

quats are (4, n)

...might want to creat module-level angluar unit flag ...might want to allow resvers delta omega

hexrd.xrd.xrdutil.simulateGVecs(pd, detector_params, grain_params, ome_range=[(-3.141592653589793, 3.141592653589793)], ome_period=(-3.141592653589793, 3.141592653589793), eta_range=[(-3.141592653589793, 3.141592653589793)], panel_dims=[(-204.8, -204.8), (204.8, 204.8)], pixel_pitch=(0.2, 0.2), distortion=(<function dummy at 0x7fb4870bf398>, []))[source]

simulate the monochormatic scattering for a specified

  • space group
  • wavelength
  • orientation
  • strain
  • position
  • detector parameters
  • oscillation axis tilt (chi)

subject to

  • omega (oscillation) ranges (list of (min, max) tuples)
  • eta (azimuth) ranges

pd................a hexrd.xrd.crystallography.PlaneData instance detector_params...a (10,) ndarray containing the tilt angles (3), translation (3),

chi (1), and sample frame translation (3) parameters
grain_params......a (12,) ndarray containing the exponential map (3),
translation (3), and inverse stretch tensor compnents in Mandel-Voigt notation (6).
  • currently only one panel is supported, but this will likely change very soon
hexrd.xrd.xrdutil.angularPixelSize(xy_det, xy_pixelPitch, rMat_d, rMat_s, tVec_d, tVec_s, tVec_c, distortion=(<function dummy at 0x7fb4870bf398>, []))[source]
  • choices to beam vector and eta vector specs have been supressed
  • assumes xy_det in UNWARPED configuration
hexrd.xrd.xrdutil.pullSpots(pd, detector_params, grain_params, reader, ome_period=(-3.141592653589793, 3.141592653589793), eta_range=[(-3.141592653589793, 3.141592653589793)], panel_dims=[(-204.8, -204.8), (204.8, 204.8)], panel_buff=[20, 20], pixel_pitch=(0.2, 0.2), distortion=(<function dummy at 0x7fb4870bf398>, []), tth_tol=0.15, eta_tol=1.0, ome_tol=1.0, npdiv=1, threshold=10, doClipping=False, filename=None, save_spot_list=False, use_closest=False)[source]
hexrd.xrd.xrdutil.validateQVecAngles(*args, **kwargs)[source]