Interpolating data from one latitude-longitude grid onto a different one?

守給你的承諾、 提交于 2019-12-06 00:45:02

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!