将数据从一个经纬度网格插值到另一个纬度-经度网格上



我有两个数据数组在纬度网格上。第一个,A,有形状(89,180)。第二个,B,有形状(94,192)。A 的纬度从 88 开始按降序排列。到 -88。经度从0开始按升序排列。到 358。B的纬度从88.54199982到-88.54199982的降序排列,经度从0升序排列。到 358.125。

我想将 B 的数据重新网格/插值到 A 的坐标系上,以便我可以得到两个大小相同的数组并计算它们之间的空间相关性。(如果这样更容易,我还可以将 A 的数据重新网格/插值到 B 的坐标系上。我尝试了mpl_toolkits.basemap.interp(datain,xin,yin,xout,yout),但这要求xout和yout的大小相同。我也尝试了scipy.interpolate.griddata,但我无法弄清楚它是如何工作的,我什至不确定这会得到我想要的东西......

您可能想查看此问题和其他类似地理插值问题的pyresample。 它提供了多种插值方法,适用于纬度/纬度数据,并包含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

基于@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

最新更新