예제 #1
0
def from_unitcell(x,y,unit_cell,space_group,qmin,qmax,**kwargs):
    '''Creates a series of estimated a peaks from the unit cell
    
    This will only work reliably if the spectrum is composed of fairly well 
    separated peaks and is well calibrated. The peaks are provided with hkl
    attributes and a new name
    
    Parameters
    ==========
    x : array_like
        independent variable of spectrum e.g. q or energy
    y : array_like
        dependent variable of spectrum e.g. counts
    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 
    qmin : float
        minimum q value for the first reflection
    qmax : float
        maximum q value for the last reflection

    Returns
    =======
    peaks : list, Peak
        A list of peaks with approximately correct parameters

    Other Parameters
    ================
    kwargs : dict
        additional keywords passed into estimate_peak   
    '''    
    qs,hkls = unitcell.get_unique_peaks(unit_cell,space_group,qmin,qmax)
    return from_hkls(x,y,unit_cell,hkls,**kwargs)
예제 #2
0
 def test_calibration_fakedata(self):
     c0,c1 = 2,0.0019
     b = unitcell.get_unique_peaks([4.04,4.04,4.04,90,90,90],'fm-3m',0,6)[0]
     a = -c0 + b*(1/c1) 
     a = np.hstack((a[0:1],[1500],a[1:2],[1900],a[2:]))
     
     cal = match_fit(a,[4.04,4.04,4.04,90,90,90],'fm-3m',qmax=7)
     cal = cal.values
     self.assertAlmostEqual(cal[0],0,3)
     self.assertAlmostEqual(cal[1],c1,4)
     self.assertAlmostEqual(cal[2],c1*c0,4)  
예제 #3
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
예제 #4
0
    def test_matchbest(self):
        b = unitcell.get_unique_peaks([4.04,4.04,4.04,90,90,90],'fm-3m',0,6)[0]
        a = 1 + b*(1/0.0019) 

        a = np.hstack((a[0:1],[1500],a[1:2],[1900],a[2:]))
        cal = match(a,b)

        ma = cal.candidates.matched.tolist()
        self.assertAlmostEqual(ma[0],1418.769,3)
        self.assertAlmostEqual(ma[1],1638.099,3)
        self.assertAlmostEqual(ma[2],2316.207,3)
        self.assertAlmostEqual(ma[3],2715.821,3)
        self.assertAlmostEqual(ma[4],2836.538,3)
        
        mb = cal.known.matched.tolist()
        self.assertAlmostEqual(mb[0],2.694,3)
        self.assertAlmostEqual(mb[1],3.11,3)
        self.assertAlmostEqual(mb[2],4.399,3)
        self.assertAlmostEqual(mb[3],5.158,3)
        self.assertAlmostEqual(mb[4],5.388,3)