You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:高斯网格GRIB转NetCDF时多工具报错问题

高斯网格SZIP压缩GRIB转NetCDF格式问题解决

文件基本信息

目标GRIB文件为高斯网格全球数据,格式为SZIP压缩,文件详情如下:

File format : GRIB szip
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter ID
     1 : MPIMET   unknown  v instant       1   1    294912   1  P24s : 182.128
   Grid coordinates :
     1 : gaussian                 : points=294912 (768x384)  F192
                              lon : 0 to 359.5312 by 0.46875 degrees_east  circular
                              lat : 89.64165 to -89.64165 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  unlimited steps

已尝试的转换方式及报错

1. CDO转换(缺少SZIP支持)

执行命令:

cdo -f nc copy input.grb output.nc

报错:

Warning (gribUnzip): Decompression disabled, szlib not available!

Error (grbUnzipRecord): Decompression problem!

2. cfgrib/xarray维度冲突

执行代码:

import xarray as xr
import cfgrib
import eccodes

ds = cfgrib.open_datasets('input.nc',backend_kwargs={'filter_by_keys': {'typeOfLevel':'surface','level':0,'shortName': 'e'}})

报错:

ValueError: conflicting sizes for dimension 'latitude': length 384 on 'e' and length 285 on {'time': 'time', 'step': 'step', 'surface': 'surface', 'latitude': 'latitude', 'longitude': 'longitude'}

3. gdalwarp比特数不匹配

执行命令:

gdalwarp -overwrite -to SRC_METHOD=NO_GEOTRANSFORM -t_srs EPSG:4326 input.grb -of netCDF output.nc

报错:

numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5244760
Creating output file that is 768P x 384L.
Processing /scistor/ivm/hmt250/raed_paper/swift.dkrz.de/clisap_echam_182/CLI_MPI-ESM-XR_t255l95_echam_265-276.cdo_processed.grb [1/1] : 0numPts * (numBits in a Group) + # of unused bits 7077896 != # of available bits 5225512
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5265624
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5258632
numPts * (numBits in a Group) + # of unused bits 7077896 != # of available bits 5275464
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5352712

4. grib_to_netcdf维度边界超出

执行命令:

grib_to_netcdf -o output2.nc input.grb

报错:

grib_to_netcdf: Version 2.21.0
grib_to_netcdf: Processing input file 'input.grb'.
grib_to_netcdf: Found 8760 GRIB fields in 1 file.
grib_to_netcdf: Ignoring key(s): method, type, stream, refdate, hdate
grib_to_netcdf: Creating netCDF file 'output2.nc'
grib_to_netcdf: NetCDF library version: 4.7.4 of Oct 29 2020 15:05:42 $
grib_to_netcdf: Creating large (64 bit) file format.
grib_to_netcdf: Defining variable 'e'.

grib_to_netcdf ERROR: line 2863, nc_put_vara_type: NetCDF: Start+count exceeds dimension bound

解决方案

方案1:修复CDO的SZIP支持(优先推荐)

CDO报错核心是未链接szlib库,即便安装了eccodes,CDO可能独立编译未关联szip。解决方式:

  • 用conda重新安装带SZIP支持的CDO:
    conda install -c conda-forge cdo eccodes szip
    
  • 验证支持:执行cdo --version,输出中应包含szlib字样。
  • 重新转换:
    cdo -f nc copy input.grb output.nc
    
  • 若仍有问题,先解压GRIB再转换:
    grib_copy -w unpack=1 input.grb input_unpacked.grb
    cdo -f nc copy input_unpacked.grb output.nc
    

方案2:修复cfgrib维度冲突

维度冲突因GRIB文件中存在不同网格的字段,先排查所有字段的网格信息:

grib_ls -N input.grb

然后过滤出目标高斯网格(768x384)的字段:

import xarray as xr
ds = xr.open_dataset(
    'input.grb',
    engine='cfgrib',
    backend_kwargs={
        'filter_by_keys': {
            'typeOfLevel': 'surface',
            'Nx': 768,
            'Ny': 384
        }
    }
)
ds.to_netcdf('output.nc')

方案3:修复grib_to_netcdf维度错误

尝试添加-M参数处理多字段,或指定维度顺序:

grib_to_netcdf -M -o output2.nc input.grb

若仍失败,拆分GRIB文件后逐个转换再合并:

# 拆分GRIB为单个字段文件
grib_copy input.grb "split_%.grb"
# 逐个转换为NetCDF
for f in split_*.grb; do
    grib_to_netcdf -o "${f%.grb}.nc" "$f"
done
# 合并所有NetCDF文件
ncrcat split_*.nc output_merged.nc

内容的提问来源于stack exchange,提问作者Henrique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 19:20:50