当前位置: 首页>>代码示例>>Python>>正文


Python interpolate.interp2d方法代码示例

本文整理汇总了Python中scipy.interpolate.interp2d方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.interp2d方法的具体用法?Python interpolate.interp2d怎么用?Python interpolate.interp2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.interpolate的用法示例。


在下文中一共展示了interpolate.interp2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def __init__(self,orbit_datapath=None,f_nStars=10,**specs): 

        ObservatoryL2Halo.__init__(self,**specs)  
        self.f_nStars = int(f_nStars)
        
        # instantiating fake star catalog, used to generate good dVmap
        fTL = TargetList(**{"ntargs":self.f_nStars,'modules':{"StarCatalog": "FakeCatalog", \
                    "TargetList":" ","OpticalSystem": "Nemati", "ZodiacalLight": "Stark", "PostProcessing": " ", \
                    "Completeness": " ","BackgroundSources": "GalaxiesFaintStars", "PlanetPhysicalModel": " ", \
                    "PlanetPopulation": "KeplerLike1"}, "scienceInstruments": [{ "name": "imager"}],  \
                    "starlightSuppressionSystems": [{ "name": "HLC-565"}]   })
        
        f_sInds = np.arange(0,fTL.nStars)
        dV,ang,dt = self.generate_dVMap(fTL,0,f_sInds,self.equinox[0])
        
        # pick out unique angle values
        ang, unq = np.unique(ang, return_index=True)
        dV = dV[:,unq]
        
        #create dV 2D interpolant
        self.dV_interp  = interp.interp2d(dt,ang,dV.T,kind='linear') 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:SotoStarshade.py

