从一个纬度 - 经度网格到另一个网格的数据插值?

时间:2016-03-01 21:39:36

标签: python interpolation latitude-longitude

我有两个数据阵列在lat-lon网格上。第一个,A,形状(89,180)。第二个B具有形状(94,192)。 A的纬度从88到-88降序排列。 &安培;经度从0到358按升序排列.B的纬度从88.54199982降至-88.54199982&经度从0到358.125递增。

我想将B&B的数据重新插入/插入到A坐标系中,这样我就可以得到两个相同大小的数组并计算它们之间的空间相关性。 (我也可以将A&#39的数据重新插入/插入到B&#39的坐标系中,如果这更容易的话。)我试过mpl_toolkits.basemap.interp(datain,xin,yin,xout,yout),但是这需要xout&你的大小一样。我也尝试了scipy.interpolate.griddata,但我无法弄清楚它是如何工作的,我甚至不确定是否会让我得到我正在寻找的东西......

2 个答案:

答案 0 :(得分:1)

您可能需要查看此pyresample以及其他类似的地理插值问题。它提供了多种插值方法,适用于lat / lon数据,并包含basemap支持。我建议使用此包,因为您还可以使用Proj4定义创建定义域的AreaDefinition个对象,然后将数据注册到AreaDefinition

针对您的具体问题,我会执行以下操作(请注意,插值步骤未完成,请参见下文):

from pyresample.geometry import SwathDefinition
from pyresample.kd_tree import resample_nearest

def interp_b_to_a(a, b):
    '''Take in two dictionaries of arrays and interpolate the second to the first.
    The dictionaries must contain the following keys: "data", "lats", "lons"
    whose values must be numpy arrays.
    '''
    def_a = SwathDefinition(lons=a['lons'], lats=a['lats'])
    def_b = SwathDefinition(lons=b['lons'], lats=b['lats'])

    interp_dat = resample_nearest(def_b, b['data'], def_a, ...)
    new_b = {'data':interp_dat,
             'lats':copy(a['lats']),
             'lons':copy(a['lons'])
            }
    return new_b

请注意,调用resample_nearest的插值步骤不完整。您还需要指定radius_of_influence,它是在每个点(米)周围使用的搜索半径。这取决于数据的分辨率。如果使用屏蔽数据,您可能还需要指定nprocs以加快速度和fill_value

答案 1 :(得分:0)

基于@Vorticity,我解决了编辑为:

from pyresample.geometry import SwathDefinition
from pyresample.kd_tree import resample_nearest

def interp_b_to_a(a, b):
    def_a = SwathDefinition(lons=a['lons'], lats=a['lats'])
    def_b = SwathDefinition(lons=b['lons'], lats=b['lats'])

    interp_dat = resample_nearest(def_a, a['data'], def_b,radius_of_influence = 5000)
    new_b = {'data':interp_dat,
             'lats':b['lats'],
             'lons':b['lons']
            }
    return new_b