如何使用SciPy以列格式插入2D数据?

时间:2019-02-21 17:43:33

标签: python numpy scipy interpolation

我有一个示例网格的速度矢量,如下所示:

Example Grid

数据可用here。但是,数据以列格式存储,如下所示:

输入数据格式

x1, y1, ... (velocity vectors)
x1, y2, ... (velocity vectors)
x1, y3, ... (velocity vectors)
 :   :               :
x4, y2, ... (velocity vectors)
x4, y3, ... (velocity vectors)
x4, y4, ... (velocity vectors)   

我正在尝试通过scipy的{​​{1}}函数应用2D插值。我需要将网格点的数量加倍,并以相同的列格式插值并写入输出文件:

所需的输出格式(插值后):

interpolate

MWE

x1_i, y1_i, ... (velocity vectors)
x1_i, y2_i, ... (velocity vectors)
x1_i, y3_i, ... (velocity vectors)
 :   :               :
x8_i, y6_i, ... (velocity vectors)
x8_i, y7_i, ... (velocity vectors)
x8_i, y8_i, ... (velocity vectors)  

现在,如何使用列格式的import numpy as np from scipy.interpolate import Rbf from scipy import interpolate _data_ = np.genfromtxt('./2d_interp.dat', skip_header=1, dtype = None, delimiter = '\t') mesh_y = (np.max(np.diff(np.sort(_data_[:,0])))) mesh_z = (np.max(np.diff(np.sort(_data_[:,1])))) mesh_min = min(mesh_y, mesh_z) x_max = np.max(_data_[:,0]) x_min = np.min(_data_[:,0]) y_max = np.max(_data_[:,1]) y_min = np.min(_data_[:,1]) interp_n_cells = max(abs(x_max - x_min)/mesh_min, abs(y_max - y_min)/mesh_min) x_interp = np.linspace(x_min, x_max, 2 * interp_n_cells) y_interp = np.linspace(y_min, y_max, 2 * interp_n_cells) xx_interp, yy_interp = np.meshgrid(x_interp, y_interp) interp_data = np.empty(shape=(len(x_interp * y_interp),6)) interp_data[:,0] = x_interp interp_data[:,1] = y_interp interp_data[:,2] = _data_[0,2] for i in range(3,5): f = interpolate.interp2d(_data_[:,0], _data_[:,1], _data_[:,i], kind='linear') interp_data[:,i] = f(x_interp, y_interp) 内插2D数据,即,我需要将点数加倍,以与输入格式相同的格式内插和输出数据(如上所述)。 scipy.interpolate如何做到?

0 个答案:

没有答案