【问题标题】:Python: convert 1-D array (with equal area coordinate system) to a 2-D array (with Geographic Coordinate Reference System)Python:将一维数组(具有等面积坐标系)转换为二维数组(具有地理坐标参考系)
【发布时间】:2020-08-07 09:51:01
【问题描述】:

我有一个一维数据数组(例如降水 [沉淀])。此外,我有 1D 纬度(最小 -90 度,最大 +90 度)和 1D 经度(最小 0,最大 360 度)数组表示该数据的坐标。坐标系是“等面积”。它是一个全局数据集。

我的问题是如何将此一维数组转换为具有地理坐标参考系(即等距网格、平行线和经线)的二维数组,空间分辨率为 1 x 1 度,以便我会有一个 180*360 的数组(最好使用 pyproj / xarray)?

谢谢!

以下是数据集的信息:

xarray.Dataset

尺寸:(eqcell:41252)

没有坐标的维度:eqcell

数据变量:

lat                (eqcell) float32 dask.array chunksize=(41252,), meta=np.ndarray

lon                (eqcell) float32 dask.array chunksize=(41252,), meta=np.ndarray

precip              (eqcell) float32 dask.array chunksize=(41252,), meta=np.ndarray

【问题讨论】:

  • 到底是什么问题?你有没有尝试过,做过任何研究?请参阅How to Askhelp center

标签: python projection coordinate-systems


【解决方案1】:

看起来你想要scipy.interpolate.griddata。这是文档中的示例:


假设我们要对二维函数进行插值

>>> def func(x, y):
...     return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2

在 [0, 1]x[0, 1] 的网格上

>>> grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]

但我们只知道它在 1000 个数据点处的值:

>>> points = np.random.rand(1000, 2)
>>> values = func(points[:,0], points[:,1])

这可以通过 griddata 来完成——下面我们尝试所有的插值方法:

>>> from scipy.interpolate import griddata
>>> grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
>>> grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
>>> grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')

可以看出,所有方法都在一定程度上重现了确切的结果,但是对于这个平滑函数,分段三次插值法给出了最好的结果:

>>> import matplotlib.pyplot as plt
>>> plt.subplot(221)
>>> plt.imshow(func(grid_x, grid_y).T, extent=(0,1,0,1), origin='lower')
>>> plt.plot(points[:,0], points[:,1], 'k.', ms=1)
>>> plt.title('Original')
>>> plt.subplot(222)
>>> plt.imshow(grid_z0.T, extent=(0,1,0,1), origin='lower')
>>> plt.title('Nearest')
>>> plt.subplot(223)
>>> plt.imshow(grid_z1.T, extent=(0,1,0,1), origin='lower')
>>> plt.title('Linear')
>>> plt.subplot(224)
>>> plt.imshow(grid_z2.T, extent=(0,1,0,1), origin='lower')
>>> plt.title('Cubic')
>>> plt.gcf().set_size_inches(6, 6)
>>> plt.show()

【讨论】:

  • @Abedeh - 据我所知,您的问题完全反映了文档中的示例,如下所示:points[:,0]latpoints[:,1]lonvaluesprecip。这有意义吗?
  • metpy.interpolate.interpolate_to_grid 也很有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 2021-06-28
  • 2016-04-10
  • 1970-01-01
  • 2016-02-06
  • 2023-04-01
相关资源
最近更新 更多