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


Python interpolate.RectBivariateSpline方法代码示例

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


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

示例1: __init__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def __init__(self, scale_list, values, extrapolate=False):
        # error checking
        if len(values.shape) != 2:
            raise ValueError('This class only works for 2D data.')
        elif len(scale_list) != 2:
            raise ValueError('input and output dimension mismatch.')

        nx, ny = values.shape
        offset, scale = scale_list[0]
        x = np.linspace(offset, (nx - 1) * scale + offset, nx)  # type: np.multiarray.ndarray
        offset, scale = scale_list[1]
        y = np.linspace(offset, (ny - 1) * scale + offset, ny)  # type: np.multiarray.ndarray

        self._min = x[0], y[0]
        self._max = x[-1], y[-1]

        DiffFunction.__init__(self, [(x[0], x[-1]), (y[0], y[-1])], delta_list=None)

        self.fun = interp.RectBivariateSpline(x, y, values)
        self._extrapolate = extrapolate 
开发者ID:ucb-art,项目名称:BAG_framework,代码行数:22,代码来源:interpolate.py

示例2: _get_above_cloud_profiles

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def _get_above_cloud_profiles(self, P_profile, T_profile, abundances,
                                  planet_mass, planet_radius, star_radius,
                                  above_cloud_cond, T_star=None):
        
        assert(len(P_profile) == len(T_profile))
        # First, get atmospheric weight profile
        mu_profile = np.zeros(len(P_profile))
        atm_abundances = {}
        
        for species_name in abundances:
            interpolator = RectBivariateSpline(
                self.T_grid, np.log10(self.P_grid),
                np.log10(abundances[species_name]), kx=1, ky=1)
            abund = 10**interpolator.ev(T_profile, np.log10(P_profile))
            atm_abundances[species_name] = abund
            mu_profile += abund * self.mass_data[species_name]

        radii, dr = _hydrostatic_solver._solve(
            P_profile, T_profile, self.ref_pressure, mu_profile, planet_mass,
            planet_radius, star_radius, above_cloud_cond, T_star)
        
        for key in atm_abundances:
            atm_abundances[key] = atm_abundances[key][above_cloud_cond]
            
        return radii, dr, atm_abundances, mu_profile 
开发者ID:ideasrule,项目名称:platon,代码行数:27,代码来源:_atmosphere_solver.py

示例3: test_baffle_leakage_Bell_refit

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def test_baffle_leakage_Bell_refit():
    from ht.conv_tube_bank import Bell_baffle_leakage_tck
    # Test refitting the data
    obj = RectBivariateSpline(Bell_baffle_leakage_x, Bell_baffle_leakage_z_values, Bell_baffle_leakage_zs, kx=3, ky=1, s=0.002)
    new_tck = obj.tck + obj.degrees
    [assert_allclose(i, j) for (i, j) in zip(Bell_baffle_leakage_tck, new_tck)]


#import matplotlib.pyplot as plt
#for ys in Bell_baffle_leakage_zs.T:
#    plt.plot(Bell_baffle_leakage_x, ys)
#for z in Bell_baffle_leakage_z_values:
#    xs = np.linspace(min(Bell_baffle_leakage_x), max(Bell_baffle_leakage_x), 1000)
#    ys = np.clip(Bell_baffle_leakage_obj(xs, z), 0, 1)
#    plt.plot(xs, ys, '--')
#
#for z in Bell_baffle_leakage_z_values:
#    xs = np.linspace(min(Bell_baffle_leakage_x), max(Bell_baffle_leakage_x), 1000)
#    rs = z
#    rl = xs
#    ys = 0.44*(1.0 - rs) + (1.0 - 0.44*(1.0 - rs))*np.exp(-2.2*rl)
#    plt.plot(xs, ys, '--') 
开发者ID:CalebBell,项目名称:ht,代码行数:24,代码来源:test_conv_tube_bank.py

示例4: get_elevation

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def get_elevation(self, interpolation='nearest_neighbor'):
        assert interpolation in ('nearest_neighbor', 'bivariate')

        if self._elevation.get(interpolation, None) is None:
            self._log.debug('Getting elevation...')
            # region = llLon, urLon, llLat, urLon
            coords = self.frame.coordinates
            lons = coords[:, 0]
            lats = coords[:, 1]

            region = (lons.min(), lons.max(), lats.min(), lats.max())
            if not srtmgl3.covers(region):
                raise AssertionError(
                    'Region is outside of SRTMGL3 topo dataset')

            tile = srtmgl3.get(region)
            if not tile:
                raise AssertionError('Cannot get SRTMGL3 topo dataset')

            if interpolation == 'nearest_neighbor':
                iy = num.rint((lats - tile.ymin) / tile.dy).astype(num.intp)
                ix = num.rint((lons - tile.xmin) / tile.dx).astype(num.intp)

                elevation = tile.data[(iy, ix)]

            elif interpolation == 'bivariate':
                interp = interpolate.RectBivariateSpline(
                    tile.y(), tile.x(), tile.data)
                elevation = interp(lats, lons, grid=False)

            elevation = elevation.reshape(self.rows, self.cols)
            self._elevation[interpolation] = elevation

        return self._elevation[interpolation] 
开发者ID:pyrocko,项目名称:kite,代码行数:36,代码来源:scene.py

示例5: test_dblint

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def test_dblint():
    # Basic test to see it runs and gives the correct result on a trivial
    # problem.  Note that `dblint` is not exposed in the interpolate namespace.
    x = np.linspace(0, 1)
    y = np.linspace(0, 1)
    xx, yy = np.meshgrid(x, y)
    rect = interpolate.RectBivariateSpline(x, y, 4 * xx * yy)
    tck = list(rect.tck)
    tck.extend(rect.degrees)

    assert_almost_equal(dblint(0, 1, 0, 1, tck), 1)
    assert_almost_equal(dblint(0, 0.5, 0, 1, tck), 0.25)
    assert_almost_equal(dblint(0.5, 1, 0, 1, tck), 0.75)
    assert_almost_equal(dblint(-100, 100, -100, 100, tck), 1) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:test_fitpack.py

示例6: interpolate_2d_features

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def interpolate_2d_features(features):
    out_size = feature_size
    x = np.arange(features.shape[0])
    y = np.arange(features.shape[1])
    z = features
    xx = np.linspace(x.min(), x.max(), out_size)
    yy = np.linspace(y.min(), y.max(), out_size)
    new_kernel = interpolate.RectBivariateSpline(x, y, z, kx=1, ky=1)
    kernel_out = new_kernel(xx, yy)
    return kernel_out


# Interpolation 2d of each channel, so we obtain 3d interpolated feature maps 
开发者ID:imatge-upc,项目名称:detection-2016-nipsws,代码行数:15,代码来源:features.py

示例7: _updatePlasmaPsi

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def _updatePlasmaPsi(self, plasma_psi):
        """
        Sets the plasma psi data, updates spline interpolation coefficients.
        Also updates:

        self.mask        2D (R,Z) array which is 1 in the core, 0 outside
        self.psi_axis    Value of psi on the magnetic axis
        self.psi_bndry   Value of psi on plasma boundary
        """
        self.plasma_psi = plasma_psi

        # Update spline interpolation
        self.psi_func = interpolate.RectBivariateSpline(self.R[:,0], self.Z[0,:], plasma_psi)

        # Update the locations of the X-points, core mask, psi ranges.
        # Note that this may fail if there are no X-points, so it should not raise an error
        # Analyse the equilibrium, finding O- and X-points
        psi = self.psi()
        opt, xpt = critical.find_critical(self.R, self.Z, psi)
        if opt:
            self.psi_axis = opt[0][2]

            if xpt:
                self.psi_bndry = xpt[0][2]
                self.mask = critical.core_mask(self.R, self.Z, psi, opt, xpt)
                
                # Use interpolation to find if a point is in the core.
                self.mask_func = interpolate.RectBivariateSpline(self.R[:,0], self.Z[0,:], self.mask)
            else:
                self.psi_bndry = None
                self.mask = None 
开发者ID:bendudson,项目名称:freegs,代码行数:33,代码来源:equilibrium.py

示例8: test_Nu_Grimison_tube_bank_tcks

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def test_Nu_Grimison_tube_bank_tcks():
    from ht.conv_tube_bank import Grimison_ST_aligned, Grimison_SL_aligned, Grimison_C1_aligned, Grimison_C1_aligned_tck
    Grimison_C1_aligned_interp = RectBivariateSpline(Grimison_ST_aligned, 
                                                     Grimison_SL_aligned,
                                                     np.array(Grimison_C1_aligned))

    tck_recalc = Grimison_C1_aligned_interp.tck
    [assert_allclose(i, j) for i, j in zip(Grimison_C1_aligned_tck, tck_recalc)]
    
    from ht.conv_tube_bank import Grimison_m_aligned_tck, Grimison_m_aligned
    Grimison_m_aligned_interp = RectBivariateSpline(Grimison_ST_aligned, 
                                                    Grimison_SL_aligned, 
                                                    np.array(Grimison_m_aligned))
    tck_recalc = Grimison_m_aligned_interp.tck
    [assert_allclose(i, j) for i, j in zip(Grimison_m_aligned_tck, tck_recalc)] 
