Module: xrd.spotfinder

12 Classes

class hexrd.xrd.spotfinder.IntensityFunc3D(*args, **kwargs)[source]

Bases: object

This is just a template for intensity distribution functions in 3D

__init__(*args, **kwargs)[source]
eval(xVec, x, y, z, w=None, vSub=None, vScale=None, diff=False, noBkg=False)[source]

if w is None: x, y, and z are 1D; if w has 1D weights: x, y, and z are 2D

if vSub is present, it is subtracted from results – useful for forming least-squares residuals; and vScale is used to scale the results if it is present

class hexrd.xrd.spotfinder.IntensityFuncGauss3D[source]

Bases: hexrd.xrd.spotfinder.IntensityFunc3D

8 parameters:
centers (3) FWHMs (3) scaling (1) background (1)
__init__()[source]
class hexrd.xrd.spotfinder.IntensityFuncGauss3DGenEll[source]

Bases: hexrd.xrd.spotfinder.IntensityFunc3D

generalization of IntensityFuncGauss3D to have principal axes generally aligned 11 parameters:

centers (3) diagonal “fwhm” (3) scaling (1) off-diagonal (3) background (1)
__init__()[source]
classmethod get2DFunc()[source]

if drop to 2D, also drop back to aligned ellipsoid

guessXVec(x, y, z, w=None, v=None, noBkg=False)[source]

guess is for aligned ellipsoid

class hexrd.xrd.spotfinder.IntensityFuncMulti3D(subFuncClass, nSubFuncs, minWidth=None)[source]

Bases: hexrd.xrd.spotfinder.IntensityFunc3D

combination of multiple overlapped functions

__init__(subFuncClass, nSubFuncs, minWidth=None)[source]
guessXVecPureNDImage(x, y, z, pxlCenterList, w=None, v=None, pxl=None, gaussFilterSigma=None, noBkg=False)[source]

for now, rely on specified centers; assumes that v can be made into integers without too much loss of precision

class hexrd.xrd.spotfinder.IntensityFunc2D(*args, **kwargs)[source]

Bases: object

This is just a template for intensity distribution functions in 2D; It could be unified with the 3D version, but that would potentially make the interface harder to understand

__init__(*args, **kwargs)[source]
eval(xVec, x, y, w=None, vSub=None, vScale=None, diff=False, noBkg=False)[source]

if w is None: x and y are 1D; if w has 1D weights: x and y are 2D

if vSub is present, it is subtracted from results – useful for forming least-squares residuals; and vScale is used to scale the results if it is present

class hexrd.xrd.spotfinder.IntensityFuncGauss2D[source]

Bases: hexrd.xrd.spotfinder.IntensityFunc2D

6 parameters:
centers (2) FWHMs (2) scaling (1) background (1)
__init__()[source]
class hexrd.xrd.spotfinder.IntensityFuncMulti2D(subFuncClass, nSubFuncs)[source]

Bases: hexrd.xrd.spotfinder.IntensityFunc2D

combination of multiple overlapped functions

__init__(subFuncClass, nSubFuncs)[source]
guessXVec(x, y, pxlCenterList, w=None, v=None, pxl=None, gaussFilterSigma=None, noBkg=False, minWidth=None, wtrshd=None)[source]

for now, rely on specified centers; assumes that v can be made into integers without too much loss of precision

class hexrd.xrd.spotfinder.UnfitableError(err, msg)[source]

Bases: exceptions.Exception

__init__(err, msg)[source]
class hexrd.xrd.spotfinder.FitFailedError(err, msg)[source]

Bases: exceptions.Exception

__init__(err, msg)[source]
class hexrd.xrd.spotfinder.Spot(key, delta_omega, data=None, omega=None, iFrame=None, detectorGeom=None)[source]

Bases: object

__init__(key, delta_omega, data=None, omega=None, iFrame=None, detectorGeom=None)[source]

key should be unique among all spots in the collection; can call with initial data or not

