Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用简化地图的方式对地图绘图模块进行性能优化 #74

Open
Clarmy opened this issue Aug 17, 2022 · 0 comments
Open

使用简化地图的方式对地图绘图模块进行性能优化 #74

Clarmy opened this issue Aug 17, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Clarmy
Copy link
Member

Clarmy commented Aug 17, 2022

在 Intel MacBook Pro 上的测试,下列脚本在1.1.0版本下的执行耗时仍然需要大约1分钟左右才能出图,这速度有点无法接受,这个慢的主要原因是矢量边界过于精细,需要处理的点太多,计算压力大。但是对于类似下面这种尺度的绘图,其实并不需要这么精细的边界数据,因此可以尝试将其精细度进行简化,达到一个不那么精细,但是出图效果从肉眼也察觉不出来的那种程度。

geopandas 提供了 simplify 的函数

import time

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cnmaps import get_adm_maps, clip_contours_by_map, draw_map
from cnmaps.sample import load_dem

lons, lats, data = load_dem()

t0 = time.time()
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
map_polygon = get_adm_maps(country="中华人民共和国", record="first", only_polygon=True)

cs = ax.contourf(
    lons,
    lats,
    data,
    cmap=plt.cm.terrain,
    levels=np.linspace(-2800, data.max(), 10),
    transform=ccrs.PlateCarree(),
)

clip_contours_by_map(cs, map_polygon)
draw_map(map_polygon, color="k", linewidth=1)

plt.savefig('./china.png')

t1 = time.time()

time_delta = t1 - t0

print("time_delta", time_delta)
@Clarmy Clarmy self-assigned this Aug 17, 2022
@Clarmy Clarmy changed the title 对画图模块的性能优化 使用简化地图的方式对地图绘图模块进行性能优化 Aug 17, 2022
@Clarmy Clarmy added the enhancement New feature or request label Aug 17, 2022
@Clarmy Clarmy added this to the v-1.2.* milestone Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant