如何将二维数组从较粗的分辨率插值到较细的分辨率

All*_*ang 2 numpy scipy netcdf python-xarray

假设我有一个形状为 的发射数据(21600,43200),它对应于latlon,即

lat = np.arange(21600)*(-0.008333333)+90
lon = np.arange(43200)*0.00833333-180
Run Code Online (Sandbox Code Playgroud)

我还有一个形状为 的缩放因子(720,1440,7),对应于latlonday of week

lat = np.arange(720)*0.25-90 
lon = np.arange(1440)*0.25-180
Run Code Online (Sandbox Code Playgroud)

现在,我想将该因子应用于排放数据,并且我认为我需要将该因子插值到(720,1440)(21600,43200)。之后,我可以将插值因子与排放数据相乘以获得新的排放输出。

但我对插值方法有困难。有人能给我一些建议吗?

tel*_*tel 5

这是您尝试执行的插值类型的完整示例。出于示例目的,我使用了emissiondata with shape(10, 20)scaledata with shape (5, 10)。它使用scipy.interpolate.RectBivariateSpline,这是在规则网格上进行插值的推荐方法:

import scipy.interpolate as sci

def latlon(res):
    return (np.arange(res)*(180/res) - 90,
            np.arange(2*res)*(360/(2*res)) - 180)

lat_fine,lon_fine = latlon(10)
emission = np.ones(10*20).reshape(10,20)

lat_coarse,lon_coarse = latlon(5)
scale = np.linspace(0, .5, num=5).reshape(-1, 1) + np.linspace(0, .5, num=10)

f = sci.RectBivariateSpline(lat_coarse, lon_coarse, scale)
scale_interp = f(lat_em, lon_em)

with np.printoptions(precision=1, suppress=True, linewidth=9999):
    print('original emission data:\n%s\n' % emission)
    print('original scale data:\n%s\n' % scale)
    print('interpolated scale data:\n%s\n' % scale_interp)
    print('scaled emission data:\n%s\n' % (emission*scale_interp))
Run Code Online (Sandbox Code Playgroud)

其输出:

original emission data:
[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1.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