if have tuple from getDataMinimal call, should be able to init directly with that tuple

angCOM(useFit=True, detectorGeom=None, getUncertainties=False, iSubSpot=None)[source]

Get center-of-mass in twotheta, eta, omega coordinates. If useFit, then return value from function fit instead of simple estimate

Could look at detectorGeom to see if it has a pVec and do something more elaborate if detectorGeom is already set without a pVec, but that is probably asking for trouble

append(dataDict, omega, iFrame)[source]

dataDict should be like one of the entries in spotDataList coming back from spotFinderSingle

cleanFit()[source]

clean up data associated with having done fit()

static cullSpots(spots, tests)[source]

Apply a list of tests to spots and return a list with spots that fail culled

spots is a list of Spot instances; tests is a list of tests to be applied;

For convenience, some tests have been defined as static methods off of the Spot class. If a test is tests has a length, then the non-first entries are used as arguments.
display(cmap=None, relfigsize=(1, 1), vAll=None, markersize=2, xyoPointsList=[([], {})], **kwargs)[source]

vAll, if present, is used instead of self.vAll; useful for results from fitting

displayFlat(vAll=None, cmap=None, markersize=2, **kwargs)[source]

Flatten in Omega for display, no loss of x-y resolution

displayFrames(reader, nFramesPad=0, sumImg=<ufunc 'maximum'>, **kwargs)[source]

display the frame(s) from which a spot came

doMap

centralize this decision so that it does not change with the use of quadrature and the like

exceptionOnFit()[source]

return the exception if stored on fit; note that not all exceptions get stored

finalize(flatten=False, modifyDeltaOmega=False, cullDupl=True)[source]

Could potentially get rid of self.data once finalize is called, but leave it around just in case it is useful for subsequent operations. It might, for example, be needed if we go back and read more intensity data in the vicinity of the spot.

fit(funcType=None, quadr='auto', full_output=False, uncertainties=False, confidence_level=0.95, debug=None, detectorGeom=None, fout=<open file '<stdout>', mode 'w' at 0x7fb496fc5150>)[source]

fit a distribution to a spot;

may throw a UnfitableError Exception if it is not possible to fit the spot with the given function

if want to re-fit a spot, call the cleanFit method first

if just want to make sure an attempt was made to fit the spot, call fitWrap

fitWrap(*args, **kwargs)[source]

useful if just want to make sure an attempt was made to fit the spot; only lets exceptions through if the spot is suspect

flattenOmega(modifyDeltaOmega=False)[source]

flatten spot in Omega;

unless modifyDeltaOmega is set, do not change delta_omega, under the assumption that the spot is being flattened if it does not significantly spill across multiple omega frames

getDoMap()[source]

centralize this decision so that it does not change with the use of quadrature and the like

getFrames(reader=None)[source]

if have self.data, do not need reader

isMarked(marks)[source]

return true of spot has been marked as indicated; marks can be an integer or list; if marks is a list, returns true if any of marks are true

static loadSpots(f, minimal=True, closeLocal=True)[source]

load spots stored with storeSpots

note that is a detectorGoem was stored by storeSpots, then all spots loaded here will have it attached to them

merge(other)[source]

merge in other’s data

setupMulti(xyoList, wtrshd=None)[source]

for now, rely on candidate centers having been provided; probably want to do a fit

setupQuardFromFWHM(fwhm, fout=<open file '<stdout>', mode 'w' at 0x7fb496fc5150>)[source]

so far, written only for withOmega being True

static spotFromDataList(key, delta_omega, dataList)[source]

useful for merging data from spots that have already been finalized

static storeSpots(f, spotList, closeLocal=True)[source]

store spots to f, which can be a filename or something which behaves like a shelve instance

stores a somewhat minimal set of data

all spots must have the same detectorGeom

consider changing to something like: import cPickle as pickle s = open(f,’w’) pickle.dump(stuff, f) f.close()

xyoCOM(useFit=True, iSubSpot=None)[source]

