Beispiel #1
0
 def test_cache_argument(self):
     x, y, z = np.arange(16), np.arange(16, 32), np.arange(32, 48)
     bisplrep_cache = {
         't': array([], float),
         'wrk': array([], float),
         'iwrk': array([], intc)
     }
     bisplrep(x, y, z, task=0, cache=bisplrep_cache)
     bisplrep(x, y, z, task=1, cache=bisplrep_cache)
Beispiel #2
0
    def test_regression_1310(self):
        # Regression test for gh-1310
        data = np.load(data_file("bug-1310.npz"))["data"]

        # Shouldn't crash -- the input data triggers work array sizes
        # that caused previously some data to not be aligned on
        # sizeof(double) boundaries in memory, which made the Fortran
        # code to crash when compiled with -O3
        bisplrep(data[:, 0], data[:, 1], data[:, 2], kx=3, ky=3, s=0, full_output=True)
    def test_regression_1310(self):
        # Regression test for gh-1310
        data = np.load(data_file('bug-1310.npz'))['data']

        # Shouldn't crash -- the input data triggers work array sizes
        # that caused previously some data to not be aligned on
        # sizeof(double) boundaries in memory, which made the Fortran
        # code to crash when compiled with -O3
        bisplrep(data[:,0], data[:,1], data[:,2], kx=3, ky=3, s=0,
                 full_output=True)
Beispiel #4
0
 def test_ilp64_bisplrep(self):
     check_free_memory(28000)  # VM size, doesn't actually use the pages
     x = np.linspace(0, 1, 400)
     y = np.linspace(0, 1, 400)
     x, y = np.meshgrid(x, y)
     z = np.zeros_like(x)
     tck = bisplrep(x, y, z, kx=3, ky=3, s=0)
     assert_allclose(bisplev(0.5, 0.5, tck), 0.0)
 def check_5(self,f=f2,kx=3,ky=3,xb=0,xe=2*pi,yb=0,ye=2*pi,Nx=20,Ny=20,s=0):
     x = xb+(xe-xb)*arange(Nx+1,dtype=float)/float(Nx)
     y = yb+(ye-yb)*arange(Ny+1,dtype=float)/float(Ny)
     xy = makepairs(x,y)
     tck = bisplrep(xy[0],xy[1],f(xy[0],xy[1]),s=s,kx=kx,ky=ky)
     tt = [tck[0][kx:-kx],tck[1][ky:-ky]]
     t2 = makepairs(tt[0],tt[1])
     v1 = bisplev(tt[0],tt[1],tck)
     v2 = f2(t2[0],t2[1])
     v2.shape = len(tt[0]),len(tt[1])
     err = norm2(ravel(v1-v2))
     assert_(err < 1e-2, err)
     put(err)
 def check_5(self,f=f2,kx=3,ky=3,xb=0,xe=2*pi,yb=0,ye=2*pi,Nx=20,Ny=20,s=0):
     x=xb+(xe-xb)*arange(Nx+1,dtype=float)/float(Nx)
     y=yb+(ye-yb)*arange(Ny+1,dtype=float)/float(Ny)
     xy=makepairs(x,y)
     tck=bisplrep(xy[0],xy[1],f(xy[0],xy[1]),s=s,kx=kx,ky=ky)
     tt=[tck[0][kx:-kx],tck[1][ky:-ky]]
     t2=makepairs(tt[0],tt[1])
     v1=bisplev(tt[0],tt[1],tck)
     v2=f2(t2[0],t2[1])
     v2.shape=len(tt[0]),len(tt[1])
     err = norm2(ravel(v1-v2))
     assert_(err < 1e-2, err)
     put(err)
 def test_rerun_lwrk2_too_small(self):
     # in this setting, lwrk2 is too small in the default run. Here we
     # check for equality with the bisplrep/bisplev output because there,
     # an automatic re-run of the spline representation is done if ier>10.
     x = np.linspace(-2, 2, 80)
     y = np.linspace(-2, 2, 80)
     z = x + y
     xi = np.linspace(-1, 1, 100)
     yi = np.linspace(-2, 2, 100)
     tck = bisplrep(x, y, z)
     res1 = bisplev(xi, yi, tck)
     interp_ = SmoothBivariateSpline(x, y, z)
     res2 = interp_(xi, yi)
     assert_almost_equal(res1, res2)
Beispiel #8
0
 def test_rerun_lwrk2_too_small(self):
     # in this setting, lwrk2 is too small in the default run. Here we
     # check for equality with the bisplrep/bisplev output because there,
     # an automatic re-run of the spline representation is done if ier>10.
     x = np.linspace(-2, 2, 80)
     y = np.linspace(-2, 2, 80)
     z = x + y
     xi = np.linspace(-1, 1, 100)
     yi = np.linspace(-2, 2, 100)
     tck = bisplrep(x, y, z)
     res1 = bisplev(xi, yi, tck)
     interp_ = SmoothBivariateSpline(x, y, z)
     res2 = interp_(xi, yi)
     assert_almost_equal(res1, res2)
