CDO - 修改操作

本篇随笔将介绍 CDO 对输入数据集进行修改的操作

修改操作 Modification Operators

Set 设置

<operator>,parameter infile outfile

OperatorsTypeDescription
setattribute,attributesSTRING设置数据集的属性,并将结果写入 outfile ;
attributes:[var_nm@]att_nm[:s|d|i]=[att_val|{[var_nm@]att_nm}]
var_nm:变量名,比如: temperature ;
var_nm 为 * ,对所有变量修改; var_nm 缺失时, 将设置全局属性;
att_nm:属性名,比如: units ;
定义属性 att_nm 的类型:字符串( att_nm:s )、双精度( att_nm:d )和整型( att_nm:i )
att_val:赋予属性 att_nm 的值,比如: K ;
att_val 可以复制现有属性( {[var_nm@]att_nm} );如果省略 att_val ,则属性 att_nm 将被删除;
setpartabp,table[,convert]STRING根据变量的 ID 搜索参数表文件 table ,对 infile 的数据进行修改,并写入 outfile ;
参数 convert 控制是否进行单位换算;
setpartabn,table[,convert]STRING根据变量的 name 搜索参数表文件 table ,对 infile 的数据进行修改,并写入 outfile ;
参数 convert 控制是否进行单位换算;
cdo setpartabn,mypartab,convert infile outfile
setcodetab,tableSTRING根据参数表文件 table ,对 infile 所有变量的 code number 进行修改,并写入 outfile
setcode,codeINTEGER设置 所有变量的 code number 为相同的给定值 code
setparam,paramSTRING设置 第一个变量的 ID 为 param
setname,nameSTRING设置 第一个变量的 name 为 name
setunit,unitSTRING设置 第一个变量的 unit 为 unit
setlevel,levelFLOAT设置 所有变量的 level 为 level
setltype,ltypeINTEGER设置 所有变量的 GRIB level type 为 ltype
setdate,dateSTRING将每个时间步中的日期设置为相同的给定值(YYYY-MM-DD)
settime,timeSTRING将每个时间步中的时间设置为相同的给定值(hh:mm:ss)
setday,dayINTEGER将每个时间步中的天设置为相同的给定值
setmon,monthINTEGER将每个时间步中的月份设置为相同的给定值
setyear,yearINTEGER将每个时间步中的年份设置为相同的给定值
settaxis,date,time[,inc]STRING设置时间轴
cdo settaxis,2020-01-01,12:00:00,1mon infile outfile
settbounds,frequencySTRING设定时间范围(hour, day, month, year)
cdo settbounds,day infile outfile
setreftime,date,time[,units]STRING设置 相对时间轴 的参考时间
cdo setreftime,2020-01-01,12:00:00,days infile outfile
settunits,unitsSTRING设置 相对时间轴 的基本单位(seconds, minutes, hours, days, months, years)
cdo settunits,days infile outfile
setcalendar,calendarSTRING设置 相对时间轴 的日历(tandard, proleptic_gregorian, 360_day, 365_day, 366_day)
cdo setcalendar,365_day infile outfile
setgrid,gridSTRINGSets a new grid description. The parameter grid is the grid description file or name.
setgridtype,gridtypeSTRINGSets the grid type of all input fields.
(curvilinear, unstructured, dereference, regular, regularnn, lonlat)
setgridarea,gridareaSTRINGSets the grid cell area. The parameter gridarea is the path to a data file.
setgridmask,gridmaskSTRINGSets the grid mask. The parameter gridmask is the path to a data file.
setzaxis,zaxisSTRINGSets the z-axis description of all variables with the same number of level as the new z-axis. The parameter zaxis is the z-axis description file or name of the target z-axis.
genlevelbounds[,zbot[,ztop]]FLOATGenerates the layer bounds of the z-axis.
setmissval,newmissFLOAT设置一个新的缺失值
setctomiss,cFLOAT将常数替换为缺失值
setmisstoc,cFLOAT将缺失值替换为常数
setrtomiss,rmin,rmaxFLOAT设置缺失值的范围
setvrange,rmin,rmaxFLOAT设置有效值的范围
setmisstonnFLOAT将所有缺失值替换为最邻近的非缺失值
setmisstodis[,neighbors]INTEGER将所有缺失值替换为周围最近的 neighbors 个非缺失值邻居的距离加权平均
setgridcell,value[,cell][,mask]FLOAT, INTEGER, STRING设置所选网格的值;可以通过网格单元索引列表 cell 或掩码 mask 来选择网格单元;如果指定网格单元,则对所有网格进行操作;
value :网格单元的值;
cell :逗号分隔的网格单元的索引列表;
mask :包含 mask 的数据文件;
setvals,oldval,newval[,...]STRING将变量的旧值 oldval 设置为新值 newval
setrtoc,rmin,rmax,cSTRING将变量满足在 [rmin,rmax] 区间的值设为常数 c
setrtoc2,rmin,rmax,c,c2STRING将变量满足在 [rmin,rmax] 区间的值设为常数 c ,否则设为常数 c2