Get center-of-mass in x, y, omega coordinates on the image stack. If useFit, then return value from function fit instead of simple estimate

class hexrd.xrd.spotfinder.Spots(planeData, data, detectorGeom, omegaMM, **kwargs)[source]

Bases: object

Meant for holding spot data in a form useful for indexing

__init__(planeData, data, detectorGeom, omegaMM, **kwargs)[source]

planeData : an instance or list (for multiple phases) of the PlaneData class data : can any of:

spots : list of Spot instances, all of which must have been finalized spotAngCoords : spot positions in angular coordinates None

detectorGeom : an instance of DetectorGeomGE or the like omegaMM : (min, max) of omega range, or list of such min/max tuples

checkClaim(index)[source]

careful: unlike claimSpots, does not check grain association

checkClaims(indices=None)[source]

careful: unlike claimSpots, does not check grain association; careful: indices should not be a boolean array

claimSpots(indices, newClaimedBy, checkOnly=False, asMaster=False)[source]

careful: indices should not be a boolean array;

returns bool of same length as indices, with True entries for indices that are in conflict; if checkOnly, then do not actaully claim the spots

cleanMulti()[source]

clean up spots for which split fitting was done, as they might need to change to single spots

static enslaveSpotData(d, dMaster)[source]

ends up, after potentially doing recursive calls, slaving master of d to master of dMaster

static findSpotsOmegaStack(reader, nFrames, threshold, minPx, discardAtBounds=True, keepWithinBBox=True, overlapPixelDistance=None, nframesLump=1, padOmega=True, padSpot=True, debug=False, pw=None, fout=None, sumImg=None)[source]

... if merge at bounds, would need to do that before culling based on size (*) spots from beginning would have already been finalized – can merge with them without trouble? (*) add comments here about what happens when reader.wrapsAround

This method does not necessarily need to hang off of the Spots class, but Spots is a convenient place to put it.

If nFrames == 0, read all frames.

if pass overlapPixelDistance, then overlap is determined based on centroid distances in pixel units; with overlapPixelDistance being set to the tolerance for overlap; probably most useful when omega steps are large

reader has been created by doing something like:
fileInfo = [(‘RUBY_4537.raw’, 2), (‘RUBY_4538.raw’, 2)] reader = detector.ReadGE(fileInfo, subtractDark=True)

if go to parallel processing, perhaps return first and last lables for doing merges

fitHasFailed(index, subSpotOnly=False)[source]

if subSpotOnly the only return true if it was a subspot that failed to fit

fitSpots(indices, *args, **kwargs)[source]

fit spots with given indices and update spotAngCoords; for indices is None, all spots are considered for fitting; indices may be a single integer instead of a list of spot indices

set claimsBased if want to base method on spots that have been claimed

fitSpotsMulti(indices, threshold, *args, **kwargs)[source]

like fitSpots, but consider splitting up spots with multiple peaks

getAngCoords(indices=None)[source]

... make returned thing unwritable even if it is a slice

getHKLSpots(hkl, phaseID=None, unclaimedOnly=False, disallowMasterWhenSplit=True)[source]

get boolean array that is True for spots associated with a given hkl (and optionally phase)

getIntegratedIntensity(index, **kwargs)[source]

wrapper that takes care of subspot details

getIterHKL(hkl, phaseID=None, unclaimedOnly=True, friedelOnly=False, iSpotLo=0, returnBothCoordTypes=False)[source]

Returns an iterator over a given set of spots

getIterPhase(phaseID=None, unclaimedOnly=True, friedelOnly=False, iSpotLo=0, returnBothCoordTypes=False)[source]

Returns an iterator over a given set of spots

getPixelIsInSpots(indices, xyo, pixelDist=0)[source]

find spots that are within pixelDist of containing a given pixel; indices may be a single integer, a list of spot indices, or a boolean array;

may want to use pixelDist of 1 or 2 to protect against dead pixels

getXYOCoords(indices)[source]

... make returned thing unwritable even if it is a slice