Beispiel #9
0
 def test_task_argument(self):
     x, y, z = np.arange(16), np.arange(16, 32), np.arange(32, 48)
     bisplrep(x, y, z, task=0)
     with pytest.raises(ValueError):
         bisplrep(x, y, z, task=1)
Beispiel #10
0
    def make_diff_func(self) :
        ''' everytime parameters are changed, the diffusion 
            function must be REMADE or it's data adapted !! 
        '''
        if  (self.difftype == 'MC_2D4pint_ext1D' 
                    or self.difftype == 'MC_2D4pint_func'):
                from GridUtils import GridFunc2D
                self.diff11   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[2]),False)
                self.diff12   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[3]),False)
                self.diff21   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[4]),False)
                self.diff22   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[5]),False)
                self.diff11_u = None;self.diff12_u = None;self.diff21_u = None;self.diff22_u = None;
                self.diff11_v = None;self.diff12_v = None;self.diff21_v = None;self.diff22_v = None;
                #grideval means a ugrid and vgrid is given, the grid made by this is evaluated
                #this is used in the plotting function
                self.diff11_grideval   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[2]),True)
                self.diff12_grideval   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[3]),True)
                self.diff21_grideval   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[4]),True)
                self.diff22_grideval   = GridFunc2D([self.param[0],self.param[1]],N.asarray(self.param[5]),True)


        elif self.difftype == 'MC_bspline_ext1D' or \
                  self.difftype == 'MC_bspline1storder_ext1D' : 
                self.arrayaware = False           
                weight = ones(self.nrparam)
                # standard dev on diffusion = 0.2, inverse is 5
                weight[:] =5 * weight[:] 
                #create an interp object
                from scipy.interpolate.fitpack import bisplrep,bisplev
                #param[0] should be list of u values
                #param[1] should be list of v values
                #param[2] should be list of D(u,v) values
                #create the data of the bicubic bspline:
                # no smoother so s = 0
                if self.difftype == 'MC_bspline1storder_ext1D' :
                    self.splinedataD11 = bisplrep(self.param[0], self.param[1],
                        self.param[2], w= weight, s=None,
                        kx = 1, ky=1, full_output = 1, quiet = 0)
                else :
                    #nknots = 11
                    #tx = range(nknots)
                    #tx = [self.umin + x/(1.*(nknots-1)) * (self.umax-self.umin) for x in tx]
                    #ty = range(nknots)
                    #ty = [self.vmin + x/(1.*(nknots-1)) * (self.vmax-self.vmin) for x in ty]
                    #tx = tx[0]*3 + tx + tx[-1]*3
                    #tx[:1] = [tx[0]]*4 ; tx[-1:] = [tx[-1]]*4
                    #ty[:1] = [ty[0]]*4 ; ty[-1:] = [ty[-1]]*4
                    #print 'tx,ty',tx, ty
                    self.splinedataD11 = bisplrep(self.param[0], self.param[1],
                        self.param[2], w= weight, s=2100, 
                        kx = 3, ky=3, full_output = 1, quiet = 0)
                #print 'D11 output :', self.splinedataD11[1:]
                if self.splinedataD11[2] > 0 :
                    print 'ERROR in spline interpolation'
                    sys.exit()
                self.splinedataD11 = self.splinedataD11[0]
                self.diff11   = lambda u,v: bisplev([u], [v], self.splinedataD11, \
                            dx = 0, dy=0)
                self.diff11_u = lambda u,v: bisplev([u], [v] , self.splinedataD11,\
                            dx = 1, dy=0)
                self.diff11_v = lambda u,v: bisplev([u], [v] , self.splinedataD11,\
                            dx = 0, dy=1)
                self.diff11_grideval   = lambda u,v: bisplev(u, v, self.splinedataD11, \
                            dx = 0, dy=0)
                self.diff11_u_grideval = lambda u,v: bisplev(u, v , self.splinedataD11,\
                            dx = 1, dy=0)
                self.diff11_v_grideval = lambda u,v: bisplev(u, v , self.splinedataD11,\
                            dx = 0, dy=1)
                if self.difftype == 'MC_bspline1storder_ext1D' :
                    self.splinedataD12 = bisplrep(self.param[0], self.param[1],
                        self.param[3], w= weight, s=None,
                        kx = 1, ky=1, full_output = 1, quiet = 1)
                else :
                    self.splinedataD12 = bisplrep(self.param[0], self.param[1],
                        self.param[3], w= weight, s=None,
                        kx = 3, ky=3, full_output = 1, quiet = 0)
                #print 'D12 output :', self.splinedataD12[1:]
                if self.splinedataD12[2] > 0 :
                    print 'ERROR in spline interpolation'
                    sys.exit()
                self.splinedataD12 = self.splinedataD12[0]
                self.diff12   = lambda u,v: bisplev([u], [v], self.splinedataD12, \
                            dx = 0, dy=0)
                self.diff12_u = lambda u,v: bisplev([u], [v] , self.splinedataD12,\
                            dx = 1, dy=0)
                self.diff12_v = lambda u,v: bisplev([u], [v] , self.splinedataD12,\
                            dx = 0, dy=1)
                self.diff12_grideval   = lambda u,v: bisplev(u, v, self.splinedataD12, \
                            dx = 0, dy=0)
                self.diff12_u_grideval = lambda u,v: bisplev(u, v , self.splinedataD12,\
                            dx = 1, dy=0)
                self.diff12_v_grideval = lambda u,v: bisplev(u, v , self.splinedataD12,\
                            dx = 0, dy=1)
                if self.difftype == 'MC_bspline1storder_ext1D' :
                    self.splinedataD21 = bisplrep(self.param[0], self.param[1],
                        self.param[4], w= weight, s=None,
                        kx = 1, ky=1, full_output = 1, quiet = 1)
                else :
                    self.splinedataD21 = bisplrep(self.param[0], self.param[1],
                        self.param[4], w= weight, s=None,
                        kx = 3, ky=3, full_output = 1, quiet = 0)
                #print 'D21 output :', self.splinedataD21[1:]
                if self.splinedataD21[2] > 0 :
                    print 'ERROR in spline interpolation'
                    sys.exit()
                self.splinedataD21 = self.splinedataD21[0]
                self.diff21   = lambda u,v: bisplev([u], [v], self.splinedataD21, \
                            dx = 0, dy=0)
                self.diff21_u = lambda u,v: bisplev([u], [v] , self.splinedataD21,\
                            dx = 1, dy=0)
                self.diff21_v = lambda u,v: bisplev([u], [v] , self.splinedataD21,\
                            dx = 0, dy=1)
                self.diff21_grideval   = lambda u,v: bisplev(u, v, self.splinedataD21, \
                            dx = 0, dy=0)
                self.diff21_u_grideval = lambda u,v: bisplev(u, v , self.splinedataD21,\
                            dx = 1, dy=0)
                self.diff21_v_grideval = lambda u,v: bisplev(u, v , self.splinedataD21,\
                            dx = 0, dy=1)
                if self.difftype == 'MC_bspline1storder_ext1D' :
                    self.splinedataD22 = bisplrep(self.param[0], self.param[1],
                        self.param[5], w= weight, s=None,
                        kx = 1, ky=1, full_output = 1, quiet = 1)
                else :
                    self.splinedataD22 = bisplrep(self.param[0], self.param[1],
                        self.param[5], w= weight, s=55000.,
                        kx = 3, ky=3, full_output = 1, quiet = 0)
                #print 'D22 output :', self.splinedataD22[1:]
                if self.splinedataD22[2] > 0 :
                    print 'ERROR in spline interpolation'
                    sys.exit()
                self.splinedataD22 = self.splinedataD22[0]
                self.diff22   = lambda u,v: bisplev([u], [v], self.splinedataD22, \
                            dx = 0, dy=0)
                self.diff22_u = lambda u,v: bisplev([u], [v] , self.splinedataD22,\
                            dx = 1, dy=0)
                self.diff22_v = lambda u,v: bisplev([u], [v] , self.splinedataD22,\
                            dx = 0, dy=1)
                self.diff22_grideval   = lambda u,v: bisplev(u, v, self.splinedataD22, \
                            dx = 0, dy=0)
                self.diff22_u_grideval = lambda u,v: bisplev(u, v , self.splinedataD22,\
                            dx = 1, dy=0)
                self.diff22_v_grideval = lambda u,v: bisplev(u, v , self.splinedataD22,\
                            dx = 0, dy=1)
        elif self.difftype == 'MC_interp2d_ext1D':
                from scipy.interpolate.interpolate import interp2d
                self.diff11   = interp2d(self.param[0],self.param[1],self.param[2])
                self.diff12   = interp2d(self.param[0],self.param[1],self.param[3])
                self.diff21   = interp2d(self.param[0],self.param[1],self.param[4])
                self.diff22   = interp2d(self.param[0],self.param[1],self.param[5])
                print 'diff11 test ' , self.diff11(1.5)
                print ' *** DO NOT USE THIS INTERPOLATION, it performs badly ***'
                sys.exit()
        elif self.difftype == 'function' :
            #self.diffij is defined when reading the init file for scalars,
            pass
        else:
            print ('Unknown diffusion type given', self.difftype)
            sys.exit()
        
        #store the functions in a list:
        self.diff = [[self.diff11 , self.diff12],[self.diff21 , self.diff22]]
        self.diff_u = [[self.diff11_u , self.diff12_u],[self.diff21_u , self.diff22_u]]
        self.diff_v = [[self.diff11_v , self.diff12_v],[self.diff21_v , self.diff22_v]]
        #changed parameters are taken into account, so diffusion is now correct
        self.modified = False