def test_chebpts1(self): #test exceptions assert_raises(ValueError, cheb.chebpts1, 1.5) assert_raises(ValueError, cheb.chebpts1, 0) #test points tgt = [0] assert_almost_equal(cheb.chebpts1(1), tgt) tgt = [-0.70710678118654746, 0.70710678118654746] assert_almost_equal(cheb.chebpts1(2), tgt) tgt = [-0.86602540378443871, 0, 0.86602540378443871] assert_almost_equal(cheb.chebpts1(3), tgt) tgt = [-0.9238795325, -0.3826834323, 0.3826834323, 0.9238795325] assert_almost_equal(cheb.chebpts1(4), tgt)
def _fit_idct(self,func,N): """ Return the chebyshev coefficients using the idct """ pts = -cheb.chebpts1(N) y = func(pts) coeffs = idct(y,type=3)/N coeffs[0] /= 2. coeffs[-1] /= 2. return coeffs
def Init_lenda_tic(self ): l_0 = self.lenda_0 self.lenda_tic=[] if self.tic_type=="cheb_": pt_1 = cheb.chebpts1(256) pt_2 = cheb.chebpts2(256) scale = (self.lenda_1-l_0)/2 off = l_0+scale self.lenda_tic = [i * scale + off for i in pt_2] assert(self.lenda_tic[0]==l_0 and self.lenda_tic[-1]==self.lenda_1) else: if( self.lenda_0<500 ): self.lenda_tic = list(range(self.lenda_0,500,1)) l_0 = 500 self.lenda_tic.extend( list(range(l_0,self.lenda_1+self.lenda_step,self.lenda_step)) )
def chebpts1(npts): from numpy.polynomial.chebyshev import chebpts1 return chebpts1(npts)
import numpy as np import numpy.polynomial.chebyshev as C import time from scipy.interpolate import BarycentricInterpolator as bi from cy_lagrange import Barycentric if __name__ == '__main__': ni = 500 ne = 20000 # Interpolation points xi = C.chebpts1(ni) # Evalutation points xe = np.linspace(-1, 1, ne) # The data to interpolate fi = np.sin(10 * xi) * np.exp(xi) t = [time.time()] # Interpolate using Cython/C++ bary = Barycentric(xi, xe) t.append(time.time()) fe = bary.interp(fi) t.append(time.time())
from scipy.fft import dct from numpy.polynomial.chebyshev import chebpts1, Chebyshev, cheb2poly from numpy.polynomial.polynomial import polyval import math import matplotlib.pyplot as plt import numpy as np #### Compute Chebyshev interpolation points of the first kind. degree = 20 X = reversed(chebpts1( degree + 1)) # Reverse the order to have increasing theta instead of increasing x. # print('X:', X) #### Evaluate f at Chebyshev interpolation points. a = -5 b = 5 def affine_transformation(x, a=a, b=b): # maps [-1,1] to [a,b] return (b - a) / 2 * x + (a + b) / 2 # print(affine_transformation(a, b, -1)) # should be a # print(affine_transformation(a, b, 1)) # should be b def inverse_affine_transformation(y, a=a, b=b): # maps [a,b] to [-1,1]
import numpy as np import numpy.polynomial.chebyshev as C import time from scipy.interpolate import BarycentricInterpolator as bi from cy_lagrange import Barycentric if __name__ == '__main__': ni = 500 ne = 20000 # Interpolation points xi = C.chebpts1(ni) # Evalutation points xe = np.linspace(-1,1,ne) # The data to interpolate fi = np.sin(10*xi)*np.exp(xi) t = [time.time()] # Interpolate using Cython/C++ bary = Barycentric(xi,xe) t.append(time.time()) fe = bary.interp(fi) t.append(time.time())
# stt_time = info['stt_time'] end_time = stt_time + tsamp * nbin0 / 86400.0 + 60. / 86400 stt_time -= 60. / 86400 time0 = file_time[0] if args.period or (not pepoch): if args.period: period = args.period phase = np.arange(nbin0) * tsamp / period info['phase0'] = 0 nperiod = int(np.ceil(np.max(phase))) stt_sec = time0[:-1].sum() - delay stt_date = time0[-1] + stt_sec // 86400 stt_sec = stt_sec % 86400 else: chebx_test0 = nc.chebpts1(args.ncoeff) chebx_test = np.concatenate(([-1], chebx_test0, [1]), axis=0) second_test = (chebx_test + 1) / 2 * nbin0 * tsamp + file_time[0][:-1].sum() - delay time_test = te.time(file_time[0][-1] * np.ones(args.ncoeff + 2), second_test, scale='local') times_test = te.times(time_test) timing_test_end = pm.psr_timing(psr, times_test, freq_end) timing_test_start = pm.psr_timing(psr, times_test, freq_start) phase_start = timing_test_end.phase.date[0] + 1 phase_end = timing_test_start.phase.date[-1] phase = timing_test_end.phase.date - phase_start + timing_test_end.phase.second nperiod = phase_end - phase_start period = ( (time_test.date[-1] - time_test.date[0]) * time_test.unit +