static mergeSpotsOmegaStack(spotsA, spotsB, readerA, readerB, keepWithinBBox=True, overlapPixelDistance=None, padOmega=True, logger=None)[source]

see findSpotsOmegaStack (documentation in header and in the body) for comments about padOmega and overlapPixelDistance

spotsB and readerB can be None if this is for wrap-around

A and B can be the same – as would be the case for omega wrapping all the way around

resetDetectorGeom(detectorGeom, doFits=False, fitArgs=, []fitKWArgs={})[source]

update detector geometry; also fits all spots; probably only want to call this for a single-grain data set or the like; updates angular and cartesian coordinates, but not 2-theta associations or other meta-data

class hexrd.xrd.spotfinder.SpotsIterator(spots, hkl, phaseID, unclaimedOnly, friedelOnly, iSpotLo, returnBothCoordTypes)[source]

iterator over a given set of spots in a Spots instance, note that the iterator ignores relations among split spots

__init__(spots, hkl, phaseID, unclaimedOnly, friedelOnly, iSpotLo, returnBothCoordTypes)[source]

18 Functions

hexrd.xrd.spotfinder.getBin(thisframe, threshold, padSpot)[source]
hexrd.xrd.spotfinder.dilateObj(obj, shape, nDilate=1)[source]
hexrd.xrd.spotfinder.emptyBox(obj, dtype)[source]
hexrd.xrd.spotfinder.getDtype(this)[source]
hexrd.xrd.spotfinder.copyBox(inpt, obj)[source]

deepcopy does not seem to do what we want with masked arrays

hexrd.xrd.spotfinder.getSpot(inpt, labels, objs, index, keepWithinBBox, padSpot, darkframe=None)[source]

labels is from ndimage.label; objs is from ndimage.find_objects

hexrd.xrd.spotfinder.getSpotFromPixels(inpt, xThese, yThese, index, keepWithinBBox, padSpot, darkframe=None)[source]

this is a bit of an oddball function, mostly for data uniformity of data structures;

hexrd.xrd.spotfinder.cullSpotUsingBin(spot, bin)[source]

remove data for pixels where bin is true; vbox does not change, just change the locations that are marked as belonging with the spot

hexrd.xrd.spotfinder.getValuesOnly(inpt, labels, objs, index)[source]

labels is from ndimage.label; objs is from ndimage.find_objects

hexrd.xrd.spotfinder.getIndices(inpt, labels, obj, index, mode='default', minlabel=0)[source]
hexrd.xrd.spotfinder.getImCOM(inpt, labels, objs, index, floor=None, getVSum=False)[source]

labels is from ndimage.label; objs is from ndimage.find_objects

set floor for a minimum intensity to use in intensity weighted COM

return sum of intensity as well if getVSum is True

hexrd.xrd.spotfinder.getObjSize(labels, objs, index)[source]

labels is from ndimage.label; objs is from ndimage.find_objects

hexrd.xrd.spotfinder.spotFinderSingle(thisframe, threshold, minPx, keepWithinBBox, padSpot, weightedCOM=True, pw=None, debug=False, darkframe=None)[source]

find spots in thisframe; threshold can be a scalar or defined over of same dimension as thisframe; minPx is the minimum number of pixels to be kept as a spot; weightedCOM is true to use thisframe data for weighting center-of-mass position; if pw is present, it is used for plotting (assumed to be plotwrap.PlotWrap instance)

hexrd.xrd.spotfinder.getWtrShd(inp, threshold, gaussFilterSigma=None, footPrint=None, fpi=5, numPeaks=None)[source]

fpi only used if footPrint is None

hexrd.xrd.spotfinder.doSpotThis(iSpot)[source]

meant for use with multiprocessing

hexrd.xrd.spotfinder.testSingle(fileInfo)[source]
hexrd.xrd.spotfinder.testSpotFinder(fileInfo, delta_omega, omega_low, howMuch=0.1)[source]
hexrd.xrd.spotfinder.main(argv=[])[source]