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


Python interpolate.Rbf方法代码示例

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


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

示例1: test_rbf_profile

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def test_rbf_profile(self, simple_linear_model, min_value, max_value):
        """Test the Rbf profile parameter."""

        m = simple_linear_model
        m.timestepper.start = '2015-01-01'
        m.timestepper.end = '2015-12-31'

        # The Rbf parameter should mirror the input data at the start and end to create roughly
        # consistent gradients across the end of year boundary.
        interp_days_of_year = [-65, 1, 100, 200, 300, 366, 465]
        interp_values = [0.2, 0.5, 0.7, 0.5, 0.2, 0.5, 0.7]

        expected_values = Rbf(interp_days_of_year, interp_values)(np.arange(365) + 1)

        data = {
            'type': 'rbfprofile',
            "days_of_year": [1, 100, 200, 300],
            "values": [0.5, 0.7, 0.5, 0.2],
        }
        if min_value is not None:
            data["min_value"] = min_value
        if max_value is not None:
            data["max_value"] = max_value

        p = load_parameter(m, data)

        @assert_rec(m, p)
        def expected_func(timestep, scenario_index):
            ev = expected_values[timestep.index]
            if min_value is not None:
                ev = max(min_value, ev)
            if max_value is not None:
                ev = min(max_value, ev)
            return ev

        m.run() 
开发者ID:pywr,项目名称:pywr,代码行数:38,代码来源:test_parameters.py

示例2: _plot

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def _plot(self, a, key, title, gx, gy, num_x, num_y):
        pp.rcParams['figure.figsize'] = (
            self._image_width / 300, self._image_height / 300
        )
        pp.title(title)
        # Interpolate the data
        rbf = Rbf(
            a['x'], a['y'], a[key], function='linear'
        )
        z = rbf(gx, gy)
        z = z.reshape((num_y, num_x))
        # Render the interpolated data to the plot
        pp.axis('off')
        # begin color mapping
        norm = matplotlib.colors.Normalize(
            vmin=min(a[key]), vmax=max(a[key]), clip=True
        )
        mapper = cm.ScalarMappable(norm=norm, cmap='RdYlBu_r')
        # end color mapping
        image = pp.imshow(
            z,
            extent=(0, self._image_width, self._image_height, 0),
            cmap='RdYlBu_r', alpha=0.5, zorder=100
        )
        pp.colorbar(image)
        pp.imshow(self._layout, interpolation='bicubic', zorder=1, alpha=1)
        # begin plotting points
        for idx in range(0, len(a['x'])):
            pp.plot(
                a['x'][idx], a['y'][idx],
                marker='o', markeredgecolor='black', markeredgewidth=1,
                markerfacecolor=mapper.to_rgba(a[key][idx]), markersize=6
            )
        # end plotting points
        fname = '%s_%s.png' % (key, self._title)
        logger.info('Writing plot to: %s', fname)
        pp.savefig(fname, dpi=300)
        pp.close('all') 
开发者ID:jantman,项目名称:python-wifi-survey-heatmap,代码行数:40,代码来源:heatmap.py

示例3: polyrbf

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def polyrbf(self):
        xs, xa = np.meshgrid(self.size.astype(float), self.alpha)
        polyrbf = Rbf(xs.ravel(), xa.ravel(), self.crit_table.T.ravel(),function='linear')
        return polyrbf 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:tabledist.py

示例4: crit3

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def crit3(self, prob, n):
        '''returns interpolated quantiles, similar to ppf or isf

        uses Rbf to interpolate critical values as function of `prob` and `n`

        Parameters
        ----------
        prob : array_like
            probabilities corresponding to the definition of table columns
        n : int or float
            sample size, second parameter of the table

        Returns
        -------
        ppf : array_like
            critical values with same shape as prob, returns nan for arguments
            that are outside of the table bounds

        '''
        prob = np.asarray(prob)
        alpha = self.alpha

        #vectorized
        cond_ilow = (prob > alpha[0])
        cond_ihigh = (prob < alpha[-1])
        cond_interior = np.logical_or(cond_ilow, cond_ihigh)

        #scalar
        if prob.size == 1:
            if cond_interior:
                return self.polyrbf(n, prob)
            else:
                return np.nan

        #vectorized
        quantile = np.nan * np.ones(prob.shape) #nans for outside

        quantile[cond_interior] = self.polyrbf(n, prob[cond_interior])
        return quantile 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:41,代码来源:tabledist.py

