How to plot geolocated RGB data faster using Python basemap

雨燕双飞 提交于 2019-12-05 14:53:43

I solved this issue by added the 1.0 to the value of every part of the colorTuple to turn it into an RGBA array. I went through the pcolormesh function and found that it was calling the color convertor to convert the RGB to an RGBA array 4 different times, taking about 50 seconds each time. If you give it an RGBA array to start, it will bypass this and produce the plot in a reasonable timeframe. The additional line of code that was added is seen below:

if one_channel:
    m.pcolormesh(lons, lats, img[:,:,0], latlon=True)
else:
    mesh_rgb = img[:, :-1, :]
    colorTuple = mesh_rgb.reshape((mesh_rgb.shape[0] * mesh_rgb.shape[1]), 3)

    # ADDED THIS LINE
    colorTuple = np.insert(colorTuple,3,1.0,axis=1)

    # What you put in for the image doesn't matter because of the color mapping
    m.pcolormesh(lons, lats, img[:,:,0], latlon=True,color=colorTuple)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!