使用NCO ncremap重映射NetCDF文件时遇错误求助
解决NCO ncremap重映射时的全零权重错误
问题背景
拥有变量结构相同但网格随时间周期性偏移的NetCDF数据集,执行ncremap重映射时触发错误:
ncks: ERROR nco_rgr_wgt() reports frc_out == frac_b contains all zeros ncremap: ERROR Failed to horizontally regrid. cmd_rgr[0] failed.
CDO的remapbil可完成重映射,但会修改变量组织与命名,不符合需求。
解决方案
1. 显式指定源/目标网格的经纬度变量名
如果数据集的经纬度变量名不是默认的lat/lon,需显式指定避免识别错误:
ncremap -d 2016090618.nc -i 2016090712.nc -o outputfile_2016090712.nc --rgr lat_nm_in=src_lat#lon_nm_in=src_lon --rgr lat_nm_out=dst_lat#lon_nm_out=dst_lon
替换src_lat/src_lon为源文件的经纬度变量名,dst_lat/dst_lon为目标文件的对应变量名。
2. 手动生成双线性重映射权重文件
默认保守重映射可能不适应周期性偏移网格,改用双线性方法,先生成权重文件再重映射:
# 生成双线性重映射权重 ncremap -g 2016090618.nc -G 2016090712.nc -w bilinear_weights.nc --rgr meth=bilinear # 使用权重文件执行重映射 ncremap -i 2016090712.nc -o outputfile_2016090712.nc -w bilinear_weights.nc
3. 开启周期性边界支持
针对周期性偏移的网格,告知ncremap经度维度是周期性的:
ncremap -d 2016090618.nc -i 2016090712.nc -o outputfile_2016090712.nc --rgr cyclic=lon
4. 统一源/目标文件的维度顺序
确保源和目标文件的维度顺序一致(如time, lat, lon),不一致时先用ncpdq调整:
# 调整源文件维度顺序 ncpdq -a time,lat,lon 2016090712.nc 2016090712_reordered.nc # 执行重映射 ncremap -d 2016090618.nc -i 2016090712_reordered.nc -o outputfile_2016090712.nc
5. 升级NCO版本
Google Colab中的NCO版本可能较旧,升级到最新版本尝试:
!apt-get remove -y nco !apt-get install -y nco
内容的提问来源于stack exchange,提问作者Rob
相关产品推荐
相关产品推荐

