Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

风场图

本节介绍如何使用 cedarkit-plots 绘制 850 hPa 风场图。

首先导入需要使用的包。包括:

  • 数据结构:numpy, pandas

  • 可视化:matplotlib

  • cedarkit 工具套件

    • 数据准备:reki

      • 数据查找函数: find_local_file

      • GRIB2文件要素加载函数:load_field_from_file

    • 气象可视化:cedarkit.plots

      • 绘图板:Panel

      • 底图布局:EastAsiaMapDomain

      • 绘图样式:BarbStyle

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 BarbStyle
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_path
PosixPath('/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 的内置要素名为 uv

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
)
v_850_field
Loading...

配置

定义风场图样式 (BarbStyle)

wind_barb_style = BarbStyle(
    barbcolor="red",
    flagcolor="red",
    linewidth=0.3,
)

绘制

创建中国区域底图布局

domain = EastAsiaMapTemplate()

绘图风场图,设置标题。

注:这里将风场稀疏化后再绘图,并只在主区域(第 1 层)绘图,即 layer=[0]

panel = Panel(domain=domain)
panel.plot([[u_850_field[::14, ::14], v_850_field[::14, ::14]]], style=wind_barb_style, layer=[0])

domain.set_title(
    panel=panel,
    graph_name="850 hPa WIND (m/s) windbarb",
    system_name=system_name,
    start_time=start_time,
    forecast_time=forecast_time,
)
panel.show()
<Figure size 3200x3200 with 2 Axes>