當前位置: 首頁>>代碼示例>>Python>>正文


Python interpolate.LinearNDInterpolator方法代碼示例

本文整理匯總了Python中scipy.interpolate.LinearNDInterpolator方法的典型用法代碼示例。如果您正苦於以下問題:Python interpolate.LinearNDInterpolator方法的具體用法?Python interpolate.LinearNDInterpolator怎麽用?Python interpolate.LinearNDInterpolator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.interpolate的用法示例。


在下文中一共展示了interpolate.LinearNDInterpolator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _interpolator

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def _interpolator(points, coord_source, coord_target, method="idw"):

    coord_source_i, coord_source_j = coord_source
    coord_target_i, coord_target_j = coord_target

    # reshape
    trg = np.vstack((coord_source_i.ravel(), coord_source_j.ravel())).T
    src = np.vstack((coord_target_i.ravel(), coord_target_j.ravel())).T

    if method == "nearest":
        interpolator = NearestNDInterpolator(src, points.ravel(),
                                             tree_options={"balanced_tree": False})
        points_interpolated = interpolator(trg)
    elif method == "linear":
        interpolator = LinearNDInterpolator(src, points.ravel(), fill_value=0)
        points_interpolated = interpolator(trg)
    elif method == "idw":
        interpolator = ipol.Idw(src, trg)
        points_interpolated = interpolator(points.ravel())

    # reshape output
    points_interpolated = points_interpolated.reshape(points.shape)

    return points_interpolated.astype(points.dtype) 
開發者ID:hydrogo,項目名稱:rainymotion,代碼行數:26,代碼來源:models.py

示例2: interpolate_look_angles

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def interpolate_look_angles(data):
    log.info('Interpolating look angles from radar coordinates...')
    log.debug('Radar coordinates extent width %d; length %d',
              data.px_width, data.px_length)
    log.debug('Radar coordinates data: length %d - %d; width %d - %d',
              data.radar_coords[1].min(), data.radar_coords[1].max(),
              data.radar_coords[0].min(), data.radar_coords[0].max())
    log.debug('Binned radar coordinate ranges: length %d - %d; width %d - %d',
              num.nanmin(data.bin_radar_i), num.nanmax(data.bin_radar_i),
              num.nanmin(data.bin_radar_j), num.nanmax(data.bin_radar_j))

    width_coords = num.linspace(0, data.px_width, 50)
    len_coords = num.linspace(0, data.px_length, 50)
    coords = num.asarray(num.meshgrid(width_coords, len_coords))\
        .reshape(2, 2500)

    radar_coords = num.vstack(
        [data.bin_radar_j.ravel() - data.radar_coords[0].min(),
         data.bin_radar_i.ravel() - data.radar_coords[1].min()])

    interp = interpolate.LinearNDInterpolator(coords.T, data.look_angles)
    data.bin_look_angles = interp(radar_coords.T).reshape(
        *data.bin_ps_mean_v.shape)
    return interp 
開發者ID:pyrocko,項目名稱:kite,代碼行數:26,代碼來源:stamps2kite.py

示例3: areas

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def areas(ip):
    """Returns the area per triangle of the triangulation inside
    a `LinearNDInterpolator` instance.

    Is useful when defining custom loss functions.

    Parameters
    ----------
    ip : `scipy.interpolate.LinearNDInterpolator` instance

    Returns
    -------
    areas : numpy.ndarray
        The area per triangle in ``ip.tri``.
    """
    p = ip.tri.points[ip.tri.vertices]
    q = p[:, :-1, :] - p[:, -1, None, :]
    areas = abs(q[:, 0, 0] * q[:, 1, 1] - q[:, 0, 1] * q[:, 1, 0]) / 2
    return areas 
開發者ID:python-adaptive,項目名稱:adaptive,代碼行數:21,代碼來源:learner2D.py

