# NavSea Weather Server Step-1 GRIB 解析环境测试 目标: 验证服务器可以正确解析 GRIB 文件。 --- # 1 安装系统依赖 在 Linux 服务器执行: apt update apt install -y python3 python3-pip apt install -y libeccodes0 libeccodes-dev apt install -y python3-eccodes --- # 2 安装 Python 库 pip3 install cfgrib pip3 install xarray pip3 install numpy --- # 3 下载测试 GRIB 文件 创建测试目录: mkdir weather_test cd weather_test 下载 NOAA GFS 示例: wget https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.20260312/00/atmos/gfs.t00z.pgrb2.0p25.f003 -O test.grib2 (如果日期目录不存在,可以换最新日期) --- # 4 创建测试脚本 创建文件: test_grib.py 内容: import xarray as xr file = "test.grib2" print("Opening GRIB file...") ds = xr.open_dataset(file, engine="cfgrib") print("Dataset loaded") print(ds) print("\nVariables:") print(ds.data_vars) --- # 5 运行测试 python3 test_grib.py 如果成功,你会看到类似输出: Dataset loaded Dimensions: latitude: 721 longitude: 1440 Variables: u10 v10 t2m msl tp --- # 6 测试读取风数据 修改脚本: import xarray as xr import numpy as np file = "test.grib2" ds = xr.open_dataset(file, engine="cfgrib") u = ds['u10'] v = ds['v10'] speed = np.sqrt(u**2 + v**2) print("Wind sample:") print(speed.values[0][0]) --- # 7 成功标志 如果成功运行: 说明: GRIB解析正常 Python环境正常 可以进入 Weather Server 开发 --- # 8 常见错误 错误: eccodes library not found 解决: apt install libeccodes-dev --- # 9 完成后下一步 下一步开发: GRIB Downloader 模块: weather_server/downloader/gfs_downloader.py 负责: 自动下载 GFS GRIB 数据。