开发者ID:CalebBell,项目名称:ht,代码行数:17,代码来源:test_conv_tube_bank.py

示例9: _get_orthrectified_from_array_flat

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def _get_orthrectified_from_array_flat(self, ortho_bounds, row_array, col_array, value_array):
        # setup the result workspace
        value_array, pixel_rows, pixel_cols, ortho_array = self._setup_flat_workspace(
            ortho_bounds, row_array, col_array, value_array)
        value_array = self._apply_radiometric_params(row_array, col_array, value_array)

        # set up our spline
        sp = RectBivariateSpline(row_array, col_array, value_array, kx=self.row_order, ky=self.col_order, s=0)
        # determine the in bounds points
        mask = self._get_mask(pixel_rows, pixel_cols, row_array, col_array)
        result = sp.ev(pixel_rows[mask], pixel_cols[mask])
        # potentially apply the radiometric parameters
        ortho_array[mask] = result
        return ortho_array 
开发者ID:ngageoint,项目名称:sarpy,代码行数:16,代码来源:ortho_rectify.py

示例10: make_cached_spline_builder

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def make_cached_spline_builder(smooth):

    @lru_cache(4)  # 4 means our tests are quick (and should tile a local patch)
    def cached_spline_builder(dir, flat, flon):
        h = cached_file_reader(dir, flat, flon)
        x, y = np.linspace(flat, flat+1, SAMPLES), np.linspace(flon, flon+1, SAMPLES)
        # not 100% sure on the scaling of s but it seems to be related to sum of errors at all points
        # however, a scaling of SAMPLES * SAMPLES means that smooth=1 gives a numerical error, so add 10
        return RectBivariateSpline(x, y, h, s=smooth * SAMPLES * SAMPLES * 10)

    return cached_spline_builder 
开发者ID:andrewcooke,项目名称:choochoo,代码行数:13,代码来源:spline.py

示例11: interpolate_zvals_at_xy

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def interpolate_zvals_at_xy(xy, topography, method='interp2d'):
        """
        Interpolates DEM values on a defined section

        Args:
            xy: x (EW) and y (NS) coordinates of the profile
            topography (:class:`gempy.core.grid_modules.topography.Topography`)
            method: interpolation method, 'interp2d' for cubic scipy.interpolate.interp2d
                                             'spline' for scipy.interpolate.RectBivariateSpline

        Returns:
            numpy.ndarray: z values, i.e. topography along the profile

        """

        xj = topography.values_2d[:, 0, 0]
        yj = topography.values_2d[0, :, 1]
        zj = topography.values_2d[:, :, 2]

        if method == 'interp2d':
            f = interpolate.interp2d(xj, yj, zj.T, kind='cubic')
            zi = f(xy[:, 0], xy[:, 1])
            if xy[:, 0][0] <= xy[:, 0][-1] and xy[:, 1][0] <= xy[:, 1][-1]:
                return np.diag(zi)
            else:
                return np.flipud(zi).diagonal()
        else:
            assert xy[:, 0][0] <= xy[:, 0][-1], 'The xy values of the first point must be smaller than second.' \
                                               'Please use interp2d as method argument. Will be fixed.'
            assert xy[:, 1][0] <= xy[:, 1][-1], 'The xy values of the first point must be smaller than second.' \
                                               'Please use interp2d as method argument. Will be fixed.'
            f = interpolate.RectBivariateSpline(xj, yj, zj)
            zi = f(xy[:, 0], xy[:, 1])
            return np.flipud(zi).diagonal() 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:36,代码来源:grid_types.py

示例12: __init__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def __init__(self, ttfile, datum):
        with open(ttfile, 'r') as f:
            count = 0
            for line in f:
                if count == 0:
                    count += 1
                    continue
                elif count == 1:
                    n_dist, n_depth = line.split()
                    n_dist = int(n_dist)
                    n_depth = int(n_depth)
                    dists = np.zeros(n_dist)
                    tt = np.zeros((n_depth, n_dist))
                    count += 1
                    continue
                elif count == 2:
                    depths = line.split()
                    depths = np.array([float(x) for x in depths])
                    count += 1
                    continue
                else:
                    temp = line.split()
                    temp = np.array([float(x) for x in temp])
                    dists[count-3] = temp[0]
                    tt[:, count-3] = temp[1:]
                    count += 1
        self.tt = tt
        self.dists = dists
        self.depths = depths
        self.datum = datum

        from scipy.interpolate import RectBivariateSpline
        self.interp_ = RectBivariateSpline(self.depths, self.dists, self.tt) 
开发者ID:interseismic,项目名称:PhaseLink,代码行数:35,代码来源:phaselink_dataset.py

