CDO - 算术运算的操作

本篇随笔将介绍 CDO 在不同维度上进行算术运算的相关功能

Arithmetic 计算

Evaluate expressions 表达式求值

<operator>,parameter infile outfile

OperatorsTypeDescription
expr,instrSTRING从参数中读取表达式,输出数据集只追加结果不保留输入数据集的变量;
例子: infile 中包含变量 aprlaprcts,创建新变量 var1var2 进行表达式计算:
cdo expr,’var1=aprl+aprc;var2=ts-273.15;’ infile outfile
exprf,filenameSTRING从文件中读取表达式,输出数据集只追加结果不保留输入数据集的变量;
cdo exprf,myexpr infile outfile
aexpr,instrSTRING从参数中读取表达式,输出数据集追加结果并保留输入数据集的变量;
aexprf,filenameSTRING从文件中读取表达式,输出数据集追加结果并保留输入数据集的变量;
ExpressionsDescriptionExpressionsDescription
表达式
x = yx + y
x - yx / y
x * yx ^ y
x == yx != y
x > yx >= y
x < yx <= y
x <=> y-1, if x < y; 1, if x > y; else 0
x && yx || y
!xx ? y : zy, if x ≠ 0, else z
计算
floor(x)不大于 x 的最大整数ceil(x)不小于 x 的最小整数值
int(x)nint(x)距离 x 最近的整数
float(x)abs(x)
sqr(x)Square of xsqrt(x)
exp(x)
ln(x)log10(x)
sin(x)asin(x)Arc-sine of x
cos(x)acos(x)Arc-cosine of x
tan(x)atan(x)Arc-tangent of x
rad(x)将 x 从角度转为弧度deg(x)将 x 从弧度转为角度
rand(x)将 x 替换为 0~1 之间的随机数isMissval(x)Returns 1 where x is missing
坐标
clon(x)x 的经度坐标clat(x)x 的纬度坐标
gridarea(x)x 的网格区域
clev(x)x 的 level 坐标cdeltaz(x)Upper minus lower level bound of x
ctimestep()Timestep number (1 to N)cdate()Verification date as YYYYMMDD
ctime()Verification time as HHMMSS.millisecondcdeltat()Difference between current and last timestep in seconds
cday()Day as DDcmonth()Month as MM
cyear()Year as YYYYcsecond()Second as SS.millisecond
cminute()Minute as MMchour()Hour as HH
ngp(x)水平网格格点数nlev(x)垂直层数
size(x)ngp(x)*nlev(x)missval(x)返回缺失值的值
统计
fldmin(x)对于每个时间步,计算区域最小值fldmax(x)
fldsum(x)fldmean(x)
fldavg(x)
fldstd(x)fldstd1(x)
fldvar(x)fldvar1(x)
zonmin(x)对于每个纬度,计算纬向最小值zonmax(x)
zonsum(x)zonmean(x)
zonavg(x)
zonstd(x)zonstd1(x)
zonvar(x)zonvar1(x)
vertmin(x)对于每个网格,计算垂直层最小值vertmax(x)
vertsum(x)vertmean(x)
vertavg(x)
vertstd(x)vertstd1(x)
vertvar(x)vertvar1(x)
切片
sellevel(x,k)Select level k of variable xsellevidx(x,k)Select level index k of variable x
sellevelrange(x,k1,k2)Select levels in range(k1, k2) of xsellevidxrange(x,k1,k2)Select level indices in range(k1, k2) of x
remove(x)Remove x from output stream

Mathematical functions 数学函数

<operator> infile outfile

OperatorsDescriptionOperatorsDescription
abs
intnint
pow
sqrsqrt
exp
lnlog10
sinasin
cosacos
tanatan
reci
not, if x equal 0; else

<operator>,c infile outfile

OperatorsDescriptionOperatorsDescription
addc,csubc,c
mulc,cdivc,c
minc,cmaxc,c

<operator> infile1 infile2 outfile

OperatorsDescriptionOperatorsDescription
addsub
muldiv
minmax
atan2

Daily arithmetic 日计算函数

<operator> infile1 infile2 outfile

a time seriesa daily time series 进行简单的计算,其中包含相同的日、月和年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的日、月、年的字段;

通常, infile2 是由 DAYSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
dayadddaysub
daymuldaydiv
  • 例子
    从时间序列使用中减去每日平均时间:

    1
    cdo daysub infile -dayavg infile outfile  

Monthly arithmetic 月计算函数

<operator> infile1 infile2 outfile

a time seriesa monthly time series 进行简单的计算,其中包含相同的月和年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的月和年的字段;

通常, infile2 是由 MONSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
monaddmonsub
monmulmondiv
  • 例子
    从时间序列使用中减去月平均时间:

    1
    cdo monsub infile -monavg infile outfile  

Yearly arithmetic 年计算函数

<operator> infile1 infile2 outfile

a time seriesa yearly time series 进行简单的计算,其中包含相同的年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的年的字段;

通常, infile2 是由 YEARSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
yearaddyearsub
yearmulyeardiv
  • 例子
    从时间序列使用中减去年平均时间:

    1
    cdo yearsub infile -yearavg infile outfile  

Multi-year hourly arithmetic

<operator> infile1 infile2 outfile

a time series 和 **a multi-year hourly time series (≤365*24) 进行简单的计算,其中包含一年中相同的日期和小时**;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的日期和小时的字段;

通常, infile2 是由 YHOURSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
yhouraddyhoursub
yhourmulyhourdiv
  • 例子
    从时间序列使用中减去多年的小时平均:

    1
    cdo yhoursub infile -yhouravg infile outfile   

Multi-year daily arithmetic

<operator> infile1 infile2 outfile

a time seriesa multi-year daily time series (≤365) 进行简单的计算,其中包含一年中相同的日期;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的日期的字段;

通常, infile2 是由 YDAYSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
ydayaddydaysub
ydaymulydaydiv
  • 例子
    从时间序列使用中减去多年的日平均:

    1
    cdo ydaysub infile -ydayavg infile outfile  

Multi-year monthly arithmetic

<operator> infile1 infile2 outfile

a time seriesa multi-year monthly time series (≤12) 进行简单的计算,其中包含一年中相同的月份;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的月份的字段;

通常, infile2 是由 YMONSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
ymonaddymonsub
ymonmulymondiv
  • 例子
    从时间序列使用中减去多年的月平均:

    1
    cdo ymonsub infile -ymonavg infile outfile  

Multi-year seasonal arithmetic

<operator> infile1 infile2 outfile

a time seriesa multi-year seasonal time series (≤4) 进行简单的计算,其中包含一年中相同的季节;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的季节的字段;

通常, infile2 是由 YSEASSTAT 模块 的操作生成的;

OperatorsDescriptionOperatorsDescription
yseasaddyseassub
yseasmulyseasdiv
  • 例子
    从时间序列使用中减去多年的季节平均:

    1
    cdo yseassub infile -yseasavg infile outfile  

Arithmetic with days

<operator> infile outfile

将 infile 的每个时间步乘以或除以相应的每月天数或每年天数

OperatorsDescriptionOperatorsDescription
muldpmdivdpm
muldpydivdpy

Arithmetic with latitude

<operator> infile outfile

将 infile 的每个元素乘以或除以相应的 纬度的余弦

OperatorsDescription
mulcoslat
divcoslat