Example #1
0
 def test_PeakFitterUncertainties(self):
     
     y = unumpy.uarray((self.y,np.sqrt(self.y)))        
     peaknames = ['LaB6_110', 'LaB6_111', 'LaB6_200', 'LaB6_210', 'LaB6_211']        
     
     pks = from_unitcell(self.x,y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,4,name='LaB6')
     fitter = PeakFitter(self.x,pks)   
     fitter.refine(y)  
     
     saveplot(self.x,unumpy.nominal_values(y),fitter.lastfit,'peakfitter_uncertainties.png')
     
     self.assertListEqual(peaknames,[p.name for p in pks])
     cens = [p.centre.nominal_value for p in pks]
     self.assertEquals(len(cens),5)
     self.assertAlmostEquals(cens[0],2.1391,4)
     self.assertAlmostEquals(cens[1],2.6195,4)
     self.assertAlmostEquals(cens[2],3.0249,4)
Example #2
0
 def test_PeakFitter(self):
     peaknames = ['LaB6_110', 'LaB6_111', 'LaB6_200', 'LaB6_210', 'LaB6_211']
     
     pks = from_unitcell(self.x,self.y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,4,name='LaB6')
     fitter = PeakFitter(self.x,pks)   
     fitter.refine(self.y)
     
     result = fitter.lastresult
     saveplot(self.x,self.y,fitter.lastfit,'peakfitter.png')        
     
     cens = [v['centre'].nominal_value for v in result.itervalues()]
     censu = [v['centre'].std_dev() for v in result.itervalues()]
     
     self.assertListEqual([p.centre.nominal_value for p in pks],cens)
     self.assertListEqual([p.centre.std_dev() for p in pks],censu)
     self.assertListEqual(peaknames,[p.name for p in pks])
     self.assertEquals(len(cens),5)
     self.assertAlmostEquals(cens[0],2.1391,4)
     self.assertAlmostEquals(cens[1],2.6195,4)
     self.assertAlmostEquals(cens[2],3.0249,4)
Example #3
0
    return x,y
    
    
#x,y = createpeak([4,0.7,2000,0,0,100])
#peak = estimate_peak(x,y,shape='g')
#print peak.height
#print y.max()-100
#
#x,y = createpeak([4,0.7,2000,0.25,0,100])
#peak = estimate_peak(x,y,shape='pv')
#print peak.height
#print y.max()-100

x,y = createpeak([4,0.17,2000,0,0,0.1])
peak = estimate_peak(x,y,shape='g')
pf = PeakFitter(x,[peak])
pf.refine(y)
print peak.height
#print peak.area
peak.height = 11052
#print peak.area
x,y = createpeak([4,0.17,peak.area,0,0,0.1])
peak = estimate_peak(x,y,shape='g')
print peak.height
#x,y = createpeak([4,0.17,3000,0.5,0,0])


#plt.plot(x,y,'b.')
#plt.plot(x,peak.profile(x,True),'r-')
#plt.show()
Example #4
0
    def test_PeakFitterAdd(self):

        peaknames = ['LaB6_110', 'LaB6_111', 'LaB6_200', 'LaB6_210', 'LaB6_211']        
        
        pks = from_unitcell(self.x,self.y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,4,name='LaB6')
        fitter = PeakFitter(self.x,[])   
        for p in pks:
            fitter.add(p)
        fitter.refine(self.y)
        
        self.assertListEqual(peaknames,[p.name for p in pks])
        cens = [p.centre.nominal_value for p in pks]
        self.assertEquals(len(cens),5)
        self.assertAlmostEquals(cens[0],2.1391,4)
        self.assertAlmostEquals(cens[1],2.6195,4)
        self.assertAlmostEquals(cens[2],3.0249,4)

        pks = from_unitcell(self.x,self.y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,4,name='LaB6')
        fitter = PeakFitter(self.x,[])   
        fitter.add_many(pks)
        fitter.refine(self.y)

        self.assertListEqual(peaknames,[p.name for p in pks])
        cens = [p.centre.nominal_value for p in pks]
        self.assertEquals(len(cens),5)
        self.assertAlmostEquals(cens[0],2.1391,4)
        self.assertAlmostEquals(cens[1],2.6195,4)
        self.assertAlmostEquals(cens[2],3.0249,4)

        pks = from_unitcell(self.x,self.y,[4.15695,4.15695,4.15695,90,90,90],'pm-3m',2,4,name='LaB6')
        fitter = PeakFitter(self.x,pks[0:2])   
        for p in pks[2:]:
            fitter.add(p)
        fitter.refine(self.y)

        self.assertListEqual(peaknames,[p.name for p in pks])
        cens = [p.centre.nominal_value for p in pks]
        self.assertEquals(len(cens),5)
        self.assertAlmostEquals(cens[0],2.1391,4)
        self.assertAlmostEquals(cens[1],2.6195,4)
        self.assertAlmostEquals(cens[2],3.0249,4)
Example #5
0
        

if __name__ == '__main__':
#    loader = unittest.TestLoader()
#    loader.loadTestsFromTestCase(TestBasicFunctions)
#    loader.loadTestsFromTestCase(TestSinglePeak)
#    loader.loadTestsFromTestCase(TestBatchFitting)
#
#    unittest.main(verbosity=2)

    truevals = [4.2,0.75,10000,0,0,150]  
    x,y = createpeak(truevals)
    
    peak = estimate_peak(x,y)
    
    pf = PeakFitter(x,[peak])
    pf.backup()
    print 'backed up'
    print id(peak._pset)
    print id(peak._pset_bck)
    print peak._pset['centre']
    print peak._pset_bck['centre']
    
    print 'refined'
    pf.refine(y)    
    print id(peak._pset)
    print id(peak._pset_bck)
    print peak._pset['centre']
    print peak._pset_bck['centre']
    
    print 'restored'