Python:从不规则的2d网格到常规网格的插值

时间:2014-10-28 10:59:55

标签: python scipy

我想在常规网格上映射不规则网格的值分布。 我正在尝试使用不同的内插器,但它看起来我无法做到。

这里有我写的代码:

import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt


N = 100
M = 10

lat   = ((np.random.rand(M,N))*2)+0.2
lon   = ((np.random.rand(M,N))*3)+0.2
theta = ((np.random.rand(M,N))*180)
lat_min = np.min(lat)
lat_max = np.max(lat)
lon_min = np.min(lon)
lon_max = np.max(lon)

dlat = 0.1            # regular step for the lat[rad]
dlon = 0.1           # regular step for the lon[rad]

# Grid dimensions
Nlat = np.int(np.abs(lat_max-lat_min)/dlat)+1
Nlon = np.int(np.abs(lon_max-lon_min)/dlon)+1

# Lat-Lon vector
reg_lat = np.linspace(lat_min, lat_max, Nlat)  # regularly spaced latitude vector
reg_lon = np.linspace(lon_min, lon_max, Nlon)  # regularly spaced longitude vector
# Lat-Lon regular Grid
reg_lon_mesh, reg_lat_mesh = np.meshgrid(reg_lon, reg_lat)

我用过:

theta2 = scipy.interpolate.griddata((lon.ravel(), lat.ravel()), theta.ravel(),(reg_lon_mesh, reg_lat_mesh), method='cubic')

但插值似乎错了

f = interpolate.interp2d(lon.ravel(), lat.ravel(), theta,kind='cubic')

并且它上升警告:在找到smoothin样条曲线时理论上不可能得到结果     用fp = s。可能导致:太小或太糟糕的选择eps。     (ABS(FP-S)/s>0.001)         kx,ky = 3,3 nx,ny = 36,34 m = 1000 fp = 14832451.907306 s = 0.000000

0 个答案:

没有答案