示例#1
0
    def test_calibrate_no_search(self):
        #from uncertainties import unumpy 
        
        x,y = self.edxdata['LaB6']
       
        searcher = WaveletPeakSearcher(1.2,25,1.15,critical_sep=2,noiselevel=20,min_ridge_length=9,
                                       min_child_length=8,ridge_skip=0)
    
        searcher.set_data(x,y)
        pks = searcher.identify_peaks()

        cf = ChunkFitter(x,pks,shape='g')
        cf.refine(y)

        candidates = np.array([peak.centre for peak in cf.peaks])
         
        #uncertainty = unumpy.std_devs(candidates)
        #uncertainty[uncertainty==0] = 1
        #candidates = unumpy.nominal_values(candidates)

        unit_cell = [4.15695,4.15695,4.15695,90,90,90]
        space_group = 'pm-3m'          
        c = match_fit(candidates,unit_cell,space_group)
        
        self.assertLess(abs(c.values[0]),1e-9)
        self.assertAlmostEqual(c.values[1], 0.001942,5)
        self.assertLess(abs(c.values[2]),0.005)
示例#2
0
 def test_ChunkFitter(self):
     peaknames = ['LaB6_110', 'LaB6_111', 'LaB6_200', 'LaB6_210', 
                  'LaB6_211', 'LaB6_220', 'LaB6_300', 'LaB6_310', 
                  'LaB6_311', 'LaB6_222', 'LaB6_320', 'LaB6_321', 
                  'LaB6_400', 'LaB6_410', 'LaB6_411', 'LaB6_331', 
                  'LaB6_420', 'LaB6_421']
     parnames = ['centre','width','area','eta','asymmetry','background']
     
     pks = from_unitcell(self.x,self.y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,7,name='LaB6')
     fitter = ChunkFitter(self.x,pks)
     fitter.refine(self.y)
     result = fitter.lastresult        
     yfit = fitter.lastfit
     
     saveplot(self.x,self.y,yfit,'chunkfitter.png')        
     
     self.assertListEqual(peaknames,[p.name for p in pks])
     self.assertItemsEqual(result['LaB6_110'].keys(),parnames)
     self.assertTupleEqual(yfit.shape,(4096,))
     cens = [p.centre.nominal_value for p in pks]
     self.assertEquals(len(cens),18)
     self.assertAlmostEquals(cens[0],2.1391,4)
     self.assertAlmostEquals(cens[2],3.0249,4)
     self.assertAlmostEquals(cens[4],3.7053,4)
     self.assertAlmostEquals(cens[8],5.0154,4)
     self.assertAlmostEquals(cens[12],6.0520,4)
     self.assertAlmostEquals(cens[16],6.7653,4)
示例#3
0
    def test_ChunkFitterWaveletSearch(self):
        wps2 = WaveletPeakSearcher(1.5,30,1.15,critical_sep=1,noiselevel=10,min_ridge_length=9,
                                   min_child_length=8,ridge_skip=0)
        wps2.set_data(self.x,self.y)
        pks = wps2.identify_peaks()      

        fitter = ChunkFitter(self.x,pks)
        fitter.refine(self.y)
示例#4
0
    def test_WeirdPeakAdding(self):
        l,h = self.x.searchsorted([2,2.5])
        pk1 = estimate_peak(self.x[l:h],self.y[l:h],name='peak1')
        
        l,h = self.x.searchsorted([2.5,2.75])
        pk2 = estimate_peak(self.x[l:h],self.y[l:h])

        l,h = self.x.searchsorted([2.8,3.2])
        pk3 = estimate_peak(self.x[l:h],self.y[l:h])
        
        pks = [pk1,pk2,pk3]        

        self.assertRaises(FitterError,ChunkFitter,self.x,pks)

        pks[2] = estimate_peak(self.x[l:h],self.y[l:h],name='peak3')
        

        fitter = ChunkFitter(self.x,pks)
        fitter.refine(self.y)

        cens = [p.centre.nominal_value for p in pks]
        cens2 = [v['centre'].nominal_value for v in fitter.lastresult.itervalues()]
        self.assertListEqual(cens,cens2)