如何将netcdf iris cube中的投影x和y坐标转换为lat lon

2024-09-21 13:51:36 发布

您现在位置:Python中文网/ 问答频道 /正文

请看上面的问题,只想从IrisCube获取谷歌地图的lat/lon

cube.coord_system()

LambertAzimuthalEqualArea(投影起点纬度=54.9,投影起点经度=2.5,假东距=0.0,假北距=0.0,椭球面=GeogCS(半长轴=6378137.0,半短轴=6356752.314140356))

enter image description here


Tags: 地图system投影lon起点latcubecoord
1条回答
网友
1楼 · 发布于 2024-09-21 13:51:36

如果只想变换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.

还要注意,上面的函数总是返回z坐标数组,但在本例中为0

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

但是,如果要在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()

希望这有帮助

相关问题 更多 >

    热门问题