本节介绍如何使用 cedarkit-plots 绘制 850 hPa 风速填充图。
首先导入需要使用的包。包括:
数据结构:numpy, pandas
cedarkit 工具套件
数据准备:reki
数据查找函数:
find_local_fileGRIB2文件要素加载函数:
load_field_from_file
气象可视化:cedarkit.plots
绘图板:
Panel底图布局:
EastAsiaMapDomain绘图样式:
ContourStyle颜色表加载函数:
get_ncl_colormap
import numpy as np
import pandas as pd
from reki.data_finder import find_local_file
from reki.format.grib.eccodes import load_field_from_file
from cedarkit.plots.style import ContourStyle
from cedarkit.plots.chart import Panel
from cedarkit.plots.domains import EastAsiaMapTemplate
from cedarkit.plots.colormap import get_ncl_colormap/home/wangdp/project/cedarkit/notebook-project/notebook-devel/repo/cedarkit-notebook-project/cedarkit-notebook/.venv/lib/python3.14/site-packages/gribapi/__init__.py:23: UserWarning: ecCodes 2.42.0 or higher is recommended. You are running version 2.34.1
warnings.warn(
# 数据环境配置:使用本地数据目录(可用环境变量 CEDARKIT_NOTEBOOK_DATA_ROOT 覆盖)
from cedarkit_notebook.data import get_data_root, get_dataset_query
DATA_CLASS = "cmadaas"
STORAGE_BASE = str(get_data_root())
设置绘图的数据参数,使用 CMA-GFS 最近可获取的时次 024 数据。
system_name = "CMA-GFS"
data_type = "cma_gfs_gmf/grib2/orig"
# 起报时次与预报时效固定为本地已下载数据(见 data/metadata/cma-gfs.yaml)
query = get_dataset_query("cma-gfs")
start_time = pd.to_datetime(query["start_time"], format="%Y%m%d%H")
forecast_time = pd.to_timedelta(query["forecast_time"])加载数据¶
获取 GRIB2 数据路径
file_path = find_local_file(
data_type,
start_time=start_time,
forecast_time=forecast_time,
data_class=DATA_CLASS,
storage_base=STORAGE_BASE
)
file_pathPosixPath('/home/wangdp/project/cedarkit/notebook-project/notebook-devel/repo/cedarkit-notebook-project/cedarkit-notebook/data/DATA/NAFP/NMC/GRAPES-GFS-GLB/2026/20260725/Z_NAFP_C_BABJ_20260725000000_P_NWPC-GRAPES-GFS-GLB-02400.grib2')加载 850 hPa 风场。风场在 ecCodes 的内置要素名为 u 和 v
u_850_field = load_field_from_file(
file_path,
parameter="u",
level_type="pl",
level=850
)
v_850_field = load_field_from_file(
file_path,
parameter="v",
level_type="pl",
level=850
)
u_850_fieldLoading...
计算得到风速场
wind_speed_850_field = np.sqrt(u_850_field ** 2 + v_850_field ** 2)
wind_speed_850_fieldLoading...
配置¶
定义填充图层次
wind_speed_contour_lev = np.arange(8, 26, 2)定义填充图色表
color_index = np.arange(90, 236, 15) - 2
color_index[0] = -1
wind_speed_color_map = get_ncl_colormap(
"rainbow+white+gray", index=color_index
)定义填充图样式 (ContourStyle)
wind_speed_style = ContourStyle(
colors=wind_speed_color_map,
levels=wind_speed_contour_lev,
fill=True,
)绘制¶
创建中国区域底图布局
domain = EastAsiaMapTemplate()绘制填充图,设置标题和颜色条
panel = Panel(domain=domain)
panel.plot(wind_speed_850_field, style=wind_speed_style)
domain.set_title(
panel=panel,
graph_name="850 hPa WIND (m/s) shadow",
system_name=system_name,
start_time=start_time,
forecast_time=forecast_time,
)
domain.add_colorbar(panel=panel, style=wind_speed_style)
panel.show()