CDO - 算术运算的操作
本篇随笔将介绍 CDO 在不同维度上进行算术运算的相关功能
Arithmetic 计算
Evaluate expressions 表达式求值
<operator>,parameter infile outfile
| Operators | Type | Description |
|---|---|---|
| expr,instr | STRING | 从参数中读取表达式,输出数据集只追加结果不保留输入数据集的变量; 例子: infile 中包含变量 aprl, aprc 和 ts,创建新变量 var1 和 var2 进行表达式计算:cdo expr,’var1=aprl+aprc;var2=ts-273.15;’ infile outfile |
| exprf,filename | STRING | 从文件中读取表达式,输出数据集只追加结果不保留输入数据集的变量;cdo exprf,myexpr infile outfile |
| aexpr,instr | STRING | 从参数中读取表达式,输出数据集追加结果并保留输入数据集的变量; |
| aexprf,filename | STRING | 从文件中读取表达式,输出数据集追加结果并保留输入数据集的变量; |
| Expressions | Description | Expressions | Description |
|---|---|---|---|
| 表达式 | |||
| x = y | x + y | ||
| x - y | x / y | ||
| x * y | x ^ y | ||
| x == y | x != y | ||
| x > y | x >= y | ||
| x < y | x <= y | ||
| x <=> y | -1, if x < y; 1, if x > y; else 0 | ||
| x && y | x || y | ||
| !x | x ? y : z | y, if x ≠ 0, else z | |
| 计算 | |||
| floor(x) | 不大于 x 的最大整数 | ceil(x) | 不小于 x 的最小整数值 |
| int(x) | nint(x) | 距离 x 最近的整数 | |
| float(x) | abs(x) | ||
| sqr(x) | Square of x | sqrt(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.millisecond | cdeltat() | Difference between current and last timestep in seconds |
| cday() | Day as DD | cmonth() | Month as MM |
| cyear() | Year as YYYY | csecond() | Second as SS.millisecond |
| cminute() | Minute as MM | chour() | 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 x | sellevidx(x,k) | Select level index k of variable x |
| sellevelrange(x,k1,k2) | Select levels in range(k1, k2) of x | sellevidxrange(x,k1,k2) | Select level indices in range(k1, k2) of x |
| remove(x) | Remove x from output stream |
Mathematical functions 数学函数
<operator> infile outfile
| Operators | Description | Operators | Description |
|---|---|---|---|
| abs | |||
| int | nint | ||
| pow | |||
| sqr | sqrt | ||
| exp | |||
| ln | log10 | ||
| sin | asin | ||
| cos | acos | ||
| tan | atan | ||
| reci | |||
| not |
<operator>,c infile outfile
| Operators | Description | Operators | Description |
|---|---|---|---|
| addc,c | subc,c | ||
| mulc,c | divc,c | ||
| minc,c | maxc,c |
<operator> infile1 infile2 outfile
| Operators | Description | Operators | Description |
|---|---|---|---|
| add | sub | ||
| mul | div | ||
| min | max | ||
| atan2 |
Daily arithmetic 日计算函数
<operator> infile1 infile2 outfile
对 a time series 和 a daily time series 进行简单的计算,其中包含相同的日、月和年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的日、月、年的字段;
通常, infile2 是由 DAYSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| dayadd | daysub | ||
| daymul | daydiv |
例子
从时间序列使用中减去每日平均时间:1
cdo daysub infile -dayavg infile outfile
Monthly arithmetic 月计算函数
<operator> infile1 infile2 outfile
对 a time series 和 a monthly time series 进行简单的计算,其中包含相同的月和年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的月和年的字段;
通常, infile2 是由 MONSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| monadd | monsub | ||
| monmul | mondiv |
例子
从时间序列使用中减去月平均时间:1
cdo monsub infile -monavg infile outfile
Yearly arithmetic 年计算函数
<operator> infile1 infile2 outfile
对 a time series 和 a yearly time series 进行简单的计算,其中包含相同的年;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的相同的年的字段;
通常, infile2 是由 YEARSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| yearadd | yearsub | ||
| yearmul | yeardiv |
例子
从时间序列使用中减去年平均时间: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 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| yhouradd | yhoursub | ||
| yhourmul | yhourdiv |
例子
从时间序列使用中减去多年的小时平均:1
cdo yhoursub infile -yhouravg infile outfile
Multi-year daily arithmetic
<operator> infile1 infile2 outfile
对 a time series 和 a multi-year daily time series (≤365) 进行简单的计算,其中包含一年中相同的日期;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的日期的字段;
通常, infile2 是由 YDAYSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| ydayadd | ydaysub | ||
| ydaymul | ydaydiv |
例子
从时间序列使用中减去多年的日平均:1
cdo ydaysub infile -ydayavg infile outfile
Multi-year monthly arithmetic
<operator> infile1 infile2 outfile
对 a time series 和 a multi-year monthly time series (≤12) 进行简单的计算,其中包含一年中相同的月份;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的月份的字段;
通常, infile2 是由 YMONSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| ymonadd | ymonsub | ||
| ymonmul | ymondiv |
例子
从时间序列使用中减去多年的月平均:1
cdo ymonsub infile -ymonavg infile outfile
Multi-year seasonal arithmetic
<operator> infile1 infile2 outfile
对 a time series 和 a multi-year seasonal time series (≤4) 进行简单的计算,其中包含一年中相同的季节;对于 infile1 中的每一个字段,都使用 infile2 中时间步的对应的一年中相同的季节的字段;
通常, infile2 是由 YSEASSTAT 模块 的操作生成的;
| Operators | Description | Operators | Description |
|---|---|---|---|
| yseasadd | yseassub | ||
| yseasmul | yseasdiv |
例子
从时间序列使用中减去多年的季节平均:1
cdo yseassub infile -yseasavg infile outfile
Arithmetic with days
<operator> infile outfile
将 infile 的每个时间步乘以或除以相应的每月天数或每年天数
| Operators | Description | Operators | Description |
|---|---|---|---|
| muldpm | divdpm | ||
| muldpy | divdpy |
Arithmetic with latitude
<operator> infile outfile
将 infile 的每个元素乘以或除以相应的 纬度的余弦
| Operators | Description |
|---|---|
| mulcoslat | |
| divcoslat |