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.

GRIB2

CEMC 数值天气预报业务系统 (简称 NWP 业务系统) 发布 GRIB2 格式的基础数据产品。 reki 调用 ECMWF 开发的 ecCodes 和 cfgrib 加载 GRIB2 文件中的要素场。

首先加载需要使用的模块

import numpy as np
import pandas as pd
import xarray as xr

from reki.format.grib.eccodes import load_field_from_file
from reki.data_finder import find_local_file
/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())

查找示例 GRIB2 文件路径

# 起报时次与预报时效固定为本地已下载数据(见 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"])

gfs_grib2_orig_file_path = find_local_file(
    "cma_gfs_gmf/grib2/orig",
    start_time=start_time,
    forecast_time=forecast_time,
    file_type="grib2",
    file_format="orig",
    data_class=DATA_CLASS,
    storage_base=STORAGE_BASE
)
gfs_grib2_orig_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')

基础用法

reki.format.grib.eccodes.load_field_from_file() 函数从本地 GRIB 文件中加载要素场。 该函数常用参数如下:

  • file_path: GRIB 文件路径

  • parameter: 要素名

  • level_type: 层次类型

  • level: 层次值

下面代码加载 850hPa 温度场。

field = load_field_from_file(
    gfs_grib2_orig_file_path,
    parameter="t",
    level_type="pl",
    level=850
)
field
Loading...

详细说明

请浏览以下章节: