本节介绍如何使用 cedarkit-plots 绘制 500hPa 位势高度等值线图。
首先导入需要使用的包。包括:
数据结构:numpy, pandas
cedarkit 工具套件
数据准备:reki
数据查找函数:
find_local_fileGRIB2文件要素加载函数:
load_field_from_file
气象可视化:cedarkit.plots
绘图板:
Panel底图布局:
EastAsiaMapTemplate绘图样式:
ContourStyle,ContourLabelStyle
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, ContourLabelStyle
from cedarkit.plots.chart import Panel
from cedarkit.plots.domains import EastAsiaMapTemplate/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')加载 500 hPa 位势高度场。位势高度在 ecCodes 的内置要素名为 gh
h_500_field = load_field_from_file(
file_path,
parameter="gh",
level_type="pl",
level=500
) / 10.0
h_500_fieldLoading...
配置¶
定义等值线层次
h_contour_lev = np.linspace(500, 588, endpoint=True, num=23)
h_contour_levarray([500., 504., 508., 512., 516., 520., 524., 528., 532., 536., 540.,
544., 548., 552., 556., 560., 564., 568., 572., 576., 580., 584.,
588.])定义等值线颜色
h_contour_colos = "blue"定义线宽
h_linewidths = np.where(h_contour_lev == 588, 1.4, 0.7)定义等值线样式 (ContourStyle),包括等值线标签样式 (ContourLabelStyle)
hgt_style = ContourStyle(
levels=h_contour_lev,
colors="blue",
linewidths=h_linewidths,
label=True,
label_style=ContourLabelStyle(
colors="black",
fontsize=8,
)
)绘制¶
创建中国区域底图布局
domain = EastAsiaMapTemplate()绘制等值线,设置标题
panel = Panel(domain=domain)
panel.plot(h_500_field, style=hgt_style)
domain.set_title(
panel=panel,
graph_name="500 hPa Height(10gpm)",
system_name=system_name,
start_time=start_time,
forecast_time=forecast_time,
)
panel.show()