在Python中插入纬度,经度和数据(圆圈内的结构化网格)

时间:2015-10-12 19:49:43

标签: python scipy gis interpolation estimation

我有一组纬度,经度点和数据变量,例如:来自地址的开车时间。这些点是通过对结构化网格进行采样然后切出一个圆来创建的。

因此我不认为我可以有一个数据矩阵,因为有些列会比其他列(圆圈的顶部和底部)有更多的零/缺失,这可能会混淆算法?

理想情况下,我想用更多积分填写圆圈;例如小数点后5位,而不是51.5454和51.5455,而是51.54540,51.54541,....,51.54550。

我的数据如下:

enter image description here

我想填补空白:

enter image description here

我尝试过使用:

from scipy.interpolate import RectSphereBivariateSpline

以下列方式 - (测试用例),但我不确定这是否是正确的方法?

def geointerp(lats, lons, data, grid_size_deg, mesh=False):
    deg2rad = np.pi/180.
    new_lats = np.linspace(50, 51, 180/grid_size_deg)
    new_lons = np.linspace(-1, 1, 360/grid_size_deg)
    new_lats, new_lons = np.meshgrid(new_lats*deg2rad, new_lons*deg2rad)
    #We need to set up the interpolator object

    lut = RectSphereBivariateSpline(lons*deg2rad, lats*deg2rad, data)

    new_lats = new_lats.ravel()
    new_lons = new_lons.ravel()
    data_interp = lut.ev(new_lats,new_lons)

    if mesh == True:
        data_interp = data_interp.reshape((360/grid_size_deg, 180/grid_size_deg)).T

    return new_lats/deg2rad, new_lons/deg2rad, data_interp

# Read in-data
lats_in = []
lons_in = []
data_in = []
with open('interpolation_test.csv') as f:
    for x in csv.reader(f):
        lats_in.append(float(x[0]))
        lons_in.append(float(x[1]))
        data_in.append(float(x[2]))

# Interpolate:
lats_in = np.asarray(lats_in)
lons_in = np.asarray(lons_in)
data_in = np.asarray(data_in)
output_list = geointerp(lats_in, lons_in, data_in, 0.01)

#  Output
f = open('interpolation_test_out.csv', 'w', newline='')
w = csv.writer(f)
for out in output_list:
    w.writerow([out])
f.close()

更不用说错误如:

"if not v.size == r.shape[1]:
IndexError: tuple index out of range"

0 个答案:

没有答案