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.

本地文件

本地文件 是支持 POSIX 协议通过文件路径访问的文件,包括但不限于:

  • 本机存储系统中的文件

  • 共享存储系统中的文件,例如超算平台的存储系统

  • 网络挂载存储中的文件,例如挂载的二级存储

cedarkit 工具套件中数据准备工具库 reki 支持从文件系统中加载要素场。

本节介绍 reki 库基本使用方法,随后几个章节介绍其他支持加载 GRIB2 要素场的工具库如何与 cedarkit-plots 对接,包括:

reki

reki 库的 reki.data_finder 模块包含本地文件查找函数 find_local_file,可以使用内置的配置文件查找 CMA 超算平台中的 CEMC 业务系统数据产品。

reki 库的 reki.format.grib 模块包含要素加载函数 load_field_from_file,支持从本地文件中加载一个要素场。

导入需要的包

import xarray as xr
import pandas as pd
from reki.data_finder import find_local_file
from reki.format.grib import load_field_from_file

# 数据环境配置:使用本地数据目录(可用环境变量 CEDARKIT_NOTEBOOK_DATA_ROOT 覆盖)
from cedarkit_notebook.data import get_data_root, get_dataset_query
/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(
DATA_CLASS = "cmadaas"
STORAGE_BASE = str(get_data_root())

设置绘图的数据参数,使用 CMA-GEPS 最近可获取的时次 024 时效集合成员 1 的数据。

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')

加载 2 米温度要素场。

t_2m_field = load_field_from_file(
    file_path,
    parameter="2t",  
) - 273.15
t_2m_field
Loading...

绘图

使用 cedarkit-plots 绘制 2 米温度填充图

Source
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

t_2m_level = [-24, -20, -16, -12, -8, -4, 0, 4, 8, 12, 16, 20, 24, 28, 32]
color_index = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152]
t_2m_color_map = get_ncl_colormap("BlAqGrYeOrReVi200", index=color_index)
t_2m_style = ContourStyle(
    colors=t_2m_color_map,
    levels=t_2m_level,
    fill=True,
)
domain = EastAsiaMapTemplate()
panel = Panel(domain=domain)
panel.plot(t_2m_field, style=t_2m_style)
domain.set_title(
    panel=panel,
    graph_name="2m Temperature (C)",
    system_name=system_name,
    start_time=start_time,
    forecast_time=forecast_time,
)
domain.add_colorbar(panel=panel, style=t_2m_style)
panel.show()
<Figure size 3200x3200 with 2 Axes>