def test_match(self):
     a = np.array([0.0,     0.19,0.41,0.62,0.65,0.78,1.0])
     b = np.array([0.0,0.10,0.21,0.39,0.61,     0.79,1.0])
     ca,cb = find_neighbours(a,b)
     ab = zip(*[a[ca],b[cb]])
     self.assertFalse(ca[4])
     self.assertFalse(cb[1])
     self.assertListEqual(ab,[(0.0,0.0),(0.19,0.21),(0.41,0.39),(0.62,0.61),
                           (0.78,0.79),(1.0,1.0)])
Exemple #2
0
def identify(peaks,unit_cell,space_group,name='phase',qmax=10):
    '''Finds abd labels peaks that correspond to the provided parameters
    
    This will only work if the spectrum is well calibrated. The peaks 
    are provided with hkl attributes and a new name
    
    Parameters
    ==========
    peaks : sequence
        any sequence of Peak instances
    unit_cell : list of floats
        unit cell of the material in form [a,b,c,alpha,beta,gamma]
    space_group : str or int
        Hermann–Mauguin notation of the space group 
    name : string
        new name to give peaks that are match
    qmax : float
        maximum q value for the last reflection

    Returns
    =======
    subset : list, Peak
        A list of those peaks that matched the unit cell
    '''
    from edxrd import calibration
    from edxrd.tools import unitcell
    
    cens = np.asarray([peak.centre.nominal_value for peak in peaks])
    known,hkls = unitcell.get_unique_peaks(unit_cell,space_group,0,qmax)
    known = np.asarray(known)
    cancond,nwncond = calibration.find_neighbours(cens,known)
    #known = known[nwncond]
    #hkls = hkls[nwncond]
    #matched = calibration.match(cens,known)
    #peaks = [peak for i,peak in enumerate(peaks) if cancond[i] == True]
    subset=[]
    j=0
    for i,peak in enumerate(peaks):
        if cancond[i] == True:
            peak.name = name+'_'+''.join([str(int(n)) for n in hkls[j]])
            j+=1
            subset.append(peak)

    return subset