Exemplo n.º 1
0
    def test_Lorentzian(self):
        truevals = [4.2,0.3,10000,1,0,150]  
        x,y = createpeak(truevals)
 
        yfit,result = quick_fit_peak(x,y)
        
        saveplot(x,y,yfit,'lorentzian.png')
   
        self.assertAlmostEqual(result['centre'].nominal_value,truevals[0],2)
        self.assertAlmostEqual(result['width'].nominal_value, truevals[1],2)
        self.assertAlmostEqual(result['area'].nominal_value,truevals[2],0)
        self.assertAlmostEqual(result['eta'].nominal_value,truevals[3],2)
        self.assertEqual(result['asymmetry'].nominal_value,truevals[4])
Exemplo n.º 2
0
    def test_PseudovoigtAsymmetric(self):
        truevals = [4.2,0.75,10000,0.1,0.8,150]  
        x,y = createpeak(truevals)

        yfit,result = quick_fit_peak(x,y,shape='apv')

        saveplot(x,y,yfit,'aysymmetric_pseudovoigt.png')
            
        self.assertAlmostEqual(result['centre'].nominal_value,truevals[0],2)
        self.assertAlmostEqual(result['width'].nominal_value, truevals[1],2)
        self.assertAlmostEqual(result['area'].nominal_value,truevals[2],0)
        self.assertAlmostEqual(result['eta'].nominal_value,truevals[3],3)
        self.assertAlmostEqual(result['asymmetry'].nominal_value,truevals[4],4)
Exemplo n.º 3
0
    def test_Gaussian_unumpy(self):
        truevals = [4.2,0.75,10000,0,0,150]  
        x,y = createpeak(truevals)

        u = np.sqrt(y)
        y = unumpy.uarray((y,u))
        
        yfit,result = quick_fit_peak(x,y)
        
        saveplot(x,unumpy.nominal_values(y),yfit,'ugaussian.png')

        self.assertAlmostEqual(result['centre'].nominal_value,truevals[0],2)
        self.assertAlmostEqual(result['width'].nominal_value, truevals[1],2)
        self.assertAlmostEqual(result['area'].nominal_value,truevals[2],0)
        self.assertAlmostEqual(result['eta'].nominal_value,truevals[3],3)
        self.assertEqual(result['asymmetry'].nominal_value,truevals[4])
Exemplo n.º 4
0
import numpy as np
import matplotlib.pyplot as plt

from edxrd.peakfitting import Peak,quick_fit_peak,fpeak #only needed for making fake data
from edxrd.peaksearch import estimate_peak

truevals = [4.2,0.2,500.,0.25,0.0,150.]
x = np.linspace(2,6,100)
peak = Peak(*truevals)
y = peak.profile(x,add_background=True)
y += np.sqrt(y)*(np.random.rand(y.size)-0.5)*0.95

if 0:
    f,ax = plt.subplots(1,1,figsize=(7,4))
    fit, res = quick_fit_peak(x,y)
    ax.plot(x,y,'b.')
    ax.plot(x,fit,'r-',lw=1)
    f.savefig('quick_fit_example.png',dpi=100)

if 0:   
    f,axs = plt.subplots(2,1,figsize=(7,7))
    fit, res = quick_fit_peak(x,y,shape='pv',ymin_on_ymax=0.001)
    axs[0].plot(x,y,'b.')
    axs[0].plot(x,fit,'r-',lw=1)
    axs[0].text(0.05, 0.8, 'ymin_on_ymax = 0.001',transform=axs[0].transAxes,fontsize=15)
    fit, res = quick_fit_peak(x,y,shape='pv',ymin_on_ymax=0.03)
    axs[1].plot(x,y,'b.')
    axs[1].plot(x,fit,'r-',lw=1)
    axs[1].text(0.05, 0.8, 'ymin_on_ymax = 0.03',transform=axs[1].transAxes,fontsize=15)