示例5: compute_latency_from_lookup_table

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def compute_latency_from_lookup_table(network_def, lookup_table_path):
    '''
        Compute the latency of all layers defined in `network_def` (only including Conv and FC).
        
        When the value of latency is not in the lookup table, that value would be interpolated.
        
        Input:
            `network_def`: defined in get_network_def_from_model()
            `lookup_table_path`: (string) path to lookup table
        
        Output: 
            `latency`: (float) latency
    '''
    latency = .0 
    with open(lookup_table_path, 'rb') as file_id:
        lookup_table = pickle.load(file_id)
    for layer_name, layer_properties in network_def.items():
        if layer_name not in lookup_table.keys():
            raise ValueError('Layer name {} in network def not found in lookup table'.format(layer_name))
            break
        num_in_channels  = layer_properties[KEY_NUM_IN_CHANNELS]
        num_out_channels = layer_properties[KEY_NUM_OUT_CHANNELS]
        if (num_in_channels, num_out_channels) in lookup_table[layer_name][KEY_LATENCY].keys():
            latency += lookup_table[layer_name][KEY_LATENCY][(num_in_channels, num_out_channels)]
        else:
            # Not found in the lookup table, then interpolate the latency
            feature_samples = np.array(list(lookup_table[layer_name][KEY_LATENCY].keys()))
            feature_samples_in  = feature_samples[:, 0]
            feature_samples_out = feature_samples[:, 1]
            measurement = np.array(list(lookup_table[layer_name][KEY_LATENCY].values()))
            assert feature_samples_in.shape == feature_samples_out.shape
            assert feature_samples_in.shape == measurement.shape
            rbf = Rbf(feature_samples_in, feature_samples_out, \
                      measurement, function='cubic')
            num_in_channels = np.array([num_in_channels])
            num_out_channels = np.array([num_out_channels])
            estimated_latency = rbf(num_in_channels, num_out_channels)
            latency += estimated_latency[0]
    return latency 
开发者ID:denru01,项目名称:netadapt,代码行数:41,代码来源:functions.py

示例6: generate_deformation_field_rbf

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def generate_deformation_field_rbf(shape, points, max_deform=DEFORMATION_MAX,
                                   nb_bound_points=25):
    """ generate deformation field as thin plate spline  deformation
    in range +/- max_deform

    :param tuple(int,int) shape: tuple of size 2
    :param points: np.array<nb_points, 2> list of landmarks
    :param float max_deform: maximal deformation distance in any direction
    :param int nb_bound_points: number of fix boundary points
    :return: np.array<shape>
    """
    # x_point = points[:, 0]
    # y_point = points[:, 1]
    # generate random shifting
    move = (np.random.random(points.shape[0]) - 0.5) * max_deform

    # fix boundary points
    # set the boundary points
    bound = np.ones(nb_bound_points - 1)
    x_bound = np.linspace(0, shape[0] - 1, nb_bound_points)
    y_bound = np.linspace(0, shape[1] - 1, nb_bound_points)
    x_point = np.hstack((points[:, 0], 0 * bound, x_bound[:-1],
                         (shape[0] - 1) * bound, x_bound[::-1][:-1]))
    y_point = np.hstack((points[:, 1], y_bound[:-1], (shape[1] - 1) * bound,
                         y_bound[::-1][:-1], 0 * bound))
    # the boundary points sex as 0 shift
    move = np.hstack((move, np.zeros(4 * nb_bound_points - 4)))
    # create the interpolation function
    smooth = 0.2 * max_deform
    rbf = interpolate.Rbf(x_point, y_point, move, function='thin-plate',
                          epsilon=1, smooth=smooth)
    # interpolate in regular grid
    x_grid, y_grid = np.mgrid[0:shape[0], 0:shape[1]].astype(np.int32)
    # FIXME: it takes to much of RAM memory, for sample image more that 8GM !
    deform = rbf(x_grid, y_grid)
    return deform 
开发者ID:Borda,项目名称:BIRL,代码行数:38,代码来源:create_real_synth_dataset.py

示例7: create_rbf_surrogate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def create_rbf_surrogate(X, Y):
    rbf = Rbf(*(X.T), Y, function='multiquadric')
    return rbf 
开发者ID:ImperialCollegeLondon,项目名称:sharpy,代码行数:5,代码来源:optimiser.py

示例8: rasterize_points_radial

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import Rbf [as 别名]
def rasterize_points_radial(
    geometry_array,
    data_values,
    grid_coords,
    method="linear",
    filter_nan=False,
    **ignored_kwargs,
):
    """
    This method uses scipy.interpolate.Rbf to interpolate point data
    to a grid.

    Parameters
    ----------
    geometry_array: geopandas.GeometryArray
        A geometry array of points.
    data_values: list
        Data values associated with the list of geojson shapes
    grid_coords: dict
        Output from `rioxarray.rioxarray.affine_to_coords`
    method: str, optional
        The function to use for interpolation in `scipy.interpolate.Rbf`.
        {'multiquadric', 'inverse', 'gaussian', 'linear',
        'cubic', 'quintic', 'thin_plate'}
    filter_nan: bool, optional
        If True, will remove nodata values from the data before rasterization.
        Default is False.
    **ignored_kwargs:
        These are there to be flexible with additional rasterization methods and
        will be ignored.

    Returns
    -------
    :class:`numpy.ndarray`: An interpolated :class:`numpy.ndarray`.

    """
    logger = get_logger()

    try:
        if filter_nan:
            data_values, geometry_array = _remove_missing_data(
                data_values, geometry_array
            )
        interp = Rbf(geometry_array.x, geometry_array.y, data_values, function=method)
        return interp(*numpy.meshgrid(grid_coords["x"], grid_coords["y"]))
    except ValueError as ter:
        if "object arrays are not supported" in str(ter):
            logger.warning(f"{ter}")
            return None
        raise 
开发者ID:corteva,项目名称:geocube,代码行数:52,代码来源:rasterize.py


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