示例2: test_interp2d_meshgrid_input_unsorted

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def test_interp2d_meshgrid_input_unsorted(self):
        np.random.seed(1234)
        x = linspace(0, 2, 16)
        y = linspace(0, pi, 21)

        z = sin(x[None,:] + y[:,None]/2.)
        ip1 = interp2d(x.copy(), y.copy(), z, kind='cubic')

        np.random.shuffle(x)
        z = sin(x[None,:] + y[:,None]/2.)
        ip2 = interp2d(x.copy(), y.copy(), z, kind='cubic')

        np.random.shuffle(x)
        np.random.shuffle(y)
        z = sin(x[None,:] + y[:,None]/2.)
        ip3 = interp2d(x, y, z, kind='cubic')

        x = linspace(0, 2, 31)
        y = linspace(0, pi, 30)

        assert_equal(ip1(x, y), ip2(x, y))
        assert_equal(ip1(x, y), ip3(x, y)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_interpolate.py

示例3: test_interp2d_bounds

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def test_interp2d_bounds(self):
        x = np.linspace(0, 1, 5)
        y = np.linspace(0, 2, 7)
        z = x[:,None]**2 + y[None,:]

        ix = np.linspace(-1, 3, 31)
        iy = np.linspace(-1, 3, 33)

        b = interp2d(x, y, z, bounds_error=True)
        assert_raises(ValueError, b, ix, iy)

        b = interp2d(x, y, z, fill_value=np.nan)
        iz = b(ix, iy)
        mx = (ix < 0) | (ix > 1)
        my = (iy < 0) | (iy > 2)
        assert_(np.isnan(iz[my,:]).all())
        assert_(np.isnan(iz[:,mx]).all())
        assert_(np.isfinite(iz[~my,:][:,~mx]).all()) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_interpolate.py

示例4: resample_2d

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def resample_2d(array, sample_pts, query_pts, kind='linear'):
    """Resample 2D array to be sampled along queried points.

    Parameters
    ----------
    array : `numpy.ndarray`
        2D array
    sample_pts : `tuple`
        pair of `numpy.ndarray` objects that contain the x and y sample locations,
        each array should be 1D
    query_pts : `tuple`
        points to interpolate onto, also 1D for each array
    kind : `str`, {'linear', 'cubic', 'quintic'}
        kind / order of spline to use

    Returns
    -------
    `numpy.ndarray`
        array resampled onto query_pts via bivariate spline

    """
    interpf = interpolate.interp2d(*sample_pts, array, kind=kind)
    return interpf(*query_pts) 
开发者ID:brandondube,项目名称:prysm,代码行数:25,代码来源:coordinates.py

示例5: _infer_interval_breaks

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def _infer_interval_breaks(coord, kind=None):
        """
        Interpolate the bounds from the data in coord

        Parameters
        ----------
        %(CFDecoder.get_plotbounds.parameters.no_ignore_shape)s

        Returns
        -------
        %(CFDecoder.get_plotbounds.returns)s

        Notes
        -----
        this currently only works for rectilinear grids"""
        if coord.ndim == 1:
            return _infer_interval_breaks(coord)
        elif coord.ndim == 2:
            from scipy.interpolate import interp2d
            kind = kind or rcParams['decoder.interp_kind']
            y, x = map(np.arange, coord.shape)
            new_x, new_y = map(_infer_interval_breaks, [x, y])
            coord = np.asarray(coord)
            return interp2d(x, y, coord, kind=kind, copy=False)(new_x, new_y) 
开发者ID:psyplot,项目名称:psyplot,代码行数:26,代码来源:data.py

示例6: _make_interpolation

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def _make_interpolation(self):
        """
        creates an interpolation grid in H_0, omega_m and computes quantities in Dd and Ds_Dds
        :return:
        """
        grid2d = np.dstack(np.meshgrid(self._H0_range, self._omega_m_range)).reshape(-1, 2)
        H0_grid = grid2d[:, 0]
        omega_m_grid = grid2d[:, 1]
        Dd_grid = np.zeros_like(H0_grid)
        Ds_Dds_grid = np.zeros_like(H0_grid)
        for i in range(len(H0_grid)):
            Dd, Ds_Dds = cosmo2angular_diameter_distances(H0_grid[i], omega_m_grid[i], self.z_d, self.z_s)
            Dd_grid[i] = Dd
            Ds_Dds_grid[i] = Ds_Dds
        self._f_H0 = interpolate.interp2d(Dd_grid, Ds_Dds_grid, H0_grid, kind='linear', copy=False, bounds_error=False, fill_value=-1)
        print("H0 interpolation done")
        self._f_omega_m = interpolate.interp2d(Dd_grid, Ds_Dds_grid, omega_m_grid, kind='linear', copy=False, bounds_error=False, fill_value=0)
        print("omega_m interpolation done") 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:20,代码来源:cosmo_solver.py

示例7: interpolate_xarray

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def interpolate_xarray(xpoints, ypoints, values, shape, kind='cubic',
                       blocksize=CHUNK_SIZE):
    """Interpolate, generating a dask array."""
    vchunks = range(0, shape[0], blocksize)
    hchunks = range(0, shape[1], blocksize)

    token = tokenize(blocksize, xpoints, ypoints, values, kind, shape)
    name = 'interpolate-' + token

    from scipy.interpolate import interp2d
    interpolator = interp2d(xpoints, ypoints, values, kind=kind)

    dskx = {(name, i, j): (interpolate_slice,
                           slice(vcs, min(vcs + blocksize, shape[0])),
                           slice(hcs, min(hcs + blocksize, shape[1])),
                           interpolator)
            for i, vcs in enumerate(vchunks)
            for j, hcs in enumerate(hchunks)
            }

    res = da.Array(dskx, name, shape=list(shape),
                   chunks=(blocksize, blocksize),
                   dtype=values.dtype)
    return DataArray(res, dims=('y', 'x')) 
开发者ID:pytroll,项目名称:satpy,代码行数:26,代码来源:sar_c_safe.py

示例8: interpol_spline2d

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def interpol_spline2d(x, y, z, xout, yout):
    """
    Performs a cubic spline interpolation of a 2D matrix/image irregularily sampled on both axes

    :author: Andreas Reigber
    :param x: The x values of the first axis of z
    :type x: 1-D ndarray float
    :param y: The y values of the second axis of z
    :type y: 1-D ndarray float
    :param z: The input matrix
    :type z: 2D ndarray
    :param xout: The values on the first axis where the interpolates are desired
    :type xout: 1D ndarray float
    :param yout: The values on the second axis where the interpolates are desired
    :type yout: 1D ndarray float
    :returns: The interpolated matrix /  image
    """
    if np.iscomplexobj(z):
        f_real = interpolate.interp2d(x, y, z.real, kind='cubic')
        f_imag = interpolate.interp2d(x, y, z.imag, kind='cubic')
        return f_real(xout, yout) + 1j * f_imag(xout, yout)
    else:
        f = interpolate.interp2d(x, y, z, kind='cubic')
        return f(xout, yout) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:26,代码来源:interpolation.py

示例9: interpol_lin2d

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def interpol_lin2d(x, y, z, xout, yout):
    """
    Performs a linear interpolation of a 2D matrix/image irregularily sampled on both axes

    :author: Andreas Reigber
    :param x: The x values of the first axis of z
    :type x: 1-D ndarray float
    :param y: The y values of the second axis of z
    :type y: 1-D ndarray float
    :param z: The input matrix
    :type z: 2D ndarray
    :param xout: The values on the first axis where the interpolates are desired
    :type xout: 1D ndarray float
    :param yout: The values on the second axis where the interpolates are desired
    :type yout: 1D ndarray float
    :returns: The interpolated matrix /  image
    """
    if np.iscomplexobj(z):
        f_real = sp.interpolate.interp2d(x, y, z.real, kind='linear')
        f_imag = sp.interpolate.interp2d(x, y, z.imag, kind='linear')
        return f_real(xout, yout) + 1j * f_imag(xout, yout)
    else:
        f = sp.interpolate.interp2d(x, y, z, kind='linear')
        return f(xout, yout) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:26,代码来源:interpolation.py

示例10: interpolator2d

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def interpolator2d(x,y,z):
  """Return a 2D interpolator"""
  x = np.array(x)
  y = np.array(y)
  from scipy.interpolate import interp2d
  ny = (y.max()-y.min())/abs(y[1]-y[0])
  ny = int(round(ny)) + 1
  nx = len(z)/ny
  nx = int(nx)
  ny = int(ny)
  x0 = np.linspace(min(x),max(x),nx)
  y0 = np.linspace(min(y),max(y),ny)
  xx, yy = np.meshgrid(x0, y0)
  Z = np.array(z).reshape(nx,ny) # makes a (Zy,Zx) matrix out of z
  T = Z.T
  f = interp2d(x0, y0, T, kind='linear')
  return f 
开发者ID:joselado,项目名称:quantum-honeycomp,代码行数:19,代码来源:interpolation.py

示例11: selected_interpolation

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def selected_interpolation(fin,mx,my,mz,nite=3):
  """Call in a function in a mesh which is two nite times finer, but only
  in those points that are expected to change, in the others interpolate"""
  if nite<1.01: return mx,my,mz 
  f = interpolate.interp2d(mx[:,0], my[0,:], mz, kind='linear') # interpolation
  x = np.linspace(np.min(mx),np.max(mx),len(mx)*2) # twice as big
  y = np.linspace(np.min(my),np.max(my),len(my)*2) # twice as big
  mx2, my2 = np.meshgrid(x, y) # new grid
  mz2 = f(x,y) # interpolate
  mz2 = mz2.transpose()
  dmz = np.gradient(mz2) # gradient
  dmz = dmz[0]*dmz[0] + dmz[1]*dmz[1] # norm of the derivative
  maxdm = np.max(dmz) # maximum derivative
  for i in range(len(mx2)):
    for j in range(len(my2)):
      if dmz[i,j]>0.001*maxdm: # if derivative is large in this point
        mz2[i,j] = fin(mx2[i,j],my2[i,j]) # re-evaluate the function
  mx2 = mx2.transpose()
  my2 = my2.transpose()
  mz2 = mz2.transpose()
  if nite>1:
    return selected_interpolation(fin,mx2,my2,mz2,nite=nite-1)
  return mx2,my2,mz2 # return function 
开发者ID:joselado,项目名称:quantum-honeycomp,代码行数:25,代码来源:phasediagram.py

示例12: __call__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def __call__(self, x, y, dx=0, dy=0, assume_sorted=False):
        """  Wrapper to scipy.interpolate.interp2d which preserves the input ordering.

        Parameters
        ----------
        x: See superclass
        y: See superclass
        dx: See superclass
        dy: See superclass
        assume_sorted: bool, optional
            This is just a place holder to prevent a warning.
            Overwriting this will not do anything

        Returns
        ----------
        array_like: See superclass

        """
        unsorted_idxs = np.argsort(np.argsort(x))
        return super(UnsortedInterp2d, self).__call__(x, y, dx=dx, dy=dy, assume_sorted=False)[unsorted_idxs]


#  Instantiate the default argument parser at runtime 
开发者ID:lscsoft,项目名称:bilby,代码行数:25,代码来源:utils.py

示例13: _interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def _interpolate(x1, y1, z1, x2, y2):
    """Helper to interpolate in 1d or 2d

    We interpolate to get the same shape than with other methods.
    """
    if x1.size > 1 and y1.size > 1:
        func = interp2d(x1, y1, z1.T, kind='linear', bounds_error=False)
        z2 = func(x2, y2)
    elif x1.size == 1 and y1.size > 1:
        func = interp1d(y1, z1.ravel(), kind='linear', bounds_error=False)
        z2 = func(y2)
    elif y1.size == 1 and x1.size > 1:
        func = interp1d(x1, z1.ravel(), kind='linear', bounds_error=False)
        z2 = func(x2)
    else:
        raise ValueError("Can't interpolate a scalar.")

    # interp2d is not intuitive and return this shape:
    z2.shape = (y2.size, x2.size)
    return z2 
开发者ID:pactools,项目名称:pactools,代码行数:22,代码来源:comodulogram.py

示例14: test_interp2d

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def test_interp2d(self):
        y, x = mgrid[0:2:20j, 0:pi:21j]
        z = sin(x+0.5*y)
        I = interp2d(x, y, z)
        assert_almost_equal(I(1.0, 2.0), sin(2.0), decimal=2)

        v,u = ogrid[0:2:24j, 0:pi:25j]
        assert_almost_equal(I(u.ravel(), v.ravel()), sin(u+0.5*v), decimal=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_interpolate.py

示例15: get_concentration_functions

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp2d [as 别名]
def get_concentration_functions(composition_table_dict):

    meta = composition_table_dict["meta"]
    composition_table = Table.from_dict(composition_table_dict["data"])
    elements = [col for col in composition_table.columns if col not in meta]
    x = composition_table["X"].values
    y = composition_table["Y"].values
    cats = composition_table["X"].unique()
    concentration, conc, d, y_c, functions = {}, {}, {}, {}, RecursiveDict()

    for el in elements:
        concentration[el] = to_numeric(composition_table[el].values) / 100.0
        conc[el], d[el], y_c[el] = {}, {}, {}

        if meta["X"] == "category":
            for i in cats:
                k = "{:06.2f}".format(float(i))
                y_c[el][k] = to_numeric(y[where(x == i)])
                conc[el][k] = to_numeric(concentration[el][where(x == i)])
                d[el][k] = interp1d(y_c[el][k], conc[el][k])

            functions[el] = lambda a, b, el=el: d[el][a](b)

        else:
            functions[el] = interp2d(float(x), float(y), concentration[el])

    return functions 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:29,代码来源:pre_submission.py


注:本文中的scipy.interpolate.interp2d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。