【问题标题】:Bilinear interpolation from structured grid to unstructured grid (arbitrary points)从结构化网格到非结构化网格的双线性插值(任意点)
【发布时间】:2019-12-08 10:54:30
【问题描述】:

我需要在任意坐标集合上从 240x240 结构化网格中对 hdf4/netcdf4/hdf5 文件的一些空气数据进行双线性插值。我不知道该怎么做。我曾尝试使用 pyresample ,但这需要目标网格的区域定义,这在我的非结构化目标数据(任意点)的情况下是不可能的。这是我的代码:

import numpy as np
import pyresample
from   netCDF4 import Dataset

air_file  = Dataset('air.hdf', mode='r')
air_data  = air_file.variables['air_2m' ][:].flatten()
air_lon   = air_file.variables['air_lon'][:].flatten()
air_lat   = air_file.variables['air_lat'][:].flatten()
air_data  = air_data.reshape(240,240)
air_lon   = air_lon. reshape(240,240) # grid size is 240x240
air_lat   = air_lat. reshape(240,240)

tar_lon   = 100 * np.random.random((100,1)) # random points 
tar_lat   = 100 * np.random.random((100,1)) # random points

source_def = pyresample.geometry.SwathDefinition(lons=air_lon, lats=air_lat)
target_def = pyresample.geometry.SwathDefinition(lons=tar_lon, lats=tar_lat)
result     = pyresample.bilinear.resample_bilinear(gmt_1500, source_def, target_def, radius=50e3, neighbours=32, nprocs=1, fill_value=None, reduce_data=True, segments=None, epsilon=0)

我收到以下错误(可以理解为它需要一个 AreaDefinition 作为目标):

AttributeError: 'SwathDefinition' object has no attribute 'proj_str'

还有其他方法吗?

【问题讨论】:

  • 这有点复杂,但是使用 RBF 内核将高斯过程拟合到您的数据可以让您推断到任何其他点,定期采样或其他方式。

标签: python gis interpolation netcdf cdo-climate


【解决方案1】:

我不熟悉 pyresample 包,但对于 python 中的双线性插值,我建议参考这个较早的 stackexchange 线程,它提供了许多有用的示例:

How to perform bilinear interpolation in Python

p.s:顺便说一句,如果有人想从命令行执行此任务,您也可以使用双线性插值和 cdo 提取一组点

# some bash loop over a pairs of x and y
cdo remapbil,lon=${x}/lat=${x} in.nc mypoint_${x}_${y}.nc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多