CATTOPY/MATPLOTLIB SAVEFIG慢速投影
我们正在从基地迁移到cartoy迁移,并找到savefig
功能对于我们的应用程序来说太慢了,特别是在使用lambertConformal CRS时。我使用下面的“代码”片段进行了快速检查,发现使用LambertConformal投影与PlateCarree所需的时间约为10倍。我们应用程序中的图包括许多数据层,包括菌落和轮廓,但我发现savefig
在使用LCC CRS时始终要慢得多。我看到其他人建议用户设置pyproj_global_context = on
,但是由于我们的应用程序是多线程,因此对我们来说不是一个选择。如果需要,我们可以采用Platecarree CRS作为默认值,但我想我会检查社区中的其他用户是否也有类似的问题。
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import time
extent = [-10, 10, 50, 60]
lcc_projection = ccrs.LambertConformal(
central_latitude=55,
central_longitude=0,
)
pc_projection = ccrs.PlateCarree()
pc_plot = plt.axes(projection=pc_projection, facecolor="dimgrey")
pc_plot.set_extent(extent, crs=pc_projection)
pc_plot.add_feature(cfeature.LAND)
t = time.time()
plt.savefig('map_pc.png')
print(f"pc savefig time : {time.time() - t}") # Takes ~3s
plt.close()
lcc_plot = plt.axes(projection=lcc_projection, facecolor="dimgrey")
lcc_plot.set_extent(extent, crs=pc_projection)
lcc_plot.add_feature(cfeature.LAND)
t = time.time()
plt.savefig('map_lcc.png')
print(f"lcc savefig time : {time.time() - t}") # Takes ~30s
plt.close()
结果图像:
We're in the process of migrating from Basemap to Cartoy and finding the savefig
functionality to be a far too slow for our app, specifically when using the LambertConformal CRS. I ran a quick check using the the code snippet below and found that it takes about 10x as long to save using the LambertConformal projection vs PlateCarree. The plots within our app include numerous data layers including colormaps and contours but I found that savefig
is consistently much slower when using the LCC CRS. I saw that others suggested users set PYPROJ_GLOBAL_CONTEXT=ON
but since our app is multithreaded that isn't an option for us. We can adopt the PlateCarree CRS as our default if needed but I thought I would check to see if other users in the community had similar issues.
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import time
extent = [-10, 10, 50, 60]
lcc_projection = ccrs.LambertConformal(
central_latitude=55,
central_longitude=0,
)
pc_projection = ccrs.PlateCarree()
pc_plot = plt.axes(projection=pc_projection, facecolor="dimgrey")
pc_plot.set_extent(extent, crs=pc_projection)
pc_plot.add_feature(cfeature.LAND)
t = time.time()
plt.savefig('map_pc.png')
print(f"pc savefig time : {time.time() - t}") # Takes ~3s
plt.close()
lcc_plot = plt.axes(projection=lcc_projection, facecolor="dimgrey")
lcc_plot.set_extent(extent, crs=pc_projection)
lcc_plot.add_feature(cfeature.LAND)
t = time.time()
plt.savefig('map_lcc.png')
print(f"lcc savefig time : {time.time() - t}") # Takes ~30s
plt.close()
Resulting images:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论