Example #1
0
    def __init__(self,
                 x,
                 y,
                 z,
                 kind='linear',
                 copy=True,
                 bounds_error=False,
                 fill_value=np.nan):
        self.x, self.y, self.z = map(asarray, [x, y, z])
        self.x, self.y = map(ravel, [self.x, self.y])

        if self.z.size == len(self.x) * len(self.y):
            rectangular_grid = True
            if not all(self.x[1:] > self.x[:-1]):
                j = np.argsort(self.x)
                self.x = self.x[j]
                self.z = self.z[:, j]
            if not all(self.y[1:] > self.y[:-1]):
                j = np.argsort(self.y)
                self.y = self.y[j]
                self.z = self.z[j, :]
            self.z = ravel(self.z.T)
        else:
            rectangular_grid = False
            self.z = ravel(self.z)
            if len(self.x) != len(self.y):
                raise ValueError(
                    "x and y must have equal lengths for non rectangular grid")
            if len(self.z) != len(self.x):
                raise ValueError(
                    "Invalid length for input z for non rectangular grid")

        try:
            kx = ky = {'linear': 1, 'cubic': 3, 'quintic': 5}[kind]
        except KeyError:
            raise ValueError("Unsupported interpolation type.")

        if not rectangular_grid:
            # TODO: surfit is really not meant for interpolation!
            self.tck = fitpack.bisplrep(self.x,
                                        self.y,
                                        self.z,
                                        kx=kx,
                                        ky=ky,
                                        s=0.0)
        else:
            nx, tx, ny, ty, c, fp, ier = dfitpack.regrid_smth(self.x,
                                                              self.y,
                                                              self.z,
                                                              None,
                                                              None,
                                                              None,
                                                              None,
                                                              kx=kx,
                                                              ky=ky,
                                                              s=0.0)
            self.tck = (tx[:nx], ty[:ny], c[:(nx - kx - 1) * (ny - ky - 1)],
                        kx, ky)
Example #2
0
    def __init__(self, x, y, z, kind='linear', copy=True, bounds_error=False,
                 fill_value=np.nan):
        self.x, self.y, self.z = map(asarray, [x, y, z])
        self.x, self.y = map(ravel, [self.x, self.y])

        if self.z.size == len(self.x) * len(self.y):
            rectangular_grid = True
            if not all(self.x[1:] > self.x[:-1]):
                j = np.argsort(self.x)
                self.x = self.x[j]
                self.z = self.z[:,j]
            if not all(self.y[1:] > self.y[:-1]):
                j = np.argsort(self.y)
                self.y = self.y[j]
                self.z = self.z[j,:]
            self.z = ravel(self.z.T)
        else:
            rectangular_grid = False
            self.z = ravel(self.z)
            if len(self.x) != len(self.y):
                raise ValueError(
                    "x and y must have equal lengths for non rectangular grid")
            if len(self.z) != len(self.x):
                raise ValueError(
                    "Invalid length for input z for non rectangular grid")

        try:
            kx = ky = {'linear' : 1,
                       'cubic' : 3,
                       'quintic' : 5}[kind]
        except KeyError:
            raise ValueError("Unsupported interpolation type.")

        if not rectangular_grid:
            # TODO: surfit is really not meant for interpolation!
            self.tck = fitpack.bisplrep(self.x, self.y, self.z,
                                        kx=kx, ky=ky, s=0.0)
        else:
            nx, tx, ny, ty, c, fp, ier = dfitpack.regrid_smth(
                self.x, self.y, self.z, None, None, None, None,
                kx=kx, ky=ky, s=0.0)
            self.tck = (tx[:nx], ty[:ny], c[:(nx - kx - 1) * (ny - ky - 1)],
                        kx, ky)
Example #3
0
    def __init__(self, x, y, z, kind='linear', copy=True, bounds_error=False,
                 fill_value=np.nan):
        self.x, self.y, self.z = map(ravel, map(asarray, [x, y, z]))

        if len(self.z) == len(self.x) * len(self.y):
            self.x, self.y = meshgrid(x,y)
            self.x, self.y = map(ravel, [self.x, self.y])
        if len(self.x) != len(self.y):
            raise ValueError("x and y must have equal lengths")
        if len(self.z) != len(self.x):
            raise ValueError("Invalid length for input z")

        try:
            kx = ky = {'linear' : 1,
                       'cubic' : 3,
                       'quintic' : 5}[kind]
        except KeyError:
            raise ValueError("Unsupported interpolation type.")

        self.tck = fitpack.bisplrep(self.x, self.y, self.z, kx=kx, ky=ky, s=0.)
Example #4
0
    def __init__(self,
                 x,
                 y,
                 z,
                 kind='linear',
                 copy=True,
                 bounds_error=False,
                 fill_value=np.nan):
        self.x, self.y, self.z = map(ravel, map(asarray, [x, y, z]))

        if len(self.z) == len(self.x) * len(self.y):
            self.x, self.y = meshgrid(x, y)
            self.x, self.y = map(ravel, [self.x, self.y])
        if len(self.x) != len(self.y):
            raise ValueError("x and y must have equal lengths")
        if len(self.z) != len(self.x):
            raise ValueError("Invalid length for input z")

        try:
            kx = ky = {'linear': 1, 'cubic': 3, 'quintic': 5}[kind]
        except KeyError:
            raise ValueError("Unsupported interpolation type.")

        self.tck = fitpack.bisplrep(self.x, self.y, self.z, kx=kx, ky=ky, s=0.)
Example #5
0
    def __init__(self, x, y, z, kind='linear', copy=True, bounds_error=False,
        fill_value=np.nan):
        """ Initialize a 2D interpolator.

        Parameters
        ----------
        x : 1D array
        y : 1D array
            Arrays defining the coordinates of a 2D grid.  If the
            points lie on a regular grid, x and y can simply specify
            the rows and colums, i.e.

            x = [0,1,2]  y = [0,1,2]
            
            otherwise x and y must specify the full coordinates, i.e.
            
            x = [0,1,2,0,1.5,2,0,1,2]  y = [0,1,2,0,1,2,0,1,2]
            
            If x and y are 2-dimensional, they are flattened (allowing
            the use of meshgrid, for example).
            
        z : 1D array
            The values of the interpolated function on the grid
            points. If z is a 2-dimensional array, it is flattened.

        kind : 'linear', 'cubic', 'quintic'
            The kind of interpolation to use.
        copy : bool
            If True, then data is copied, otherwise only a reference is held.
        bounds_error : bool
            If True, when interoplated values are requested outside of the
            domain of the input data, an error is raised.
            If False, then fill_value is used.
        fill_value : number
            If provided, the value to use for points outside of the
            interpolation domain. Defaults to NaN.

        Raises
        ------
        ValueError when inputs are invalid.

        """        
        self.x, self.y, self.z = map(ravel, map(array, [x, y, z]))
        if not map(rank, [self.x, self.y, self.z]) == [1,1,1]:
            raise ValueError("One of the input arrays is not 1-d.")
        if len(self.x) != len(self.y):
            raise ValueError("x and y must have equal lengths")
        if len(self.z) == len(self.x) * len(self.y):
            self.x, self.y = meshgrid(x,y)
            self.x, self.y = map(ravel, [self.x, self.y])
        if len(self.z) != len(self.x):
            raise ValueError("Invalid length for input z")
        
        try:
            kx = ky = {'linear' : 1,
                       'cubic' : 3,
                       'quintic' : 5}[kind]
        except KeyError:
            raise ValueError("Unsupported interpolation type.")
        
        self.tck = fitpack.bisplrep(self.x, self.y, self.z, kx=kx, ky=ky, s=0.)