示例4: default_loss

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def default_loss(ip):
    """Loss function that combines `deviations` and `areas` of the triangles.

    Works with `~adaptive.Learner2D` only.

    Parameters
    ----------
    ip : `scipy.interpolate.LinearNDInterpolator` instance

    Returns
    -------
    losses : numpy.ndarray
        Loss per triangle in ``ip.tri``.
    """
    dev = np.sum(deviations(ip), axis=0)
    A = areas(ip)
    losses = dev * np.sqrt(A) + 0.3 * A
    return losses 
開發者ID:python-adaptive,項目名稱:adaptive,代碼行數:20,代碼來源:learner2D.py

示例5: impute_atmosphere_grid

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def impute_atmosphere_grid(self, grid):
        """
        This function imputes the passed atmosphere grid by linear N-D interpolation.
        As grid is passed by reference, it is not necessary to re-assign the table to
        the return value of this function; the return value is provided for convenience
        only, but the grid is changed in place.
        """

        valid_mask = ~np.isnan(grid[...,0])
        coords = np.array(np.nonzero(valid_mask)).T
        values = grid[valid_mask][:,0]
        it = interpolate.LinearNDInterpolator(coords, values, fill_value=0)
        filled = it(list(np.ndindex(grid[...,0].shape))).reshape(grid[...,0].shape)
        filled[filled==0] = np.nan
        grid[...,0] = filled
        return grid 
開發者ID:phoebe-project,項目名稱:phoebe2,代碼行數:18,代碼來源:passbands.py

示例6: _initialize_distance_interpolator_flat

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def _initialize_distance_interpolator_flat(self, layer):
        self._layer = layer
        self.triangulate_layer_flat(layer=self._layer)

        self._interpolator = [None, None]
        for side in [0, 1]:
            self._interpolator[side] = LinearNDInterpolator(
                self.surf_triang[side], self.triangulation_points[side][:, 2]) 
開發者ID:Marcello-Sega,項目名稱:pytim,代碼行數:10,代碼來源:surface.py

示例7: lin_interp

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def lin_interp(shape, xyd):
    # taken from https://github.com/hunse/kitti
    from scipy.interpolate import LinearNDInterpolator
    m, n = shape
    ij, d = xyd[:, 1::-1], xyd[:, 2]
    f = LinearNDInterpolator(ij, d, fill_value=0)
    J, I = np.meshgrid(np.arange(n), np.arange(m))
    IJ = np.vstack([I.flatten(), J.flatten()]).T
    disparity = f(IJ).reshape(shape)
    return disparity 
開發者ID:hlzz,項目名稱:DeepMatchVO,代碼行數:12,代碼來源:depth_evaluation_utils.py

示例8: bellman_operator

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def bellman_operator(self, v):
        """

        The Bellman operator.  Including for comparison. Value function
        iteration is not recommended for this problem.  See the
        reservation wage operator below.

        Parameters
        ----------
        v : array_like(float, ndim=1, length=len(π_grid))
            An approximate value function represented as a
            one-dimensional array.

        Returns
        -------
        new_v : array_like(float, ndim=1, length=len(π_grid))
            The updated value function

        """
        # == Simplify names == #
        f, g, β, c, q = self.f, self.g, self.β, self.c, self.q

        vf = LinearNDInterpolator(self.grid_points, v)
        N = len(v)
        new_v = np.empty(N)

        for i in range(N):
            w, π = self.grid_points[i, :]
            v1 = w / (1 - β)
            integrand = lambda m: vf(m, q(m, π)) * (π * f(m)
                                                     + (1 - π) * g(m))
            integral, error = fixed_quad(integrand, 0, self.w_max)
            v2 = c + β * integral
            new_v[i] = max(v1, v2)

        return new_v 
開發者ID:QuantEcon,項目名稱:QuantEcon.lectures.code,代碼行數:38,代碼來源:odu.py

