写在前面
cdo 是个很好用的工具,一行命令可以实现插值、经度转换、提取变量等等功能
但是,有时候由于数据的grid coordinates的原因,在使用相关命令时会出现报错提示:
比如说:
- 插值
remapcon (Abort): Unsupported generic coordinates (Variable: info)!
这个问题我经常遇到,也早就已经被人在CDO官网论坛和stackoverflow网站上挂起,其原因也早就被人探索过。问题在于
你的netcdf文件中的网格属性为: Grid coordinates :generic ;或者是同时具有generic和lonlat
这可以通过cdo infos infile.nc来查看

问题1:当你的Grid coordinates 为generic时
解决方法如下
- 使用
setgrid运算符解决这个问题,创建一个网格文件,这个文件与您给出的文件相同,但是用lonlat替换原本的generic
cdo griddes infile.nc > mygrid
sed -i "s/generic/lonlat/g" mygrid
cdo setgrid,mygrid infile.nc infile_fixedgrid.nc
按照上面的步骤,我这里的文件名称为: olr.day.mean.nc,所以只需要
cdo griddes olr.day.mean.nc > mygrid
sed -i "s/generic/lonlat/g" mygrid
cdo setgrid,mygrid olr.day.mean.nc olr.day.mean_regrid.nc
然后下面对于olr.day.mean_regrid.nc重新进行插值或者其他相关命令即可
其实可以打开mygrid这个文件看看里面是啥
cat mygrid
打开后显示如下内容,其实就是包含了你原有数据的一些信息,如果里面的内容缺失的话,还可以自己手动补足添加
#
# gridID 1
#
gridtype = lonlat
gridsize = 7
xsize = 7
#
# gridID 2
#
gridtype = lonlat
gridsize = 10512
datatype = float
xsize = 144
ysize = 73
xname = lon
xlongname = "Longitude"
xunits = "degrees_east"
yname = lat
ylongname = "Latitude"
yunits = "degrees_north"
xfirst = 0
xinc = 2.5
yfirst = 90
yinc = -2.5
问题2:当你的Grid coordinates 同时具有generic和lonlat
这种情况就更简单了,由于你的数据本身是含有lonlat的属性的,所以只需要把lonlat取出来即可
cdo selgrid,lonlat olr.day.mean.nc olr.day.mean_grid.nc
其中,第一个nc文件为原始文件,第二个nc文件为取出lonlat属性后的输出文件名称
取出来可以查看数据信息
cdo infos olr.day.mean_grid.nc
File format : NetCDF4 classic
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter ID
1 : unknown ftp.cpc.ncep v instant 1 1 10512 1 F32 : -1
Grid coordinates :
1 : lonlat : points=10512 (144x73)
lon : 0 to 357.5 by 2.5 degrees_east circular
lat : 90 to -90 by -2.5 degrees_north
Vertical coordinates :
1 : surface : levels=1
Time coordinate : 17746 steps
RefTime = 1800-01-01 00:00:00 Units = hours Calendar = standard
YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
1974-06-01 00:00:00 1974-06-02 00:00:00 1974-06-03 00:00:00 1974-06-04 00:00:00
1974-06-05 00:00:00 1974-06-06 00:00:00 1974-06-07 00:00:00 1974-06-08 00:00:00
1974-06-09 00:00:00 1974-06-10 00:00:00 1974-06-11 00:00:00 1974-06-12 00:00:00
1974-06-13 00:00:00 1974-06-14 00:00:00 1974-06-15 00:00:00 1974-06-16 00:00:00
1974-06-17 00:00:00 1974-06-18 00:00:00 1974-06-19 00:00:00 1974-06-20 00:00:00
1974-06-21 00:00:00 1974-06-22 00:00:00 1974-06-23 00:00:00 1974-06-24 00:00:00
1974-06-25 00:00:00 1974-06-26 00:00:00 1974-06-27 00:00:00 1974-06-28 00:00:00
1974-06-29 00:00:00 1974-06-30 00:00:00 1974-07-01 00:00:00 1974-07-02 00:00:00
1974-07-03 00:00:00 1974-07-04 00:00:00 1974-07-05 00:00:00 1974-07-06 00:00:00
1974-07-07 00:00:00 1974-07-08 00:00:00 1974-07-09 00:00:00 1974-07-10 00:00:00
1974-07-11 00:00:00 1974-07-12 00:00:00 1974-07-13 00:00:00 1974-07-14 00:00:00
1974-07-15 00:00:00 1974-07-16 00:00:00 1974-07-17 00:00:00 1974-07-18 00:00:00
1974-07-19 00:00:00 1974-07-20 00:00:00 1974-07-21 00:00:00 1974-07-22 00:00:00
1974-07-23 00:00:00 1974-07-24 00:00:00 1974-07-25 00:00:00 1974-07-26 00:00:00
1974-07-27 00:00:00 1974-07-28 00:00:00 1974-07-29 00:00:00 1974-07-30 00:00:00
................................................................................
................................................................................
................................................................................
.........
2022-11-04 00:00:00 2022-11-05 00:00:00 2022-11-06 00:00:00 2022-11-07 00:00:00
2022-11-08 00:00:00 2022-11-09 00:00:00 2022-11-10 00:00:00 2022-11-11 00:00:00
2022-11-12 00:00:00 2022-11-13 00:00:00 2022-11-14 00:00:00 2022-11-15 00:00:00
2022-11-16 00:00:00 2022-11-17 00:00:00 2022-11-18 00:00:00 2022-11-19 00:00:00
2022-11-20 00:00:00 2022-11-21 00:00:00 2022-11-22 00:00:00 2022-11-23 00:00:00
2022-11-24 00:00:00 2022-11-25 00:00:00 2022-11-26 00:00:00 2022-11-27 00:00:00
2022-11-28 00:00:00 2022-11-29 00:00:00 2022-11-30 00:00:00 2022-12-01 00:00:00
2022-12-02 00:00:00 2022-12-03 00:00:00 2022-12-04 00:00:00 2022-12-05 00:00:00
2022-12-06 00:00:00 2022-12-07 00:00:00 2022-12-08 00:00:00 2022-12-09 00:00:00
2022-12-10 00:00:00 2022-12-11 00:00:00 2022-12-12 00:00:00 2022-12-13 00:00:00
2022-12-14 00:00:00 2022-12-15 00:00:00 2022-12-16 00:00:00 2022-12-17 00:00:00
2022-12-18 00:00:00 2022-12-19 00:00:00 2022-12-20 00:00:00 2022-12-21 00:00:00
2022-12-22 00:00:00 2022-12-23 00:00:00 2022-12-24 00:00:00 2022-12-25 00:00:00
2022-12-26 00:00:00 2022-12-27 00:00:00 2022-12-28 00:00:00 2022-12-29 00:00:00
2022-12-30 00:00:00 2022-12-31 00:00:00
cdo sinfo: Processed 1 variable over 17746 timesteps [0.22s 13MB].
下面就可以继续进行相关命令了
问题3: 垂直层具有两种gridtype
这里指的是你的数据中关于 Vertical coordinates 这一项
一般来说都是surface :levels =1 ,只有表面一层的数据
但是也有例外,比如说:
垂直坐标具有不同的pramameter ID
surface - generic
pressure level - lonlat
cdo -sellonlatbox,-120,240,-90,90 -selparam,-1 in.nc. out.nc
不得不说,cdo的手册还是值得多研究

来测试一下自动回复的功能,想获取cdo常用命令手册的可以在后台输入关键字: cdo
虽然网上到处都是。。。
https://code.mpimet.mpg.de/boards/2/topics/8946
https://stackoverflow.com/questions/67986451/converting-generic-grid-type-to-a-lonlat-gridtype-using-cdo
https://sourceforge.net/p/nco/discussion/9829/thread/82eaf81e84/
https://blog.csdn.net/weixin_44237337/article/details/121614319