示例13: __init__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def __init__(self, inp_img):
        self.ndim = 2

        # Load up the image (greyscale) and filter to soften it up
        img = median_filter(imread(inp_img, flatten=True), 5)

        # Convert 'ij' indexing to 'xy' coordinates
        self.img = np.flipud(img).T
        self._lower_left = np.array([0., 0.])
        self._upper_right = self.img.shape

        # Construct a spline interpolant to use as a target
        x = np.arange(self._lower_left[0], self._upper_right[0], 1)
        y = np.arange(self._lower_left[1], self._upper_right[1], 1)
        self._interpolant = RectBivariateSpline(x, y, self.img) 
开发者ID:bfarr,项目名称:kombine,代码行数:17,代码来源:twoD.py

示例14: cartesian_to_polar

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def cartesian_to_polar(
    interpolated_data_cartesian: ndarray,
    extent_cartesian: Tuple[float, float, float, float],
) -> Tuple[ndarray, Tuple[float, float, float, float]]:
    """Convert interpolated Cartesian pixel grid to polar coordinates.

    Parameters
    ----------
    interpolated_data_cartesian
        The interpolated data on a Cartesian grid.
    extent_cartesian
        The extent in Cartesian space as (xmin, xmax, ymin, ymax). It
        must be square.

    Returns
    -------
    interpolated_data_polar
        The interpolated data on a polar grid (R, phi).
    extent_polar
        The extent on a polar grid (0, Rmax, 0, 2π).
    """
    data, extent = interpolated_data_cartesian, extent_cartesian

    if not np.allclose(extent[1] - extent[0], extent[3] - extent[2]):
        raise ValueError('Bad polar plot: x and y have different scales')

    number_of_pixels = data.shape
    radius_pix = 0.5 * data.shape[0]

    data = transform.warp_polar(data, radius=radius_pix)

    radius = 0.5 * (extent[1] - extent[0])
    extent_polar = (0, radius, 0, 2 * np.pi)

    x_grid = np.linspace(*extent[:2], data.shape[0])
    y_grid = np.linspace(*extent[2:], data.shape[1])
    spl = RectBivariateSpline(x_grid, y_grid, data)
    x_regrid = np.linspace(extent[0], extent[1], number_of_pixels[0])
    y_regrid = np.linspace(extent[2], extent[3], number_of_pixels[1])
    interpolated_data_polar = spl(x_regrid, y_regrid)

    return interpolated_data_polar, extent_polar 
开发者ID:dmentipl,项目名称:plonk,代码行数:44,代码来源:geometry.py

示例15: newDomain

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import RectBivariateSpline [as 别名]
def newDomain(eq,
              Rmin=None, Rmax=None,
              Zmin=None, Zmax=None,
              nx=None, ny=None):
    """Creates a new Equilibrium, solving in a different domain.
    The domain size (Rmin, Rmax, Zmin, Zmax) and resolution (nx,ny)
    are taken from the input equilibrium eq if not specified.
    """
    if Rmin is None:
        Rmin = eq.Rmin
    if Rmax is None:
        Rmax = eq.Rmax
    if Zmin is None:
        Zmin = eq.Zmin
    if Zmax is None:
        Zmax = eq.Zmax
    if nx is None:
        nx = eq.R.shape[0]
    if ny is None:
        ny = eq.R.shape[0]

    # Create a new equilibrium with the new domain
    result = Equilibrium(tokamak=eq.tokamak,
                         Rmin = Rmin,
                         Rmax = Rmax,
                         Zmin = Zmin,
                         Zmax = Zmax,
                         nx=nx, ny=ny)

    # Calculate the current on the old grid
    profiles = eq._profiles
    Jtor = profiles.Jtor(eq.R, eq.Z, eq.psi())

    # Interpolate Jtor onto new grid
    Jtor_func = interpolate.RectBivariateSpline(eq.R[:,0], eq.Z[0,:], Jtor)
    Jtor_new = Jtor_func(result.R, result.Z, grid=False)

    result._applyBoundary(result, Jtor_new, result.plasma_psi)

    # Right hand side of G-S equation
    rhs = -mu0 * result.R * Jtor_new

    # Copy boundary conditions
    rhs[0,:] = result.plasma_psi[0,:]
    rhs[:,0] = result.plasma_psi[:,0]
    rhs[-1,:] = result.plasma_psi[-1,:]
    rhs[:,-1] = result.plasma_psi[:,-1]

    # Call elliptic solver
    plasma_psi = result._solver(result.plasma_psi, rhs)
        
    result._updatePlasmaPsi(plasma_psi)

    # Solve once more, calculating Jtor using new psi
    result.solve(profiles)
    
    return result 
开发者ID:bendudson,项目名称:freegs,代码行数:59,代码来源:equilibrium.py


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