极稀疏网格插值在乡村热图生成中的应用

2024-10-01 07:12:47 发布

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

我有一个随时间推移的每个国家的事件数据集,我想在事件发生的同一时间段内创建一个变化的热图。到目前为止,我已经:

        ax2 = plt.axes(projection=ccrs.Miller())
        ax2.set_global()
        ax2.coastlines()
        ax2.add_feature(cfeature.OCEAN, zorder=0)
        ax2.add_feature(cfeature.BORDERS, linewidth=0.6)
        ax2.set_title('Second axis plot')

        grid_z0 = griddata(points, values, (x2d, y2d), method='cubic', fill_value=0)
        print grid_z0

        cnt = ax2.pcolormesh(lons_new, lats_new, grid_z0,
         transform=ccrs.PlateCarree(), cmap = cmap, alpha = 0.5)

        plt.show()

在哪里

  • 点/值是通过指定 事件数量的国家(因此对于第一次迭代): 阿根廷具有“1”的所有价值观,英国具有“1”的所有价值。在
  • x2d,y2d是:

       lats_new = np.linspace(-90, 90, 91)
       lons_new = np.linspace(-180, 180, 91)
       x2d, y2d = np.meshgrid(lons_new, lats_new)
    

这将产生: first incident

我要实现的是:基于距离的插值(即我所附的图中的两个国家应该是分开的红色的,在边界处逐渐消失)。我尝试过scipy的一些插值方法,但似乎都做得不好(2d,以及griddata中的所有方法)。在


Tags: addnewnp事件plt国家gridset
1条回答
网友
1楼 · 发布于 2024-10-01 07:12:47

修正了使用高斯滤波器插值矩阵前轮廓:

    图像作为事件值的二元矩阵(英国中的一个事件) 一个在阿根廷)。此处显示为彩色网格:

    Color mesh before Guassian filter

  1. 对世界各地的掩模矩阵应用高斯滤波器:

        sigma_y = 3.0
        sigma_x = 3.0
    
        sigma = [sigma_y, sigma_x]
    
        y = sp.ndimage.filters.gaussian_filter(grid_new, sigma, mode='constant')
    

其中grid_new是事件值的二维矩阵。使用guassian过滤器后的彩色网格: Matrix after guassian filter seen as a pcolormesh

  1. 将.contourf函数应用于guassian过滤矩阵: Contourf of gaussian filtered matrix

相关问题 更多 >