def create(x,strains,phis,material): qs = material.get_peaks(x.min(),x.max())[0] for i,s in enumerate(strains): y = np.zeros(x.shape) e1,e2,e12 = s #print e1,e2,e12 for i in range(len(phis)): sqs = qs - qs*(e1*np.cos(phis[i])**2 + e2*np.sin(phis[i])**2 + e12*np.sin(2*phis[i])) for q in sqs: y[i,:] += fpeak(x[i,:],q, 0.013+q*0.001,rand(11500,12500)/q**3,0) y[i,:] += fpeak(x[i,:],1.3,0.5,200,0,2) y[i,:] += fpeak(x[i,:],2.8,2,1500,0,-0.5) y[i,:] += fpeak(x[i,:],4.8,4,80,0,0) y[i,:] += rand(-20,20,y[i,:].size) yield y,{'x':i}
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)
def createpeak(truevals): x = np.linspace(2,6,800) y = fpeak(x,*truevals) #y += np.sqrt(y)*(np.random.rand(x.size)-0.5)*0.0025 return x,y
x = np.arange(4000) y = np.zeros_like(x) vals = [(1000,15.3,1200,0.25), (1300,15.5,12000,0.25), (1700,15.8,22000,0.25), (1750,16.3,32000,0.25), (1800,17.3,22000,0.25), (2300,18.3,11000,0.25), (2600,70.3,8000,0.25), (3200,22.3,6000,0.25), (3700,25.3,4000,0.25), ] for v in vals: y += fpeak(x,*v) back = np.poly1d((-1e-12,3e-9,-1e-7,0.01,100))(x) back += fpeak(x,1700,800,100000) y+=back ax1.plot(x,back,'k--',lw=1) #ax2.plot(x,back,'k--',lw=1) y+=np.random.uniform(-10,10,y.size) reduction=1 xb = x[::reduction] ax1.plot(x,y,'b',lw=1) #line1, = ax1.plot(xb,np.zeros_like(xb),'r.',markersize=2) #ax2.plot(x,y,'b',lw=1)
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) f.savefig('effect_of_ymin_on_ymax.png',dpi=100) if 0: lx = np.linspace(3.4,5.,100) f,axs = plt.subplots(1,5,figsize=(7,4)) ax1,ax2,ax3,ax4,ax5 = axs truevals[3] = 0 y = fpeak(lx,*truevals) fit, res = quick_fit_peak(lx,y,shape='g') ax1.plot(lx,y,'b.') ax1.plot(lx,fit,'r-',lw=1) truevals[3] = 1 y = fpeak(lx,*truevals) fit, res = quick_fit_peak(lx,y,shape='l') ax2.plot(lx,y,'b.') ax2.plot(lx,fit,'r-',lw=1) truevals[3] = 0.5 y = fpeak(lx,*truevals) fit, res = quick_fit_peak(lx,y,shape='pv') ax3.plot(lx,y,'b.') ax3.plot(lx,fit,'r-',lw=1)