介绍

  • CDO——Climate Data Operators
  • grads数据格式,这是一种气象业务及早期模式后处理需要的图形语言,它的标准包括了一个数据描述文件,一般是xxx.ctl 和一个二进制的存数据流文件(这种文件又细分为C系列语言生成的,和Fortran直接生成的,区别在于前者没有数据区块的概念,后者则有一定的分段big_endian)
  • netcdf数据格式:这里就不罗嗦了简单说就是自描述的数据格式,优点是可移植性好,缺点是大。

    数据类型

    GrADS 数据 grd ctl

    为什么要这么干?

    其实grads,它能很方便的查看数值模式的输出结果(图像化),但是目前很多的高级语言其实对其支持并不友好,因此诞生了将其转化成netcdf格式的想法。

    实现方案

    在你的linux系统或者mac系统上使用/
    上面的特殊条件是因为CDO对windows的兼容并不好,还需要调用额外的linux模拟器。而且推荐在linux系统上进行,大型机上把数据打包转化好再用本地机子的脚本处理数据。
    CDO官网下载适当的版本(我用的1.7.2,因为最新版我接触的大型机上C++11库没有,不想太过麻烦)的tar.gz文件,解压后进入所得目录,用下面的代码段安装:
    1. //HDF库是可选的,因为之后数据类型也会用到就顺便安装了,这个和本篇无关。
    2. ./configure --prefix "指定安装目录"
    3. --with-netcdf="你机子上netcdf的根目录"
    4. --with-hdf5="你机子上HDF的根目录"
  1. 使用命令cdo -b F64 -f nc import_binary “你的CTL文件” “希望输出的文件.nc” 这样只要在你的ctl里描述时间变量以及多个模式输出结果文件程序就会自动打包转化为一个netcdf文件。(这里面的-b F64 参数是为了将存储数据的精度扩大,有些模式输出的结果小数点后有很多位的,默认的选项会报错好像Error (cdf_put_vara_double) : NetCDF: Numeric conversion not representable
  2. 之后就可以愉快的用python处理数据啦~~~
  3. CDO除了干这一种单一的工作外,官网也有教其他用法,据说有600+的应用命令呢~~

基本入门

  1. 查看数据基本属性
  2. # 查看年份个数
  3. !cdo nyear /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  4. 1
  5. cdo nyear: Processed 1 variable over 365 timesteps [0.02s 22MB].
  6. # 查看月份个数
  7. !cdo nmon /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  8. 12
  9. cdo nmon: Processed 1 variable over 365 timesteps [0.01s 22MB].
  10. # 查看变量个数
  11. !cdo npar /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  12. 1
  13. cdo npar: Processed 1 variable [0.00s 22MB].
  14. # 查看数据概况
  15. !cdo sinfon /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  16. File format : NetCDF4 classic zip
  17. -1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
  18. 1 : unknown NOAA/NCDC v instant 1 1 1036800 1 F32z : anom
  19. Grid coordinates :
  20. 1 : lonlat : points=1036800 (1440x720)
  21. lon : 0.125 to 359.875 by 0.25 degrees_east circular
  22. lat : -89.875 to 89.875 by 0.25 degrees_north
  23. Vertical coordinates :
  24. 1 : surface : levels=1
  25. Time coordinate : 365 steps
  26. RefTime = 1800-01-01 00:00:00 Units = days Calendar = standard
  27. YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
  28. 2015-01-01 00:00:00 2015-01-02 00:00:00 2015-01-03 00:00:00 2015-01-04 00:00:00
  29. 2015-01-05 00:00:00 2015-01-06 00:00:00 2015-01-07 00:00:00 2015-01-08 00:00:00
  30. 2015-01-09 00:00:00 2015-01-10 00:00:00 2015-01-11 00:00:00 2015-01-12 00:00:00
  31. 2015-01-13 00:00:00 2015-01-14 00:00:00 2015-01-15 00:00:00 2015-01-16 00:00:00
  32. 2015-01-17 00:00:00 2015-01-18 00:00:00 2015-01-19 00:00:00 2015-01-20 00:00:00
  33. 2015-01-21 00:00:00 2015-01-22 00:00:00 2015-01-23 00:00:00 2015-01-24 00:00:00
  34. 2015-01-25 00:00:00 2015-01-26 00:00:00 2015-01-27 00:00:00 2015-01-28 00:00:00
  35. 2015-01-29 00:00:00 2015-01-30 00:00:00 2015-01-31 00:00:00 2015-02-01 00:00:00
  36. 2015-02-02 00:00:00 2015-02-03 00:00:00 2015-02-04 00:00:00 2015-02-05 00:00:00
  37. 2015-02-06 00:00:00 2015-02-07 00:00:00 2015-02-08 00:00:00 2015-02-09 00:00:00
  38. 2015-02-10 00:00:00 2015-02-11 00:00:00 2015-02-12 00:00:00 2015-02-13 00:00:00
  39. 2015-02-14 00:00:00 2015-02-15 00:00:00 2015-02-16 00:00:00 2015-02-17 00:00:00
  40. 2015-02-18 00:00:00 2015-02-19 00:00:00 2015-02-20 00:00:00 2015-02-21 00:00:00
  41. 2015-02-22 00:00:00 2015-02-23 00:00:00 2015-02-24 00:00:00 2015-02-25 00:00:00
  42. 2015-02-26 00:00:00 2015-02-27 00:00:00 2015-02-28 00:00:00 2015-03-01 00:00:00
  43. ................................................................................
  44. .................
  45. 2015-11-05 00:00:00 2015-11-06 00:00:00 2015-11-07 00:00:00 2015-11-08 00:00:00
  46. 2015-11-09 00:00:00 2015-11-10 00:00:00 2015-11-11 00:00:00 2015-11-12 00:00:00
  47. 2015-11-13 00:00:00 2015-11-14 00:00:00 2015-11-15 00:00:00 2015-11-16 00:00:00
  48. 2015-11-17 00:00:00 2015-11-18 00:00:00 2015-11-19 00:00:00 2015-11-20 00:00:00
  49. 2015-11-21 00:00:00 2015-11-22 00:00:00 2015-11-23 00:00:00 2015-11-24 00:00:00
  50. 2015-11-25 00:00:00 2015-11-26 00:00:00 2015-11-27 00:00:00 2015-11-28 00:00:00
  51. 2015-11-29 00:00:00 2015-11-30 00:00:00 2015-12-01 00:00:00 2015-12-02 00:00:00
  52. 2015-12-03 00:00:00 2015-12-04 00:00:00 2015-12-05 00:00:00 2015-12-06 00:00:00
  53. 2015-12-07 00:00:00 2015-12-08 00:00:00 2015-12-09 00:00:00 2015-12-10 00:00:00
  54. 2015-12-11 00:00:00 2015-12-12 00:00:00 2015-12-13 00:00:00 2015-12-14 00:00:00
  55. 2015-12-15 00:00:00 2015-12-16 00:00:00 2015-12-17 00:00:00 2015-12-18 00:00:00
  56. 2015-12-19 00:00:00 2015-12-20 00:00:00 2015-12-21 00:00:00 2015-12-22 00:00:00
  57. 2015-12-23 00:00:00 2015-12-24 00:00:00 2015-12-25 00:00:00 2015-12-26 00:00:00
  58. 2015-12-27 00:00:00 2015-12-28 00:00:00 2015-12-29 00:00:00 2015-12-30 00:00:00
  59. 2015-12-31 00:00:00
  60. cdo sinfon: Processed 1 variable over 365 timesteps [0.02s 22MB].
  61. # 查看数据的日期
  62. !cdo showdate /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  63. 2015-01-01 2015-01-02 2015-01-03 2015-01-04 2015-01-05 2015-01-06 2015-01-07 2015-01-08 2015-01-09 2015-01-10 2015-01-11 2015-01-12 2015-01-13 2015-01-14 2015-01-15 2015-01-16 2015-01-17 2015-01-18 2015-01-19 2015-01-20 2015-01-21 2015-01-22 2015-01-23 2015-01-24 2015-01-25 2015-01-26 2015-01-27 2015-01-28 2015-01-29 2015-01-30 2015-01-31 2015-02-01 2015-02-02 2015-02-03 2015-02-04 2015-02-05 2015-02-06 2015-02-07 2015-02-08 2015-02-09 2015-02-10 2015-02-11 2015-02-12 2015-02-13 2015-02-14 2015-02-15 2015-02-16 2015-02-17 2015-02-18 2015-02-19 2015-02-20 2015-02-21 2015-02-22 2015-02-23 2015-02-24 2015-02-25 2015-02-26 2015-02-27 2015-02-28 2015-03-01 2015-03-02 2015-03-03 2015-03-04 2015-03-05 2015-03-06 2015-03-07 2015-03-08 2015-03-09 2015-03-10 2015-03-11 2015-03-12 2015-03-13 2015-03-14 2015-03-15 2015-03-16 2015-03-17 2015-03-18 2015-03-19 2015-03-20 2015-03-21 2015-03-22 2015-03-23 2015-03-24 2015-03-25 2015-03-26 2015-03-27 2015-03-28 2015-03-29 2015-03-30 2015-03-31 2015-04-01 2015-04-02 2015-04-03 2015-04-04 2015-04-05 2015-04-06 2015-04-07 2015-04-08 2015-04-09 2015-04-10 2015-04-11 2015-04-12 2015-04-13 2015-04-14 2015-04-15 2015-04-16 2015-04-17 2015-04-18 2015-04-19 2015-04-20 2015-04-21 2015-04-22 2015-04-23 2015-04-24 2015-04-25 2015-04-26 2015-04-27 2015-04-28 2015-04-29 2015-04-30 2015-05-01 2015-05-02 2015-05-03 2015-05-04 2015-05-05 2015-05-06 2015-05-07 2015-05-08 2015-05-09 2015-05-10 2015-05-11 2015-05-12 2015-05-13 2015-05-14 2015-05-15 2015-05-16 2015-05-17 2015-05-18 2015-05-19 2015-05-20 2015-05-21 2015-05-22 2015-05-23 2015-05-24 2015-05-25 2015-05-26 2015-05-27 2015-05-28 2015-05-29 2015-05-30 2015-05-31 2015-06-01 2015-06-02 2015-06-03 2015-06-04 2015-06-05 2015-06-06 2015-06-07 2015-06-08 2015-06-09 2015-06-10 2015-06-11 2015-06-12 2015-06-13 2015-06-14 2015-06-15 2015-06-16 2015-06-17 2015-06-18 2015-06-19 2015-06-20 2015-06-21 2015-06-22 2015-06-23 2015-06-24 2015-06-25 2015-06-26 2015-06-27 2015-06-28 2015-06-29 2015-06-30 2015-07-01 2015-07-02 2015-07-03 2015-07-04 2015-07-05 2015-07-06 2015-07-07 2015-07-08 2015-07-09 2015-07-10 2015-07-11 2015-07-12 2015-07-13 2015-07-14 2015-07-15 2015-07-16 2015-07-17 2015-07-18 2015-07-19 2015-07-20 2015-07-21 2015-07-22 2015-07-23 2015-07-24 2015-07-25 2015-07-26 2015-07-27 2015-07-28 2015-07-29 2015-07-30 2015-07-31 2015-08-01 2015-08-02 2015-08-03 2015-08-04 2015-08-05 2015-08-06 2015-08-07 2015-08-08 2015-08-09 2015-08-10 2015-08-11 2015-08-12 2015-08-13 2015-08-14 2015-08-15 2015-08-16 2015-08-17 2015-08-18 2015-08-19 2015-08-20 2015-08-21 2015-08-22 2015-08-23 2015-08-24 2015-08-25 2015-08-26 2015-08-27 2015-08-28 2015-08-29 2015-08-30 2015-08-31 2015-09-01 2015-09-02 2015-09-03 2015-09-04 2015-09-05 2015-09-06 2015-09-07 2015-09-08 2015-09-09 2015-09-10 2015-09-11 2015-09-12 2015-09-13 2015-09-14 2015-09-15 2015-09-16 2015-09-17 2015-09-18 2015-09-19 2015-09-20 2015-09-21 2015-09-22 2015-09-23 2015-09-24 2015-09-25 2015-09-26 2015-09-27 2015-09-28 2015-09-29 2015-09-30 2015-10-01 2015-10-02 2015-10-03 2015-10-04 2015-10-05 2015-10-06 2015-10-07 2015-10-08 2015-10-09 2015-10-10 2015-10-11 2015-10-12 2015-10-13 2015-10-14 2015-10-15 2015-10-16 2015-10-17 2015-10-18 2015-10-19 2015-10-20 2015-10-21 2015-10-22 2015-10-23 2015-10-24 2015-10-25 2015-10-26 2015-10-27 2015-10-28 2015-10-29 2015-10-30 2015-10-31 2015-11-01 2015-11-02 2015-11-03 2015-11-04 2015-11-05 2015-11-06 2015-11-07 2015-11-08 2015-11-09 2015-11-10 2015-11-11 2015-11-12 2015-11-13 2015-11-14 2015-11-15 2015-11-16 2015-11-17 2015-11-18 2015-11-19 2015-11-20 2015-11-21 2015-11-22 2015-11-23 2015-11-24 2015-11-25 2015-11-26 2015-11-27 2015-11-28 2015-11-29 2015-11-30 2015-12-01 2015-12-02 2015-12-03 2015-12-04 2015-12-05 2015-12-06 2015-12-07 2015-12-08 2015-12-09 2015-12-10 2015-12-11 2015-12-12 2015-12-13 2015-12-14 2015-12-15 2015-12-16 2015-12-17 2015-12-18 2015-12-19 2015-12-20 2015-12-21 2015-12-22 2015-12-23 2015-12-24 2015-12-25 2015-12-26 2015-12-27 2015-12-28 2015-12-29 2015-12-30 2015-12-31
  64. cdo showdate: Processed 1 variable over 365 timesteps [0.01s 22MB].
  65. # 查看空间网格信息
  66. !cdo griddes /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
  67. #
  68. # gridID 1
  69. #
  70. gridtype = lonlat
  71. gridsize = 1036800
  72. datatype = float
  73. xsize = 1440
  74. ysize = 720
  75. xname = lon
  76. xlongname = "Longitude"
  77. xunits = "degrees_east"
  78. yname = lat
  79. ylongname = "Latitude"
  80. yunits = "degrees_north"
  81. xfirst = 0.125
  82. xinc = 0.25
  83. yfirst = -89.875
  84. yinc = 0.25
  85. cdo griddes: Processed 1 variable [0.00s 22MB].
  86. 特定时间和特定区域提取
  87. # 筛选特定日期范围
  88. !cdo seldate,2015-01-01,2015-02-15 /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc new.nc
  89. cdo seldate: Processed 47692800 values from 1 variable over 47 timesteps [1.32s 75MB].
  90. !cdo showdate new.nc
  91. 2015-01-01 2015-01-02 2015-01-03 2015-01-04 2015-01-05 2015-01-06 2015-01-07 2015-01-08 2015-01-09 2015-01-10 2015-01-11 2015-01-12 2015-01-13 2015-01-14 2015-01-15 2015-01-16 2015-01-17 2015-01-18 2015-01-19 2015-01-20 2015-01-21 2015-01-22 2015-01-23 2015-01-24 2015-01-25 2015-01-26 2015-01-27 2015-01-28 2015-01-29 2015-01-30 2015-01-31 2015-02-01 2015-02-02 2015-02-03 2015-02-04 2015-02-05 2015-02-06 2015-02-07 2015-02-08 2015-02-09 2015-02-10 2015-02-11 2015-02-12 2015-02-13 2015-02-14 2015-02-15
  92. cdo showdate: Processed 1 variable over 46 timesteps [0.01s 22MB].
  93. # 筛选特定月份和区域
  94. !cdo -selmon,6,7,8 -sellonlatbox,70,135,10,55 /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc summer.nc
  95. cdo(1) sellonlatbox: Process started
  96. cdo(1) sellonlatbox: Processed 378432000 values from 1 variable over 365 timesteps.
  97. cdo selmonth: Processed 4305600 values from 1 variable over 365 timesteps [8.91s 80MB].
  98. !cdo sinfon summer.nc
  99. File format : NetCDF4 classic
  100. -1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
  101. 1 : unknown NOAA/NCDC v instant 1 1 46800 1 F32 : anom
  102. Grid coordinates :
  103. 1 : lonlat : points=46800 (260x180)
  104. lon : 70.125 to 134.875 by 0.25 degrees_east
  105. lat : 10.125 to 54.875 by 0.25 degrees_north
  106. Vertical coordinates :
  107. 1 : surface : levels=1
  108. Time coordinate : 92 steps
  109. RefTime = 1800-01-01 00:00:00 Units = days Calendar = standard
  110. YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
  111. 2015-06-01 00:00:00 2015-06-02 00:00:00 2015-06-03 00:00:00 2015-06-04 00:00:00
  112. 2015-06-05 00:00:00 2015-06-06 00:00:00 2015-06-07 00:00:00 2015-06-08 00:00:00
  113. 2015-06-09 00:00:00 2015-06-10 00:00:00 2015-06-11 00:00:00 2015-06-12 00:00:00
  114. 2015-06-13 00:00:00 2015-06-14 00:00:00 2015-06-15 00:00:00 2015-06-16 00:00:00
  115. 2015-06-17 00:00:00 2015-06-18 00:00:00 2015-06-19 00:00:00 2015-06-20 00:00:00
  116. 2015-06-21 00:00:00 2015-06-22 00:00:00 2015-06-23 00:00:00 2015-06-24 00:00:00
  117. 2015-06-25 00:00:00 2015-06-26 00:00:00 2015-06-27 00:00:00 2015-06-28 00:00:00
  118. 2015-06-29 00:00:00 2015-06-30 00:00:00 2015-07-01 00:00:00 2015-07-02 00:00:00
  119. 2015-07-03 00:00:00 2015-07-04 00:00:00 2015-07-05 00:00:00 2015-07-06 00:00:00
  120. 2015-07-07 00:00:00 2015-07-08 00:00:00 2015-07-09 00:00:00 2015-07-10 00:00:00
  121. 2015-07-11 00:00:00 2015-07-12 00:00:00 2015-07-13 00:00:00 2015-07-14 00:00:00
  122. 2015-07-15 00:00:00 2015-07-16 00:00:00 2015-07-17 00:00:00 2015-07-18 00:00:00
  123. 2015-07-19 00:00:00 2015-07-20 00:00:00 2015-07-21 00:00:00 2015-07-22 00:00:00
  124. 2015-07-23 00:00:00 2015-07-24 00:00:00 2015-07-25 00:00:00 2015-07-26 00:00:00
  125. 2015-07-27 00:00:00 2015-07-28 00:00:00 2015-07-29 00:00:00 2015-07-30 00:00:00
  126. 2015-07-31 00:00:00 2015-08-01 00:00:00 2015-08-02 00:00:00 2015-08-03 00:00:00
  127. 2015-08-04 00:00:00 2015-08-05 00:00:00 2015-08-06 00:00:00 2015-08-07 00:00:00
  128. 2015-08-08 00:00:00 2015-08-09 00:00:00 2015-08-10 00:00:00 2015-08-11 00:00:00
  129. 2015-08-12 00:00:00 2015-08-13 00:00:00 2015-08-14 00:00:00 2015-08-15 00:00:00
  130. 2015-08-16 00:00:00 2015-08-17 00:00:00 2015-08-18 00:00:00 2015-08-19 00:00:00
  131. 2015-08-20 00:00:00 2015-08-21 00:00:00 2015-08-22 00:00:00 2015-08-23 00:00:00
  132. 2015-08-24 00:00:00 2015-08-25 00:00:00 2015-08-26 00:00:00 2015-08-27 00:00:00
  133. 2015-08-28 00:00:00 2015-08-29 00:00:00 2015-08-30 00:00:00 2015-08-31 00:00:00
  134. cdo sinfon: Processed 1 variable over 92 timesteps [0.01s 21MB].

参考 https://cloud.tencent.com/developer/article/1618310

  1. 显示文件的变量Display variables of a file

    1. cdo -showname <infile>
  2. 显示文件的时间步数目Display number of timesteps of a file

    cdo -ntime

  3. 显示格点信息?Display Information about the underlying grid: griddes does the following:

    cdo -griddes tsurf.nc

  4. 文件转换到不同类型File conversion with different file types:

Copying whole data sets can be easily done with the copy operator.
With the ‘-f’ switch, you can choose a new file type:

cdo -f grb -copy tsurf.nc tsurf.grb

Combine this with the ‘-z’ options for changing to a higher compression ration:

cdo -f grb -z szip tsurf.nc tsurf.grb

  1. 选择变量Select variables from file: select variable tas

    cdo -selname,tas

select variables u10 and v10

cdo -selname,u10,v10

  1. 选择时间步Select timesteps from file: e.g. select only the 3rd time step

    cdo -seltimestep,3

or select 3 timestepscdo -seltimestep,1,13,25 or select a time range from 1 to 12

cdo -seltimestep,1/12

If you have a list of dates (e.g. format YYY-MM-DD) you can use the select operator:

cdo -select,date=date1,date2,…,dateN

  1. 选取子区域Select only data of the northern hemisphere (sub-region):

    cdo -sellonlatbox,-180,180,0,90

  2. 经纬度网格重新排列Rearrange data from longitude 0 to 360 degrees to -180 to 180 degrees (latitude: -90 to 90 degrees):

    cdo -sellonlatbox,-180,180,-90,90

  3. 经纬度反转Invert the latitudes from north-south to south-north:

    cdo -invertlat

  4. 转换成摄氏度Convert from K to degC when input file contains temperature values:

    cdo -addc,-273.15

and don’t forget to change the variable (here tas) units, too. Combining operators:

cdo -setattribute,tas@units=”degC” -addc,-273.15

  1. 设置缺测值Set constant value to missing value: change data value -999.0 to be missing value

    cdo -setctomiss,-999.0

or vice versa set missing value to constant value:

cdo setmisstoc,0

  1. _计算各月的平均Compute the monthly mean with respect to the number of days per month:** don’t forget to change the units attribute of the variable

    cdo -r -setattribute,tas@units=”K/day” -divdpm -monsum

  2. Delete February 29th:

    cdo -delete,month=2,day=29


CDO中提供了两个均值计算操作符:meanaveragemean是按照统计函数的方式计算均值,即排除缺省值的影响average通过求样本总和然后除样本总数,并未排除缺省值的影响。如果样本中不包含缺省值的话,meanaverage的计算结果相同。

进行变量修改

可以使用chname,chcode或setattribute等一些CDO运算符修改变量的名称及其属性(元数据)。
要将变量的名称从temp更改为t2m:

cdo -chname,temp,t2m infile outfile

要将代码98更改为179,将代码编号99更改为211:

cdo -chcode,98,179,99,211 infile outfile

要在某些计算后更改变量属性单位:

cdo -setattribute,pressure@units=pascal infile outfile

setattribute运算符接受多个属性,并且它支持通配符,比如:

  1. do -setattribute,
  2. y?_?@units="degrees_north",
  3. x?_?@units="degrees_east",
  4. ????_a@coordinates="yc_a xc_a",
  5. ????_b@coordinates="yc_b xc_b"
  6. infile outfile

注意!
CDO无法更改坐标(维度)变量名称,但您可以使用NCO的ncrename来完成此操作。
如果要重命名坐标变量以使其保持坐标变量,则必须单独重命名维度和变量。
例如。 将坐标(维度)变量名称从ncl1,ncl2,ncl3重命名为time,lat,lon:
ncrename -d ncl1,time -d ncl2,lat -d ncl3,lon -v ncl1,time -v ncl2,lat -v ncl3,lon infile outfile

运算符组合

具有一个输出流的所有运算符可以将结果直接传递给另一个运算符。 运算符必须使用“ - ”开头才能与其他运算符组合。 这可以通过以下方式改善性能:

  • 减少不必要的磁盘I / O:没有中间文件
  • 并行处理:在一个工作链中的所有运算符并行运行
  1. 简单组合:

    cdo -sub -dayavg ifile2 -timavg ifile1 ofile

而不是

cdo -timavg ifile1 tmp1 cdo -dayavg ifile2 tmp2 cdo -sub tmp2 tmp1 ofile rm tmp1 tmp2

  1. 高级组合:

cdo -timmean -yearsum -setrtoc2,75,78,1,0 -selmon,9,10,11,12,1,2,3 -selyear,1960/1969 ifile ofile
运算符链是CDO的主要特征之一。 尽可能多地使用它。 但请注意:具有任意输入文件列表的运算符不能与其他运算符组合使用:

  • merge/mergetime
  • cat/copy
  • select
  • ens

    expr 操作符

    The expr 操作符可能是一个很少使用但却更有用的工具。 其目的是在任意字段上逐点计算复杂的数学运算。
    假设height.nc like height.nc包含一个3d垂直坐标变量z,为了输出气压,可以像这样使用expr:
    cdo -expr,’ps=1013.25exp((-1)(1.602769777072154)log((exp(z/10000.0)213.15+75.0)/288.15))’ 3dheights.nc out.nc
    计算或选择部分数据并将其保存到新文件。例如,创建新变量tupper ,其包含了变量tas中大于等于273.15的值;创建新变量tlower,其包含了变量tas中小于的273.15的值:
    cdo -expr,’tupper = ((tas >= 273.15)) ? tas : (tas/0.0); tlower = ((tas < 273.15)) ? tas : (tas/0.0)’

将变量tas单位转换为摄氏度,并计算tupper和tlower变量:
cdo -expr,’tc=tas-273.15; tplus = ((tc >= 0)) ? tc : (tc/0.0); tmin = ((tc < 0)) ? tc : (tas/0.0)’

selectdelete操作符

我们已经看到了一些CDO的选择功能,如seltimestep或selname。 select运算符从输入文件中选择一些字段并将其写入输出文件,例如 变量名称,层次,日期或季节。 delete运算符删除一些字段并将结果写入输出文件。
要选择用户定义的季节,请使用带有参数season的select运算符,其中给定的季节是逗号分隔的季节列表(DJFMAMJJA-SOND或ANN的子字符串):
cdo -select,season=JFMAM infile outfile

在不知道infile的总时间步的情况下选择上一个时间步长:
cdo -select,timestep=-1 infile outfile

假设您有3个输入文件。 每个输入文件包含不同时间段的相同变量。 要从所有3个输入文件中选择层次200,500和850上的变量T,U和V,使用:
cdo -select,name=T,U,V,level=200,500,850 infile1 infile2 infile3 outfile

删除文件中的第一个时间步:
cdo -delete,timestep=1 infile outfile

缺测值

有时您需要设置或更改变量的缺测值,或将NaN更改为缺测值。
将缺测值设置为常量值,例如-9999
cdo -setmisstoc,-9999 infile outfile

将常量如-9999设为缺测值
cdo -setctomiss,-999.9 infile outfile

将NaN设为缺测值并把缺测值设为-9999.9
cdo -setmissval,nan infile outfile cdo -setmissval,-9999.9 -setmissval,nan ifile ofile

自动完成

在官方发行版的contrib子目录中是使用bash,zsh和tcsh自动完成的配置文件。 对于当前的开发状态,可以在这里找到:source:/trunk/cdo/contrib
对于激活,您必须让shell读取相应的文件,例如 对于zsh:

source cdoCompletion.zsh

bash和tcsh的方法类似