예제 #1
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)
예제 #2
0
    def test_Estimate(self):
        truevals = [4.2,0.5,10000,0.0,0.0,150]  
        x = np.linspace(2,6,50)
        y = fpeak(x,*truevals)
        p = estimate_peak(x,y)   
        p.shape = 'g'

        f,ax = plt.subplots(figsize=(7,7))
        ax.plot(x,y,'b+')
        ax.plot(x,p.profile(x)+p.background.nominal_value,'r',lw=1)
        f.savefig('estimate.png',dpi=200)
        
        self.assertAlmostEqual(p.centre.nominal_value,truevals[0],1)
        self.assertAlmostEqual(p.width.nominal_value, truevals[1],1)
        self.assertAlmostEqual(p.area.nominal_value,truevals[2],-2)
        self.assertEqual(p.eta.nominal_value,truevals[3])
        self.assertEqual(p.asymmetry.nominal_value,truevals[4])
        self.assertAlmostEqual(p.background,truevals[5],1)
예제 #3
0
파일: test.py 프로젝트: matthewjpeel/edxrd
    #y += np.sqrt(y)*(np.random.rand(x.size)-0.5)*0.0025  
    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()
예제 #4
0
        self.assertAlmostEquals(cens[4],3.7053,4)     
        self.assertAlmostEquals(cens[5],4.2773,4)
        

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']
예제 #5
0
    fit, res = quick_fit_peak(lx,y,shape='apv')
    ax5.plot(lx,y,'b.')
    ax5.plot(lx,fit,'r-',lw=1)
    
    for ax in axs:
        ax.set_ybound(0,2500)
        ax.set_xticks([3.6,4.2,4.8])
        ax.set_yticks([])
        ax.vlines(4.2,0,2500,lw=1,linestyle='--')
        
    f.savefig('peak_shapes.png',dpi=100)
  
if 0:
    y = fpeak(x,4.0,0.6,1200)+100
    y += np.sqrt(y)*(np.random.rand(y.size)-0.5)*5
    mypeak = estimate_peak(x,y)  

    f,ax = plt.subplots(1,1,figsize=(7,4))
    ax.plot(x,y,'b.')
    ax.plot(x,mypeak.profile(x,True),'r-',lw=1)
    f.savefig('estimate_peak.png',dpi=100)

if 0:
    y = fpeak(x,3.0,0.6,800)
    y += fpeak(x,5.0,0.6,1200)+100
    y += np.sqrt(y)*(np.random.rand(y.size)-0.5)*5
     
    f,axs = plt.subplots(1,2,figsize=(7,4))
    ax1,ax2 =axs

    mypeak = estimate_peak(x,y)