【问题标题】:how to convert projection x and y coordinate in netcdf iris cube to lat lon如何将netcdf iris cube中的投影x和y坐标转换为lat lon
【发布时间】:2020-10-02 10:09:23
【问题描述】:

查看上面的问题,只想从 Iris cube 获取 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))

【问题讨论】:

    标签: python netcdf python-iris


    【解决方案1】:

    如果您只想转换 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的transform方法将原生投影中的二维坐标数组转换为目标投影中的坐标。

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

    还要注意,上面的函数总是返回z坐标数组,但在本例中为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()
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-03-31
      • 2022-12-14
      • 2010-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      • 2020-10-09
      • 2019-12-29
      相关资源
      最近更新 更多