當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。