如何将 netcdf 虹膜立方体中的投影 x 和 y 坐标转换为经纬度

how to convert projection x and y coordinate in netcdf iris cube to lat lon

参见上面的问题,只想从 Iris 立方体中获取 lat/lon 的 Google 贴图...

cube.coord_system()

LambertAzimuthalEqualArea(latitude_of_projection_origin=54.9, longitude_of_projection_origin=-2.5, false_easting=0.0, false_northing=0.0, ellipsoid=GeogCS(semi_major_axis= 6378137.0, semi_minor_axis=6356752.314140356))

如果您只想转换 x 和 y 坐标来绘制数据,您可以使用 iriscartopy:

import iris
import numpy as np

首先获取原生投影中的坐标点

proj_x = cube.coord("projection_x_coordinate").points
proj_y = cube.coord("projection_y_coordinate").points

接下来,制作一对形状相同的二维数组

xx, yy = np.meshgrid(proj_x, proj_y)

然后提取原生投影并将其转换为cartopy投影:

cs_nat = cube.coord_system()
cs_nat_cart = cs_nat.as_cartopy_projection()

接下来,创建目标投影,例如标准椭球投影

cs_tgt = iris.coord_systems.GeogCS(iris.analysis.cartography.DEFAULT_SPHERICAL_EARTH_RADIUS)
# Again, convert it to a cartopy projection
cs_tgt_cart = cs_tgt.as_cartopy_projection()

最后,使用cartopy的变换方法将原生投影中的二维坐标数组转换为目标投影中的坐标。

lons, lats, _ = cs_tgt_cart.transform_points(cs_nat_cart, xx, yy).T
# Note the transpose at the end.

还要注意上面的函数总是returnsz坐标数组,但在本例中是0.

然后您可以使用 lonslats 在 Google 地图或其他应用程序中绘制您的数据。请记住,这些新坐标是曲线的,因此实际上必须是二维数组。

但是,如果您想要绘制 iris(和 matplotlib)中的数据,您可以这样做:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt


proj_x = cube.coord("projection_x_coordinate").points
proj_y = cube.coord("projection_y_coordinate").points
cs_nat_cart = cube.coord_system().as_cartopy_projection()

fig = plt.figure()
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
ax.pcolormesh(proj_x, proj_y, cube.data, transform=cs_nat_cart)
ax.coastlines()

希望对您有所帮助。