我有3个具有长,纬度和降雨值的numpy数组:
// your string
$string = "galaxy-s6.jpg";
// replace after .
$removed = preg_replace('/\\.[^.\\s]{3,4}$/', '', $string);
// replace - between file name
$replace = str_replace("-", " ", $removed);
// ucwords for first letter capital
$upper = ucwords($replace);
echo $upper;
Scipy插值需要1个具有3个不同Lons的数组,另一个具有2个不同的Lons和3x2的降雨数组。我怎样才能重塑它们?
答案 0 :(得分:3)
听起来你想要2D插值。
例如,让我们使用一些类似于你的随机数据并绘制它:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1) # Make example exactly reproducable
num_points = 20
lon = 0.1 * np.random.random(num_points) - 7.5
lat = 0.1 * np.random.random(num_points) + 41.8
z = 0.05 * np.random.random(num_points)
fig, ax = plt.subplots()
artist = ax.scatter(lon, lat, c=z, s=200, cmap='gist_earth')
fig.colorbar(artist)
ax.axis('tight')
plt.show()
对于这种情况,插值算法的良好选择将是某种径向基函数(例如样条)。在scipy中,那是scipy.interpolate.Rbf
:
import scipy.interpolate
interp = scipy.interpolate.Rbf(lon, lat, z, function='linear')
# 20x20 grid of points to interpolate on
yy, xx = np.mgrid[lat.min():lat.max():20j, lon.min():lon.max():20j]
zi = interp(xx, yy)
# Plot the results
fig, ax = plt.subplots()
artist = ax.scatter(lon, lat, c=z, s=100, cmap='gist_earth',
vmin=zi.min(), vmax=zi.max())
ax.pcolormesh(xx, yy, zi, cmap='gist_earth')
ax.axis('tight')
plt.show()