示例9: get_greedy

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def get_greedy(self, v):
        """
        Compute optimal actions taking v as the value function.

        Parameters
        ----------
        v : array_like(float, ndim=1, length=len(π_grid))
            An approximate value function represented as a
            one-dimensional array.

        Returns
        -------
        policy : array_like(float, ndim=1, length=len(π_grid))
            The decision to accept or reject an offer where 1 indicates
            accept and 0 indicates reject

        """
        # == Simplify names == #
        f, g, β, c, q = self.f, self.g, self.β, self.c, self.q

        vf = LinearNDInterpolator(self.grid_points, v)
        N = len(v)
        policy = np.zeros(N, dtype=int)

        for i in range(N):
            w, π = self.grid_points[i, :]
            v1 = w / (1 - β)
            integrand = lambda m: vf(m, q(m, π)) * (π * f(m) +
                                                     (1 - π) * g(m))
            integral, error = fixed_quad(integrand, 0, self.w_max)
            v2 = c + β * integral
            policy[i] = v1 > v2  # Evaluates to 1 or 0

        return policy 
開發者ID:QuantEcon,項目名稱:QuantEcon.lectures.code,代碼行數:36,代碼來源:odu.py

示例10: make_linear_interpolator_unstructured

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def make_linear_interpolator_unstructured(field, grid=None, fill_value=np.nan):
	'''Make a linear interpolator for an unstructured grid.

	Parameters
	----------
	field : Field or array_like
		The field to interpolate.
	grid : Grid or None
		The grid of the field. If it is given, the grid of `field` is replaced by this grid.
	fill_value : scalar
		The value to use for points outside of the domain of the input field. Extrapolation is not supported.

	Returns
	-------
	Field generator
		The interpolator as a Field generator. The grid on which this field generator will be evaluated does
		not need to have any structure.
	'''
	if fill_value is None:
		raise ValueError('Extrapolation is not supported for a linear interpolator on an unstructured grid.')

	if grid is None:
		grid = field.grid
	else:
		field = Field(field, grid)

	interp = LinearNDInterpolator(grid.points, field, fill_value)

	def interpolator(evaluated_grid):
		res = interp(grid.points)
		return Field(res, evaluated_grid)

	return interpolator 
開發者ID:ehpor,項目名稱:hcipy,代碼行數:35,代碼來源:linear.py

示例11: build_interpolator

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def build_interpolator(self, dem_proc):
        # Build an interpolator
        gc = dem_proc.elev.grid_coordinates
#       points = np.meshgrid(gc.x_axis, gc.y_axis)
#       points = np.column_stack([pts.ravel() for pts in points])
#       interp = spinterp.NearestNDInterpolator(points, dem_proc.data.ravel())
#       interp = spinterp.LinearNDInterpolator(points, np.ravel(dem_proc.data),
#                                               fill_value=np.nan)
        interp = spinterp.interpolate.RegularGridInterpolator(
            points=(gc.y_axis[::-1], gc.x_axis),
            values=dem_proc.data[::-1, :].astype(float),
            method='nearest', fill_value=np.nan, bounds_error=False)
        return interp 
開發者ID:creare-com,項目名稱:pydem,代碼行數:15,代碼來源:processing_manager.py

示例12: __init__

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def __init__(self, filename, verbose=1):
        """
        Initialisation of class to load templates from a file and create the interpolation
        objects

        Parameters
        ----------
        filename: string
            Location of Template file
        verbose: int
            Verbosity level,
            0 = no logging
            1 = File + interpolation point information
            2 = Detailed description of interpolation points
        """
        self.verbose = verbose
        if self.verbose:
            print("Loading lookup tables from", filename)

        grid, bins, template = self.parse_fits_table(filename)
        x_bins, y_bins = bins

        self.interpolator = interpolate.LinearNDInterpolator(
            grid, template, fill_value=0
        )
        self.nearest_interpolator = interpolate.NearestNDInterpolator(grid, template)

        self.grid_interp = interpolate.RegularGridInterpolator(
            (x_bins, y_bins),
            np.zeros([x_bins.shape[0], y_bins.shape[0]]),
            method="linear",
            bounds_error=False,
            fill_value=0,
        ) 
