介绍
- 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文件,解压后进入所得目录,用下面的代码段安装://HDF库是可选的,因为之后数据类型也会用到就顺便安装了,这个和本篇无关。
./configure --prefix "指定安装目录"
--with-netcdf="你机子上netcdf的根目录"
--with-hdf5="你机子上HDF的根目录"
- 使用命令cdo -b F64 -f nc import_binary “你的CTL文件” “希望输出的文件.nc” 这样只要在你的ctl里描述时间变量以及多个模式输出结果文件程序就会自动打包转化为一个netcdf文件。(这里面的-b F64 参数是为了将存储数据的精度扩大,有些模式输出的结果小数点后有很多位的,默认的选项会报错好像Error (cdf_put_vara_double) : NetCDF: Numeric conversion not representable)
- 之后就可以愉快的用python处理数据啦~~~
- CDO除了干这一种单一的工作外,官网也有教其他用法,据说有600+的应用命令呢~~
基本入门
查看数据基本属性
# 查看年份个数
!cdo nyear /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
1
cdo nyear: Processed 1 variable over 365 timesteps [0.02s 22MB].
# 查看月份个数
!cdo nmon /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
12
cdo nmon: Processed 1 variable over 365 timesteps [0.01s 22MB].
# 查看变量个数
!cdo npar /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
1
cdo npar: Processed 1 variable [0.00s 22MB].
# 查看数据概况
!cdo sinfon /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
File format : NetCDF4 classic zip
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
1 : unknown NOAA/NCDC v instant 1 1 1036800 1 F32z : anom
Grid coordinates :
1 : lonlat : points=1036800 (1440x720)
lon : 0.125 to 359.875 by 0.25 degrees_east circular
lat : -89.875 to 89.875 by 0.25 degrees_north
Vertical coordinates :
1 : surface : levels=1
Time coordinate : 365 steps
RefTime = 1800-01-01 00:00:00 Units = days 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
2015-01-01 00:00:00 2015-01-02 00:00:00 2015-01-03 00:00:00 2015-01-04 00:00:00
2015-01-05 00:00:00 2015-01-06 00:00:00 2015-01-07 00:00:00 2015-01-08 00:00:00
2015-01-09 00:00:00 2015-01-10 00:00:00 2015-01-11 00:00:00 2015-01-12 00:00:00
2015-01-13 00:00:00 2015-01-14 00:00:00 2015-01-15 00:00:00 2015-01-16 00:00:00
2015-01-17 00:00:00 2015-01-18 00:00:00 2015-01-19 00:00:00 2015-01-20 00:00:00
2015-01-21 00:00:00 2015-01-22 00:00:00 2015-01-23 00:00:00 2015-01-24 00:00:00
2015-01-25 00:00:00 2015-01-26 00:00:00 2015-01-27 00:00:00 2015-01-28 00:00:00
2015-01-29 00:00:00 2015-01-30 00:00:00 2015-01-31 00:00:00 2015-02-01 00:00:00
2015-02-02 00:00:00 2015-02-03 00:00:00 2015-02-04 00:00:00 2015-02-05 00:00:00
2015-02-06 00:00:00 2015-02-07 00:00:00 2015-02-08 00:00:00 2015-02-09 00:00:00
2015-02-10 00:00:00 2015-02-11 00:00:00 2015-02-12 00:00:00 2015-02-13 00:00:00
2015-02-14 00:00:00 2015-02-15 00:00:00 2015-02-16 00:00:00 2015-02-17 00:00:00
2015-02-18 00:00:00 2015-02-19 00:00:00 2015-02-20 00:00:00 2015-02-21 00:00:00
2015-02-22 00:00:00 2015-02-23 00:00:00 2015-02-24 00:00:00 2015-02-25 00:00:00
2015-02-26 00:00:00 2015-02-27 00:00:00 2015-02-28 00:00:00 2015-03-01 00:00:00
................................................................................
.................
2015-11-05 00:00:00 2015-11-06 00:00:00 2015-11-07 00:00:00 2015-11-08 00:00:00
2015-11-09 00:00:00 2015-11-10 00:00:00 2015-11-11 00:00:00 2015-11-12 00:00:00
2015-11-13 00:00:00 2015-11-14 00:00:00 2015-11-15 00:00:00 2015-11-16 00:00:00
2015-11-17 00:00:00 2015-11-18 00:00:00 2015-11-19 00:00:00 2015-11-20 00:00:00
2015-11-21 00:00:00 2015-11-22 00:00:00 2015-11-23 00:00:00 2015-11-24 00:00:00
2015-11-25 00:00:00 2015-11-26 00:00:00 2015-11-27 00:00:00 2015-11-28 00:00:00
2015-11-29 00:00:00 2015-11-30 00:00:00 2015-12-01 00:00:00 2015-12-02 00:00:00
2015-12-03 00:00:00 2015-12-04 00:00:00 2015-12-05 00:00:00 2015-12-06 00:00:00
2015-12-07 00:00:00 2015-12-08 00:00:00 2015-12-09 00:00:00 2015-12-10 00:00:00
2015-12-11 00:00:00 2015-12-12 00:00:00 2015-12-13 00:00:00 2015-12-14 00:00:00
2015-12-15 00:00:00 2015-12-16 00:00:00 2015-12-17 00:00:00 2015-12-18 00:00:00
2015-12-19 00:00:00 2015-12-20 00:00:00 2015-12-21 00:00:00 2015-12-22 00:00:00
2015-12-23 00:00:00 2015-12-24 00:00:00 2015-12-25 00:00:00 2015-12-26 00:00:00
2015-12-27 00:00:00 2015-12-28 00:00:00 2015-12-29 00:00:00 2015-12-30 00:00:00
2015-12-31 00:00:00
cdo sinfon: Processed 1 variable over 365 timesteps [0.02s 22MB].
# 查看数据的日期
!cdo showdate /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
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
cdo showdate: Processed 1 variable over 365 timesteps [0.01s 22MB].
# 查看空间网格信息
!cdo griddes /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc
#
# gridID 1
#
gridtype = lonlat
gridsize = 1036800
datatype = float
xsize = 1440
ysize = 720
xname = lon
xlongname = "Longitude"
xunits = "degrees_east"
yname = lat
ylongname = "Latitude"
yunits = "degrees_north"
xfirst = 0.125
xinc = 0.25
yfirst = -89.875
yinc = 0.25
cdo griddes: Processed 1 variable [0.00s 22MB].
特定时间和特定区域提取
# 筛选特定日期范围
!cdo seldate,2015-01-01,2015-02-15 /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc new.nc
cdo seldate: Processed 47692800 values from 1 variable over 47 timesteps [1.32s 75MB].
!cdo showdate new.nc
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
cdo showdate: Processed 1 variable over 46 timesteps [0.01s 22MB].
# 筛选特定月份和区域
!cdo -selmon,6,7,8 -sellonlatbox,70,135,10,55 /home/kesci/input/OISSTV27010/sst.day.anom.2015.nc summer.nc
cdo(1) sellonlatbox: Process started
cdo(1) sellonlatbox: Processed 378432000 values from 1 variable over 365 timesteps.
cdo selmonth: Processed 4305600 values from 1 variable over 365 timesteps [8.91s 80MB].
!cdo sinfon summer.nc
File format : NetCDF4 classic
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
1 : unknown NOAA/NCDC v instant 1 1 46800 1 F32 : anom
Grid coordinates :
1 : lonlat : points=46800 (260x180)
lon : 70.125 to 134.875 by 0.25 degrees_east
lat : 10.125 to 54.875 by 0.25 degrees_north
Vertical coordinates :
1 : surface : levels=1
Time coordinate : 92 steps
RefTime = 1800-01-01 00:00:00 Units = days 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
2015-06-01 00:00:00 2015-06-02 00:00:00 2015-06-03 00:00:00 2015-06-04 00:00:00
2015-06-05 00:00:00 2015-06-06 00:00:00 2015-06-07 00:00:00 2015-06-08 00:00:00
2015-06-09 00:00:00 2015-06-10 00:00:00 2015-06-11 00:00:00 2015-06-12 00:00:00
2015-06-13 00:00:00 2015-06-14 00:00:00 2015-06-15 00:00:00 2015-06-16 00:00:00
2015-06-17 00:00:00 2015-06-18 00:00:00 2015-06-19 00:00:00 2015-06-20 00:00:00
2015-06-21 00:00:00 2015-06-22 00:00:00 2015-06-23 00:00:00 2015-06-24 00:00:00
2015-06-25 00:00:00 2015-06-26 00:00:00 2015-06-27 00:00:00 2015-06-28 00:00:00
2015-06-29 00:00:00 2015-06-30 00:00:00 2015-07-01 00:00:00 2015-07-02 00:00:00
2015-07-03 00:00:00 2015-07-04 00:00:00 2015-07-05 00:00:00 2015-07-06 00:00:00
2015-07-07 00:00:00 2015-07-08 00:00:00 2015-07-09 00:00:00 2015-07-10 00:00:00
2015-07-11 00:00:00 2015-07-12 00:00:00 2015-07-13 00:00:00 2015-07-14 00:00:00
2015-07-15 00:00:00 2015-07-16 00:00:00 2015-07-17 00:00:00 2015-07-18 00:00:00
2015-07-19 00:00:00 2015-07-20 00:00:00 2015-07-21 00:00:00 2015-07-22 00:00:00
2015-07-23 00:00:00 2015-07-24 00:00:00 2015-07-25 00:00:00 2015-07-26 00:00:00
2015-07-27 00:00:00 2015-07-28 00:00:00 2015-07-29 00:00:00 2015-07-30 00:00:00
2015-07-31 00:00:00 2015-08-01 00:00:00 2015-08-02 00:00:00 2015-08-03 00:00:00
2015-08-04 00:00:00 2015-08-05 00:00:00 2015-08-06 00:00:00 2015-08-07 00:00:00
2015-08-08 00:00:00 2015-08-09 00:00:00 2015-08-10 00:00:00 2015-08-11 00:00:00
2015-08-12 00:00:00 2015-08-13 00:00:00 2015-08-14 00:00:00 2015-08-15 00:00:00
2015-08-16 00:00:00 2015-08-17 00:00:00 2015-08-18 00:00:00 2015-08-19 00:00:00
2015-08-20 00:00:00 2015-08-21 00:00:00 2015-08-22 00:00:00 2015-08-23 00:00:00
2015-08-24 00:00:00 2015-08-25 00:00:00 2015-08-26 00:00:00 2015-08-27 00:00:00
2015-08-28 00:00:00 2015-08-29 00:00:00 2015-08-30 00:00:00 2015-08-31 00:00:00
cdo sinfon: Processed 1 variable over 92 timesteps [0.01s 21MB].
显示文件的变量Display variables of a file
cdo -showname <infile>
显示文件的时间步数目Display number of timesteps of a file
cdo -ntime
显示格点信息?Display Information about the underlying grid: griddes does the following:
cdo -griddes tsurf.nc
文件转换到不同类型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
- 选择变量Select variables from file: select variable tas
cdo -selname,tas
select variables u10 and v10
cdo -selname,u10,v10
- 选择时间步Select timesteps from file: e.g. select only the 3rd time step
cdo -seltimestep,3
or select 3 timestepscdo -seltimestep,1,13,25
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
选取子区域Select only data of the northern hemisphere (sub-region):
cdo -sellonlatbox,-180,180,0,90
经纬度网格重新排列Rearrange data from longitude 0 to 360 degrees to -180 to 180 degrees (latitude: -90 to 90 degrees):
cdo -sellonlatbox,-180,180,-90,90
经纬度反转Invert the latitudes from north-south to south-north:
cdo -invertlat
转换成摄氏度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
- 设置缺测值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
_计算各月的平均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
Delete February 29th:
cdo -delete,month=2,day=29
CDO中提供了两个均值计算操作符:mean 和 average。mean是按照统计函数的方式计算均值,即排除缺省值的影响;average通过求样本总和然后除样本总数,并未排除缺省值的影响。如果样本中不包含缺省值的话,mean和average的计算结果相同。
进行变量修改
可以使用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运算符接受多个属性,并且它支持通配符,比如:
do -setattribute,
y?_?@units="degrees_north",
x?_?@units="degrees_east",
????_a@coordinates="yc_a xc_a",
????_b@coordinates="yc_b xc_b"
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:没有中间文件
- 并行处理:在一个工作链中的所有运算符并行运行
- 简单组合:
cdo -sub -dayavg ifile2 -timavg ifile1 ofile
而不是
cdo -timavg ifile1 tmp1 cdo -dayavg ifile2 tmp2 cdo -sub tmp2 tmp1 ofile rm tmp1 tmp2
- 高级组合:
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)’
select和delete操作符
我们已经看到了一些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的方法类似