Change 更改

<operator>,parameter infile outfile

OperatorsTypeDescription
chcode,oldcode,newcode[,oldcode,newcode,...]INTEGER根据 oldcodenewcode 更改 code number
chparam,oldparam,newparam,...STRING根据 oldparamnewparam 更改变量 ID
chname,oldname,newname,...STRING根据 oldnamenewname 更改变量 name
chunit,oldunit,newunit,...STRING根据 oldunitnewunit 更改变量单位
chlevel,oldlev,newlev,...FLOAT根据 oldlevnewlev 更改 level
chlevelc,code,oldlev,newlevINTEGER, FLOAT更改给定 code number 的变量的 level
chlevelv,name,oldlev,newlevSTRING, FLOAT更改给定 变量 name 对应的 level

Invert 反转

<operator> infile outfile

OperatorsTypeDescription
invertlatINTEGER反转纬度
invertlevINTEGER反转 levels

Shift 移动

<operator>,parameter infile outfile

OperatorsTypeDescription
shifttime,svalSTRING通过参数 sval 移动所有的时间步
cdo shifttime,-12hour infile outfile
shiftx,nshift[,cyclic][,coord]INTEGER在 x 方向上移动所有的场
参数cyclic设置对单元格进行循环填充,缺失则对单元格进行缺失填充
参数coord控制是否同时移动坐标
shifty,nshift[,cyclic][,coord]INTEGER在 y 方向上移动所有的场
cdo shifty,1,cyclic infile outfile

Mask

<operator>,parameter infile outfile

OperatorsTypeDescription
maskregion,regionsSTRING用规则的 lon/lat 网格 mask 不同区域的字段;区域内的元素不变,区域外的元素设为缺失;
参数 regions 为区域的描述文件,描述文件每一行为多边形一个点的经度和纬度;
cdo maskregion,myregion infile outfile
masklonlatbox,lon1,lon2,lat1,lat2FLOAT根据经纬度的值 mask 一个矩形框区域,框内元素不变,框外元素设为缺失
maskindexbox,idx1,idx2,idy1,idy2INTEGER根据经纬度的索引 mask 一个矩形框区域,框内元素不变,框外元素设为缺失
setclonlatbox,c,lon1,lon2,lat1,lat2FLOAT, FLOAT根据经纬度的值确定一个矩形框区域,框内元素设为常数 c ,框外元素不变
setcindexbox,c,idx1,idx2,idy1,idy2FLOAT, INTEGER根据经纬度的索引确定一个矩形框区域,框内元素设为常数 c ,框外元素不变
enlarge,gridSTRING根据目标网格描述文件或名称 grid 对 infile 进行广播操作,将 infile 的水平网格广播到与给定的水平网格 grid 相同;

例子: infile1 的水平网格为全局区域, infile2 为一个点,如果想将 infile1 和 infile2 相加,则需要先对 infile2 广播:
cdo add infile1 -enlarge,infile1 infile2 outfile