開發者ID:cta-observatory,項目名稱:ctapipe,代碼行數:36,代碼來源:table_interpolator.py

示例13: test_linear_nd

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def test_linear_nd():
    """
    In its simplest configuration this code should behave exactly the same as the scipy
    LinearNDInterpolator, so lets test that
    """

    # First set up 4 grid points and fill them randomly
    interpolation_points = {
        (0, 0): np.random.rand(2, 2),
        (0, 1): np.random.rand(2, 2),
        (1, 0): np.random.rand(2, 2),
        (1, 1): np.random.rand(2, 2),
    }

    # Create UnstructuredInterpolator and LinearNDInterpolator with these points
    interpolator = UnstructuredInterpolator(interpolation_points)
    linear_nd = LinearNDInterpolator(
        list(interpolation_points.keys()), list(interpolation_points.values())
    )

    # Create some random coordinates in this space
    points = np.random.rand(10, 2)
    # And interpolate...
    interpolated_points = interpolator(points)
    linear_nd_points = linear_nd(points)

    # Check everything agrees to a reasonable precision
    assert np.all(np.abs(interpolated_points - linear_nd_points) < 1e-10) 
開發者ID:cta-observatory,項目名稱:ctapipe,代碼行數:30,代碼來源:test_unstructured_interpolator.py

示例14: test_remember_last

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def test_remember_last():
    """
    Check we get the same answer when using masked arrays
    """

    # First set up 4 grid points and fill them randomly
    interpolation_points = {
        (0, 0): np.random.rand(2, 2),
        (0, 1): np.random.rand(2, 2),
        (1, 0): np.random.rand(2, 2),
        (1, 1): np.random.rand(2, 2),
    }

    # Create UnstructuredInterpolator and LinearNDInterpolator with these points
    interpolator = UnstructuredInterpolator(interpolation_points, remember_last=True)

    # Create some random coordinates in this space
    random_nums = np.random.rand(2, 2)
    points_mask = ma.masked_array(random_nums, mask=[[True, False], [True, False]])

    # And interpolate...
    interpolated_points = interpolator(random_nums).T[0]
    interpolated_points_mask = interpolator(points_mask).T[0]

    # Check everything agrees to a reasonable precision
    assert np.all(np.abs(interpolated_points - interpolated_points_mask) < 1e-10) 
開發者ID:cta-observatory,項目名稱:ctapipe,代碼行數:28,代碼來源:test_unstructured_interpolator.py

示例15: test_masked_input

# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import LinearNDInterpolator [as 別名]
def test_masked_input():
    """
    Now lets test how well this all works if we pass a masked input
    """

    # First set up 4 grid points and fill them randomly
    interpolation_points = {
        (0, 0): np.random.rand(2, 2),
        (0, 1): np.random.rand(2, 2),
        (1, 0): np.random.rand(2, 2),
        (1, 1): np.random.rand(2, 2),
    }

    # Create UnstructuredInterpolator and LinearNDInterpolator with these points
    interpolator = UnstructuredInterpolator(interpolation_points, remember_last=True)
    linear_nd = LinearNDInterpolator(
        list(interpolation_points.keys()), list(interpolation_points.values())
    )

    # Create some random coordinates in this space
    points = np.random.rand(10, 2)
    # And interpolate...
    interpolator(points)
    interpolated_points = interpolator(points)

    linear_nd_points = linear_nd(points)

    # Check everything agrees to a reasonable precision
    assert np.all(np.abs(interpolated_points - linear_nd_points) < 1e-10) 
開發者ID:cta-observatory,項目名稱:ctapipe,代碼行數:31,代碼來源:test_unstructured_interpolator.py


注:本文中的scipy.interpolate.LinearNDInterpolator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。