ImageD11.closest
index
/sware/exp/fable/standalone/redhate4-a64/lib/python2.5/site-packages/ImageD11/closest.so

/* *******************************************************************
* closest.c  Two useful functions for indexing grains 
*
* 1. From python: closest(cosines_allowed, cosine_measured)
*    Take 1 peak with hkl's assigned, compute the cosines to
*    another powder ring (angles between this peak and peaks in
*    that ring). This extension finds the best peak in the
*    other ring to pair up with.
*
*    More generally closest(array, values) finds the closest
*    item in values to one of the values in array.  Returns the
*    difference and the index of the closest thing it finds.
*
*    Both arguments should be one dimensional Numeric arrays
*    of type Numeric.Float
*
* 2. From python: score(ubi, gv, tol) where ubi is an orientation
*    matrix and gv are an array of g-vectors. Returns the number
*    of g-vectors which have integer hkl peaks within tolerance
*    tol. Uses the conv_double_to_int_fast function in here for 
*    factor of !EIGHT! speed increase compared to rounding in 
*    C. In fact this gives the nearest even integer, instead
*    of the nearest integer, but we don't care, as a peak having
*    hkl of 0.5 is nowhere near being indexed anyway.
*
*    Returns and integer - number of peaks indexed
*    UBI is a 3x3 Numeric.Float array (figure out the transposing yourself)
*    GV is a nx3 Numeric.Float array, and you should try to make the 3 
*       be the fast index for best performance
*       
* 3. From python: same as score, I hope, but ubi is overwritten
*    with refined matrix following paciorek algorithm which is 
*    in indexing.py
*    

* 4. score_and_assign( ubi, gv, tol, drlv, labels, (int) label)
*    as for score, but assignments are only made if drlv is lower than
*    the previous. Fills in label with the new label
*
* 5. refine_assigned( ubi, gv, labels, label, weight) 
*    Use only the peaks where label matches labels in refinement 
*    ...following again the Paciorek algorithm 
*
* 6. put_incr( data, indices, values)
*    pretty much as numeric.put but as increments
*
* ****************************************************************** */

 
Functions
       
closest(...)
int,float closest(x,v)
Find element in x closest to one in v
x,v 1D flat Float arrays
put_incr(...)
None = put_incr( data, ind, vals )
does the loop 
for i, v in ind, vals:
    data[ ind[i] ] += vals[i]
refine_assigned(...)
int, float refine_assigned(ubi, gv, labels, label, sigma)
refines ubi to match gv where labels==label
sigma is a soft cutoff on tolerance (drlv)
returns npks, <drlv2>
score(...)
int score(ubi,gv,tol)
Find number of gv which are integer h within tol
score_and_assign(...)
int score_and_assign(ubi, gv, tol, drlv2, labels, label)
Find number of gv which have lower drlv2 than stored values in drlv2.
Label them as label in labels array
score_and_refine(...)
int score_and_refine(ubi,gv,tol)
Find number of gv which are integer h within tol and overwrite UB with refined