CDO学习2 CDO 入门教程Tutorial

摘要:
#20210117#注意:如果您需要使用CDO拦截数据,可以参考bug中的几个博客文章:如何使用CDO从数据集中提取数据CDO条件选择数据-云+社区-腾讯云CDO转换数据集格式-云+社群-腾讯云-------------------------------------------------------------------------------------------------------

#20210117#注:如果需要用cdo对数据进行截取,可参考buguse的几篇博文:

  1. 如何利用CDO从数据集中提取数据
  2. CDO条件性选择数据 - 云+社区 - 腾讯云
  3. CDO转换数据集格式 - 云+社区 - 腾讯云

-------------------------------------------------------------------------------------------------------------

用户手册,参考https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf

本文翻译搬运自https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial

教程

CDO软件是一个包含大量标准处理气候和预报模式数据的算子的集合。该算子包括简单的统计和算术方程,资料选取和二次抽样,和空间插值。

开发CDO是为了为GRIB [GRIB]和NetCDF [NetCDF]数据集提供相同的处理功能集整合在一个包中。

CDI(气候数据接口)用于快速和文件格式独立访问GRIB和NetCDF数据集。还支持本地MPI-MET数据格式SERVICE,EXTRA和IEG。

GRIB和NetCDF数据集存在一些限制。 GRIB数据集必须一致,类似于NetCDF。 这意味着所有时间步都需要具有相同的变量,并且在一个时间步长内,每个变量只能出现一次。 NetCDF数据集仅支持经典数据模型和最多4维的阵列。 这些尺寸应仅用于水平和垂直网格以及时间。 NetCDF属性应遵循GDT,COARDS或CF约定。

引言

显示所有cdo选项

cdo -h

获得所有操作符有一个简短的声明

cdo -h

得到更多一个运算符的信息

cdo -h <operator>

