def check_curfit_against_dierckx_smth(self): x,y = curfit_test['x'],curfit_test['y'] k,s = curfit_test_smth['k'],curfit_test_smth['s'] iopt = curfit_test_smth['iopt'] for i in range(len(k)): tck = splrep(x,y,k=k[i],task=iopt[i],s=s[i]) out = splrep(x,y,k=k[i],task=iopt[i],s=s[i],full_output=1) tck,fp=out[0],out[1] sp = splev(x,tck) assert_almost_equal(fp, curfit_test_smth['fp'][i], decimal=2) assert_array_almost_equal(around(tck[0],1), curfit_test_smth['t'][i]) assert_array_almost_equal(around(tck[1],4), curfit_test_smth['c'][i], decimal=3) assert_array_almost_equal(around(sp,1), curfit_test_smth['sp'][i])
def check_sproot(self): a=0 b=15 N=20 x=a+(b-a)*arange(N+1,dtype=float)/float(N) v=f1(x) k=3 tck = splrep(x,v,k=k,s=0) ex = array([0.0, pi, 2.0*pi, 3.0*pi, 4.0*pi]) assert_array_almost_equal(sproot(tck),ex, decimal=3)
def check_splder(self): N = 50 a,b = 0,2*pi dx = 0.2*pi k = range(3,6) x=a+(b-a)*arange(N+1,dtype=float)/float(N) v=f1(x) for j in range(len(k)): tck = splrep(x,v,k=k[j],s=0) dr = spalde(dx,tck) d2 = splev(dx,tck,der=1) assert_almost_equal(1, dr[1]/f1(dx,1.0), decimal=2)
def check_percur_against_dierckx(self): x,y = percur_test['x'], percur_test['y'] k,s = percur_test['k'], percur_test['s'] iopt, res = percur_test['iopt'], percur_test['res'] err = percur_test['err'] coef, knots = percur_test['coef'], percur_test['knots'] sp = percur_test['sp'] for i in range(len(k)): if iopt[i] != -1: tck,fp,ier,msg = splrep(x,y,k=k[i],task=iopt[i],s=s[i], per=True,full_output=True) else: tck,fp,ier,msg = splrep(x,y,t=knots[i],k=k[i],task=iopt[i], per=True,full_output=True) tt,cc,kk = tck tt,cc = asarray(tt), asarray(cc) assert_almost_equal(ier,err[i]) assert_almost_equal(fp,res[i],decimal=1) assert_array_almost_equal(tt,knots[i], decimal=3) assert_array_almost_equal(cc,coef[i], decimal=3) yy = asarray(splev(x,tck)) assert_array_almost_equal(yy,sp[i], decimal=3)
def check_curfit_against_dierckx_lsq(self): """ Test against results obtined from the pure fortran routines. Here we check simple spline creation and evaluation. """ x,y = curfit_test['x'],curfit_test['y'] k = curfit_test_lsq['k'] for i in range(len(k)): t = curfit_test_lsq['t'][i] out = splrep(x,y,t=t,k=k[i],full_output=1) tck,fp=out[0],out[1] sp = splev(x,tck) assert_almost_equal(fp, curfit_test_lsq['fp'][i], decimal=2) assert_array_almost_equal(around(tck[1],4), curfit_test_lsq['c'][i], decimal=3) assert_array_almost_equal(around(sp,1), curfit_test_lsq['sp'][i])
def check_parcur(self): f=f1; per=0; s=0; a=0; b=2*pi; N=[20,50] ia=0; ib=2*pi; dx=0.2*pi xb,xe=a,b for i in range(len(N)): x=a+(b-a)*arange(N[i]+1,dtype=float)/float(N[i]) x1=a+(b-a)*arange(1,N[i],dtype=float)/float(N[i]-1) # mid points v,v1=f(x),f(x1) for k in range(1,6): tckp,u=splprep([x,v],s=s,per=per,k=k) tck=splrep(x,v,s=s,per=per,k=k) uv=splev(dx,tckp) assert_almost_equal(0.0, around(abs(uv[1]-f(uv[0])),2), decimal=1) assert_almost_equal(0.0, around(abs(splev(uv[0],tck)-f(uv[0])),2),decimal=1)
def check_splint_spalde(self): per = [0, 1, 0] N = [20, 20, 50] ia = [0, 0, 0.2*pi] ib = [0, 0, pi] a,b = 0,2*pi dx = 0.2*pi k = range(1,6) for i in range(len(per)): x=a+(b-a)*arange(N[i]+1,dtype=float)/float(N[i]) v=f1(x) for j in range(len(k)): tck = splrep(x,v,k=k[j],s=0,per=per[i]) ir = splint(ia[i],ib[i],tck) dr = spalde(dx,tck) assert_almost_equal(ir, f1(ib[i],-1)-f1(ia[i],-1), decimal=2) d=0 for ddr in dr: if d<k[j]-1: assert_almost_equal(1, ddr/f1(dx,d), decimal=2) d=d+1