本文整理汇总了Python中scipy.interpolate.griddata方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.griddata方法的具体用法?Python interpolate.griddata怎么用?Python interpolate.griddata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.griddata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_RSM
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def load_RSM(filename):
om, tt, psd = xu.io.getxrdml_map(filename)
om = np.deg2rad(om)
tt = np.deg2rad(tt)
wavelength = 1.54056
q_y = (1 / wavelength) * (np.cos(tt) - np.cos(2 * om - tt))
q_x = (1 / wavelength) * (np.sin(tt) - np.sin(2 * om - tt))
xi = np.linspace(np.min(q_x), np.max(q_x), 100)
yi = np.linspace(np.min(q_y), np.max(q_y), 100)
psd[psd < 1] = 1
data_grid = griddata(
(q_x, q_y), psd, (xi[None, :], yi[:, None]), fill_value=1, method="cubic"
)
nx, ny = data_grid.shape
range_values = [np.min(q_x), np.max(q_x), np.min(q_y), np.max(q_y)]
output_data = (
Panel(np.log(data_grid).reshape(nx, ny, 1), minor_axis=["RSM"])
.transpose(2, 0, 1)
.to_frame()
)
return range_values, output_data
示例2: test_square_rescale_manual
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def test_square_rescale_manual(self):
points = np.array([(0,0), (0,100), (10,100), (10,0), (1, 5)], dtype=np.double)
points_rescaled = np.array([(0,0), (0,1), (1,1), (1,0), (0.1, 0.05)], dtype=np.double)
values = np.array([1., 2., -3., 5., 9.], dtype=np.double)
xx, yy = np.broadcast_arrays(np.linspace(0, 10, 14)[:,None],
np.linspace(0, 100, 14)[None,:])
xx = xx.ravel()
yy = yy.ravel()
xi = np.array([xx, yy]).T.copy()
for method in ('nearest', 'linear', 'cubic'):
msg = method
zi = griddata(points_rescaled, values, xi/np.array([10, 100.]),
method=method)
zi_rescaled = griddata(points, values, xi, method=method,
rescale=True)
assert_allclose(zi, zi_rescaled, err_msg=msg,
atol=1e-12)
示例3: plot_landscape
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def plot_landscape(data):
"""
Plot the data as an energy landscape.
Args:
data: (x, y, xx, yy, z, xlim, ylim). x, y, z represent the \
coordinates of the points that will be interpolated. xx, yy \
represent the meshgrid used to interpolate the points. xlim, \
ylim are tuples containing the limits of the x and y axes.
Returns:
Plot representing the interpolated energy landscape of the target points.
"""
x, y, xx, yy, z, xlim, ylim = data
zz = griddata((x, y), z, (xx, yy), method="linear")
mesh = holoviews.QuadMesh((xx, yy, zz))
contour = holoviews.operation.contours(mesh, levels=8)
scatter = holoviews.Scatter((x, y))
contour_mesh = mesh * contour * scatter
return contour_mesh.redim(
x=holoviews.Dimension("x", range=xlim), y=holoviews.Dimension("y", range=ylim),
)
示例4: interpolation_near
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def interpolation_near(x1, y1, x2, y2, x1grd, y1grd, method='linear', **kwargs):
''' Interpolate values of x2/y2 onto full-res grids of x1/y1 using
linear interpolation of nearest points
Parameters
----------
x1 : 1D vector - X coordinates of keypoints on image 1
y1 : 1D vector - Y coordinates of keypoints on image 1
x1 : 1D vector - X coordinates of keypoints on image 2
y1 : 1D vector - Y coordinates of keypoints on image 2
x1grd : 1D vector - source X coordinate on img1
y1grd : 1D vector - source Y coordinate on img2
method : str - parameter for SciPy griddata
Returns
-------
x2grd : 1D vector - destination X coordinate on img1
y2grd : 1D vector - destination Y coordinate on img2
'''
src = np.array([y1, x1]).T
dst = np.array([y1grd, x1grd]).T
x2grd = griddata(src, x2, dst, method=method).T
y2grd = griddata(src, y2, dst, method=method).T
return x2grd, y2grd
示例5: _view_griddata
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def _view_griddata(cls, data, data_view, target_view, method='nearest',
x_tolerance=1e-3, y_tolerance=1e-3):
t_xmin, t_ymin, t_xmax, t_ymax = target_view.bbox
d_xmin, d_ymin, d_xmax, d_ymax = data_view.bbox
nodata = target_view.nodata
view = np.full(target_view.shape, nodata)
viewcoords = target_view.coords
datacoords = data_view.coords
yx_tolerance = np.sqrt(x_tolerance**2 + y_tolerance**2)
row_bool = ((datacoords[:,0] <= t_ymax + y_tolerance) &
(datacoords[:,0] >= t_ymin - y_tolerance))
col_bool = ((datacoords[:,1] <= t_xmax + x_tolerance) &
(datacoords[:,1] >= t_xmin - x_tolerance))
yx_grid = datacoords[row_bool & col_bool]
view = interpolate.griddata(yx_grid,
data.flat[row_bool & col_bool],
viewcoords, method=method,
fill_value=nodata)
view = view.reshape(target_view.shape)
return view
示例6: test_complex_2d
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def test_complex_2d(self):
x = np.array([(0,0), (-0.5,-0.5), (-0.5,0.5), (0.5, 0.5), (0.25, 0.3)],
dtype=np.double)
y = np.arange(x.shape[0], dtype=np.double)
y = y - 2j*y[::-1]
xi = x[:,None,:] + np.array([0,0,0])[None,:,None]
for method in ('nearest', 'linear', 'cubic'):
for rescale in (True, False):
msg = repr((method, rescale))
yi = griddata(x, y, xi, method=method, rescale=rescale)
assert_equal(yi.shape, (5, 3), err_msg=msg)
assert_allclose(yi, np.tile(y[:,None], (1, 3)),
atol=1e-14, err_msg=msg)
示例7: test_1d_borders
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def test_1d_borders(self):
# Test for nearest neighbor case with xi outside
# the range of the values.
x = np.array([1, 2.5, 3, 4.5, 5, 6])
y = np.array([1, 2, 0, 3.9, 2, 1])
xi = np.array([0.9, 6.5])
yi_should = np.array([1.0, 1.0])
method = 'nearest'
assert_allclose(griddata(x, y, xi,
method=method), yi_should,
err_msg=method,
atol=1e-14)
assert_allclose(griddata(x.reshape(6, 1), y, xi,
method=method), yi_should,
err_msg=method,
atol=1e-14)
assert_allclose(griddata((x, ), y, (xi, ),
method=method), yi_should,
err_msg=method,
atol=1e-14)
示例8: test_xi_1d
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def test_xi_1d(self):
# Check that 1-D xi is interpreted as a coordinate
x = np.array([(0,0), (-0.5,-0.5), (-0.5,0.5), (0.5, 0.5), (0.25, 0.3)],
dtype=np.double)
y = np.arange(x.shape[0], dtype=np.double)
y = y - 2j*y[::-1]
xi = np.array([0.5, 0.5])
for method in ('nearest', 'linear', 'cubic'):
p1 = griddata(x, y, xi, method=method)
p2 = griddata(x, y, xi[None,:], method=method)
assert_allclose(p1, p2, err_msg=method)
xi1 = np.array([0.5])
xi3 = np.array([0.5, 0.5, 0.5])
assert_raises(ValueError, griddata, x, y, xi1,
method=method)
assert_raises(ValueError, griddata, x, y, xi3,
method=method)
示例9: get_reference_elevation
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def get_reference_elevation(input, recGrid, elevation):
"""
The following function define the elevation from the TIN to a regular grid...
Args:
input: class containing XML input file parameters.
recGrid: class describing the regular grid characteristics.
elevation: TIN elevation mesh.
Returns:
- ref_elev - interpolated elevation on the regular grid
"""
if input.searef:
x_ref, y_ref = input.searef
pts = recGrid.tinMesh["vertices"]
ref_elev = griddata(
points=pts, values=elevation, xi=[x_ref, y_ref], method="nearest"
)
else:
ref_elev = 0.0
return ref_elev
示例10: interpj
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def interpj(self, key_or_var, lay, lat, angle):
from scipy.interpolate import griddata
lays = self.variables['LAY']
lats = self.variables['LAT']
angles = self.variables['ANGLE']
points = np.array([[[(lay_, lat_, angle_) for angle_ in angles]
for lat_ in lats] for lay_ in lays]).reshape(-1, 3)
if isinstance(key_or_var, str):
v = self.variables[key_or_var].ravel()
else:
v = np.array(key_or_var)
assert(key_or_var.shape == (self.NLAYS, self.NLATS, self.NANGLES))
if isinstance(lay, (int, float)):
idx = np.array((lay, lat, angle), ndmin=2)
else:
idx = np.array((lay, lat, angle)).swapaxes(0, 1)
assert(idx.shape[0] == 2)
return griddata(points, v, idx)[0]
示例11: regrid
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def regrid(self):
''' Regrid the non-uniform data on a regular mesh '''
if self.values is None:
warnings.warn('Cannont regrid: data missing.')
return
# First we need to interpolate the non-uniformly sampled data
# onto a uniform grid
from scipy.interpolate import griddata
x = int(np.sqrt(self.n_points / 2))
G = np.mgrid[-np.pi:np.pi:2j*x, 0:np.pi:1j*x]
spherical_grid = np.squeeze(G.reshape((2,1,-1)))
gridded = griddata(self.spherical.T, self.values, spherical_grid.T, method='nearest', fill_value=0.)
dirty_img = gridded.reshape((2*x, x))
return G[0], G[1], gridded.reshape((2*x, x))
示例12: calc_albedo_from_sma
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def calc_albedo_from_sma(self, a):
"""Helper function for calculating albedo.
We assume a uniform distribution of metallicities, and then interpolate the
grid from Cahoy et al. 2010.
Args:
a (astropy Quanitity array):
Semi-major axis values
Returns:
p (ndarray):
Albedo values
"""
# grab the sma values and constrain to grid
atmp = np.clip(a.to('AU').value, 0.8, 10.)
#generate uniform fe grid:
fetmp = np.random.uniform(size=atmp.size, low=1, high=30)
p = interpolate.griddata(self.albedo_pts, self.albedo_vals,
(atmp, fetmp), method='cubic')
return p
示例13: get_binary_mask
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def get_binary_mask(cv2_mask):
if cv2_mask is None:
return None, None
# The two reds in MS Paint are
# Bright Red: 236, 28, 36
# Dark Red: 136, 0, 27
# Try to support both here
red_pixels = np.logical_and(np.logical_and(cv2_mask[:,:,0] < 40, cv2_mask[:,:,1] < 40), cv2_mask[:,:,2] > 130)
# The blues in Paint3d are:
# Indigo: 62, 73, 204
# Turquoise: 0, 168, 243
blue_pixels = np.logical_and(np.logical_and(cv2_mask[:,:,0] > 200, cv2_mask[:,:,1] < 180), cv2_mask[:,:,2] < 70)
# Don't infill areas painted in Red
# Red turns to black, otherwise, white. Black will not be infilled or sent in the output image
remove_mask = (255.0*np.ones((cv2_mask.shape[0], cv2_mask.shape[1], 1))).astype('uint8')
remove_mask[red_pixels] = 0
# Preserve original terrain for areas marked in Blue
preserve_mask = (np.zeros((cv2_mask.shape[0], cv2_mask.shape[1], 1))).astype('uint8')
preserve_mask[blue_pixels] = 255
return remove_mask, preserve_mask
# Uses scipy griddata to interpolate and "recompute" the terrain data based on only the valid image points
# Seems to produce a smoother and more natural result
# Also allows us to sample in arbitrary sizes
示例14: plot_solution
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def plot_solution(X_star, u_star, index):
lb = X_star.min(0)
ub = X_star.max(0)
nn = 200
x = np.linspace(lb[0], ub[0], nn)
y = np.linspace(lb[1], ub[1], nn)
X, Y = np.meshgrid(x,y)
U_star = griddata(X_star, u_star.flatten(), (X, Y), method='cubic')
plt.figure(index)
plt.pcolor(X,Y,U_star, cmap = 'jet')
plt.colorbar()
示例15: plot_solution
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import griddata [as 别名]
def plot_solution(X_data, w_data, index):
lb = X_data.min(0)
ub = X_data.max(0)
nn = 200
x = np.linspace(lb[0], ub[0], nn)
y = np.linspace(lb[1], ub[1], nn)
X, Y = np.meshgrid(x,y)
W_data = griddata(X_data, w_data.flatten(), (X, Y), method='cubic')
plt.figure(index)
plt.pcolor(X,Y,W_data, cmap = 'jet')
plt.colorbar()