得到完整信息的最好方法是阅读文档[[https://code.mpimet.mpg.de/projects/cdo/embedded/index.html]]

在开始工作前需要知道数据存储了哪些变量,什么格点,不要忘记查看定义的全局的变量维数属性。

使用'cdo info'命令,您可以看到时间步,层次,最小值,最大值,平均值和缺测值。 输入

cdo -info <infile>

并且使用NCO的ncdump可以显示所有元数据和数据内容。 要显示文件的元数据,请键入

ncdump -h <infile>

基本用法

  1. 显示文件的变量Display variables of a file
    cdo -showname <infile>
  2. 显示文件的时间步数目Display number of timesteps of a file
    cdo -ntime <infile>
  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
  5. 选择变量Select variables from file: select variable tas
    cdo -selname,tas <infile> <outfile>
    select variables u10 and v10
    cdo -selname,u10,v10 <infile> <outfile>
  6. 选择时间步Select timesteps from file: e.g. select only the 3rd time step
    cdo -seltimestep,3 <infile> <outfile>
    or select 3 timesteps
    cdo -seltimestep,1,13,25 <infile> <outfile>
    or select a time range from 1 to 12
    cdo -seltimestep,1/12 <infile> <outfile>
    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 <infile> <outfile>
  7. 选取子区域Select only data of the northern hemisphere (sub-region):
    cdo -sellonlatbox,-180,180,0,90 <infile> <outfile>
  8. 经纬度网格重新排列Rearrange data from longitude 0 to 360 degrees to -180 to 180 degrees (latitude: -90 to 90 degrees):
    cdo -sellonlatbox,-180,180,-90,90 <infile> <outfile>
  9. 经纬度反转Invert the latitudes from north-south to south-north:
    cdo -invertlat <infile> <outfile>
  10. 转换成摄氏度Convert from K to degC when input file contains temperature values:
    cdo -addc,-273.15 <infile> <outfile>
    and don't forget to change the variable (here tas) units, too. Combining operators:
    cdo -setattribute,tas@units="degC" -addc,-273.15 <infile> <outfile>
  11. 设置缺测值Set constant value to missing value: change data value -999.0 to be missing value
    cdo -setctomiss,-999.0 <infile> <outfile>
    or vice versa set missing value to constant value:
    cdo setmisstoc,0 <infile> <outfile>
  12. 计算各月的平均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 <infile> <outfile>
  13. Delete February 29th:
    cdo -delete,month=2,day=29 <infile> <outfile>

进行变量修改

可以使用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运算符接受多个属性,并且它支持通配符,比如:

cdo -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:没有中间文件
  • 并行处理:在一个工作链中的所有运算符并行运行
  1. 简单组合:
    cdo -sub -dayavg ifile2 -timavg ifile1 ofile
    而不是
      cdo -timavg ifile1 tmp1
    
      cdo -dayavg ifile2 tmp2
    
      cdo -sub tmp2 tmp1 ofile
    
      rm tmp1 tmp2
    
    
  2. 高级组合:
    cdo -timmean -yearsum -setrtoc2,75,78,1,0  -selmon,9,10,11,12,1,2,3 -selyear,1960/1969 ifile ofile

运算符链是CDO的主要特征之一。 尽可能多地使用它。 但请注意:具有任意输入文件列表的运算符不能与其他运算符组合使用:

expr 操作符

The expr 操作符可能是一个很少使用但却更有用的工具。 其目的是在任意字段上逐点计算复杂的数学运算。

假设height.nc like height.nc包含一个3d垂直坐标变量z,为了输出气压,可以像这样使用expr:

cdo -expr,'ps=1013.25*exp((-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)' <infile> <outfile>

将变量tas单位转换为摄氏度,并计算tupper和tlower变量:

cdo -expr,'tc=tas-273.15; tplus = ((tc >= 0)) ? tc : (tc/0.0); tmin = ((tc < 0)) ? tc : (tas/0.0)' <infile> <outfile>

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的方法类似 

引自https://cloud.tencent.com/developer/article/1618310 注:

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

免责声明:文章转载自《CDO学习2 CDO 入门教程Tutorial》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【Python】opencv显示图像echarts 定制化(优化样式、交互)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Mysql的变量一览

Server System Variables(系统变量) MySQL系统变量(system variables)是指MySQL实例的各种系统变量,实际上是一些系统参数,用于初始化或设定数据库对系统资源的占用,文件存放位置等等,这些变量包含MySQL编译时的参数默认值,或者my.cnf配置文件里配置的参数值。默认情况下系统变量都是小写字母。 作用域范围 系...

【转】C++标准转换运算符static_cast

static_cast<new_type> (expression) 虽然const_cast是用来去除变量的const限定,但是static_cast却不是用来去除变量的static引用。其实这是很容易理解的,static决定的是一个变量的作用域和生命周期,比如:在一个文件中将变量定义为static,则说明这个变量只能在本Package中使用...

MYSQL数据库基础篇

MySQL基础入门 一、数据库1 数据库概念(了解) 1.1 什么是数据库 数据库就是用来存储和管理数据的仓库! 数据库存储数据的优先: l  可存储大量数据; l  方便检索; l  保持数据的一致性、完整性; l  安全,可共享; l  通过组合分析,可产生新数据。 数据库具有原子性,数据不可再分割! 1.2 数据库的发展历程 l  没有数据库,使用...

jquery 多级联动下拉列表含(数据模型)

方法 /** * 级联 * 联动 * @param url:访问json数据的地址 * @param param:参数 * @param levelIds:页面下拉标签数组,为联动级数 * @private */ function _yh_linkage(url,params, levelIds){ _yh_post...

Oracle函数

Oracle函数 一.字符函数 (1)大小写控制函数 lower():全部小写 select LOWER('SMITH') "CLERK" from DUAL;upper():全部大写 SELECT UPPER('last_name') "Uppercase"FROM dual;initcap():首字母大写 SELECT INITCAP('the soa...

Linux网络编程 select/epoll得知socket有数据可读,如何判断数据全部被读取完毕?

补充一点:只有在使用epoll ET(Edge Trigger)模式的时候,才需要关注数据是否读取完毕了。使用select或者epoll的LT模式,其实根本不用关注数据是否读完了,select/epoll检测到有数据可读去读就OK了。 这里有两种做法: 1. 针对TCP,调用recv方法,根据recv方法的返回值,如果返回值小于我们指定的recv buf...