将数据从一个经度网格插值到另一个网格上? [英] Interpolating data from one latitude-longitude grid onto a different one?

查看:180
本文介绍了将数据从一个经度网格插值到另一个网格上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个位于纬度网格上的数据数组.第一个A的形状为(89,180).第二个B的形状为(94,192). A的纬度从88.降到-88. &经度从0到358升序.B的纬度从88.54199982到-88.54199982&经度从0到358.125升序.

I have two data arrays that are on lat-lon grids. The first one, A, has the shape (89, 180). The second one, B, has the shape (94, 192). A's latitudes are in descending order from 88. to -88. & longitudes are in ascending order from 0. to 358. B's latitudes are in descending order from 88.54199982 to -88.54199982 & longitudes are in ascending order from 0. to 358.125.

我想将B的数据重新插入/插值到A的坐标系上,这样我就可以使两个数组具有相同的大小并计算它们之间的空间相关性. (如果比较容易,我也可以将A的数据重新插入/插值到B的坐标系上.)我尝试了mpl_toolkits.basemap.interp(datain,xin,yin,xout,yout),但这需要xout&大小相同.我也尝试过scipy.interpolate.griddata,但是我不知道它是如何工作的,我什至不知道那会给我我想要的东西...

I want to regrid/interpolate B's data onto A's coordinate system so that I can get both arrays the same size and calculate the spatial correlation between them. (I can also regrid/interpolate A's data onto B's coordinate system if that's easier.) I tried mpl_toolkits.basemap.interp(datain, xin, yin, xout, yout), but that requires xout & yout to be the same size. I also tried scipy.interpolate.griddata, but I can't figure out how it works and I'm not even sure that'll get me what I'm looking for...

推荐答案

您可能希望查看pyresample来解决此问题以及其他类似的地理插值问题.它提供了多种插值方法,可以很好地处理经/纬度数据,并集成了basemap支持.我建议使用此软件包,因为您还可以创建使用Proj4定义定义域的AreaDefinition对象,然后将数据注册到AreaDefinition.

You may want to look at pyresample for this and other similar geographical interpolation problems. It provides multiple methods for interpolation, works well with lat/lon data, and incorporates basemap support. I suggest this package because you can also create AreaDefinition objects that define a domain using Proj4 definitions, then register data to the AreaDefinition.

对于您的特定问题,我将执行以下操作(请注意,插值步骤尚未​​完成,请参见下文):

For your specific problem, I would do the following (note, the interpolation step is not complete, see below):

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如果您使用的是屏蔽数据.

Note that the interpolation step where resample_nearest is called is not complete. You will also need to specify the radius_of_influence which is the search radius to use around each point in meters. This is dependent on the resolution of your data. You may also want to specify nprocs to speed things up and fill_value if you are using masked data.

这篇关于将数据从一个经度网格插值到另一个网格上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