CDO學習1 CDO簡介


參考自如下網站 

http://www.ceda.ac.uk/static/media/uploads/ncas-reading-2015/cdo.pdf

介紹

  • 一個有幾百種操作符的單獨命令
  • CDO受NCO啟發,通過命令行,提供了一系列的氣候數據相關的操作
  • 主要是被設計用在操作netCDF3/4,GRIB1/2
  • 眾多的函數可以被用在任何NetCDF/格點化數據
  • 非常適合與特定任務
  • 有效的調動內存

CDO:一個命令行工具

$ cdo <operator> [options] <files>

CDO操作的類別

  1. 文件信息和文件操作符
  2. 選擇和比較
  3. 元數據的修改
  4. 算術操作符
  5. 統計分析
  6. 回歸和內插
  7. 矢量和譜轉換
  8. 格式化I/O
  9. 氣候指數

眾多操作符

CDO將其的功能分解成單獨的操作符

當前(2015年)有超過650個操作符。如

showstdname Show standard names

sellonlatbox Select a longitude/latitude box

setmissval Set a new missing value

monadd Add monthly time series

zonstd Zonal standard deviation

eca_hd Heating degree days per time period

得到操作符的參考

如需參考,只需輸入:cdo -h <operator>

 操作符:1.文件信息

 $ cdo infov ifile 

這是一個帶有一個2D變量的數據集的示例結果,包括3個時間步長:

-1 : Date Time Varname Level Size Miss : Minimum Mean Maximum
1 : 1987?01?31 12:00:00 SST 0 2048 1361 : 232.77 266.65 305.31
2 : 1987?02?28 12:00:00 SST 0 2048 1361 : 233.64 267.11 307.15
3 : 1987?03?31 12:00:00 SST 0 2048 1361 : 225.31 267.52 307.67

 

$ cdo showtimestamp ggas2014121200_00-18.nc
2014-12-12T00:00:00 2014-12-12T06:00:00 2014-12-12T12:00:00 2014-12-12T18:00:00

 

$ cdo pardes ggas2014121200_00-18.nc
-1 CI Sea-ice cover [(0 - 1)]
-2 SSTK Sea surface temperature [K]
-3 MSL Mean sea-level pressure [Pa]
-4 TCC Total cloud cover [(0 - 1)]
-5 U10 10 metre U wind component [m s**-1]
-6 V10 10 metre V wind component [m s**-1]
-7 SKT Skin temperature [K]

 

很容易看到2個文件之間數值差異的概況:

$ cdo diff tas_rcp45_2055_ann_95p_change.nc tas_rcp45_2055_ann_05p_change.nc
Date Time Param Level Size Miss : S Z Max_Absdiff Max_Reldiff
1 : 2065-12-30 12:00:00 -1 0 64800 0 : T F 16.693 0.99997
1 of 1 records differ

 

操作符的所有文件列表包括

  • 賦值和連接
  • 合並場和時間
  • 按變量/層次/格點/時間分割場

一些例子

To copy a file and convert the output to NetCDF:

 $ cdo −f nc copy ifile ofile.nc 

To merge all files along the time axis:
 $ cdo mergetime ifile1 ifile2 ifile3 ofile 

可以用一些不同的方法選擇數據包括:

  • 變量碼,名稱或者屬性
  • 層次
  • 時間
  • 空間區域(緯度/經度)

 

操作符:2.選擇

用id選擇變量:“SSTK”和"CI":

 $ cdo selname,SSTK,CI infile.nc outfile.nc 

To select a lat/lon bounding box:
 $ cdo sellonlatbox,120,-90,20,-20 infile.nc outfile.nc 

To select a date/time range:
 $ cdo seldate,2014-12-12T12:00:00, 2015-01-31T18:00:00 infile.nc outfile.nc 

 

操作符:3.修改

設置時間軸到198701-16 12:00, 時間增量一個月增量 使用

 $ cdo settaxis,1987-01-16,12:00,1mon ifile ofile 

將一個2維場緯度從N到S反轉成S到N

 $ cdo invertlat ifile ofile 

 

操作符:4.算術

計算所有場元素的平方根:

 $ cdo sqrt ifile ofile 

將所有輸入場加入一個常數-273.15:

 $ cdo -addc,-273.15 ifile ofile 

 

操作符:5.統計

計算所有輸入場的緯向平均:

 $ cdo zonmean ifile ofile 

假設輸入數據集具有數年的月度平均值。 為了從月度計算季節性均值,必須跳過前兩個月:Assume an input dataset has monthly means over several years. In order to compute seasonal means from monthly means the first two months must be skipped:

 $ cdo timselmean,3,2 ifile ofile 

多年逐日滑動百分值:

  • 為了計算一個百分值,必須知道最小和最大邊界。

 $ cdo ydrunpctdl,p,nts infile minfile maxfile outfile 

該運算符寫滑動的百分值對於一年中的每一天,從infile寫到outfile。最小和最大邊界用minfile和maxfile提供。

計算一個對年逐日的滑動百分率值,需要執行多步。

$ cdo ydrunmin,5 ifile minfile
$ cdo ydrunmax,5 ifile maxfile
$ cdo ydrunpctl,90,5 ifile minfile maxfile ofile

 

操作符:6 內插

為了將所有場線性插值到一個T42高斯格點。

 $ cdo remapbil,t42grid ifile ofile 

為了將混合模式層數據插值到氣壓層925,850,500和200 hPa

 $ cdo ml2pl,92500,85000,50000,20000 ifile ofile 

 

操作符:9 氣候指數

得到一個逐日降水總量時間序列找那個連續干日的最大數目。

 $ cdo eca_cdd rrfile ofile 

其中rrfile是逐日降水總量RR的時間序列,然后統計了連續天數的最大值,當RR小於1 mm時。

為了得到熱帶夜晚一個時間序列逐日最小溫度

 $ cdo eca_tr tnfile ofile 

其中tnfile是逐日最低溫度TN的時間序列,隨后統計的是當TN>T時候的天數。T是一個可選的參數,其缺省值T=20℃。

 

除此之外CDO還能做什么? CDO有許多通用的命令行開關,可以與(大多數)運算符一起使用。 這是一個選擇:

-a 生成絕對時間軸Generate an absolute time axis
-f <format> 指定格式Specify format ("grb", "nc", "nc4" etc)
-m <val> 設置默認缺測值Set the default missing value
-Q 對netCDF變量名排序Sort netCDF variable names
-r 生成相對時間軸Generate a relative time axis
-s 靜默模式Silent mode
-V Version of CDO
-v Verbose - print extra details.
-z zip Deflate compression of netCDF4 vars.

 

組合運算符

所有的運算符都有一個固定的輸入流和一個輸出流,可以直接將結果管道給其它的操作符。這個操作符必須以“-”開始,為了和其它相結合。可以通過一下,來促進性能:

  • 減少不必要的磁盤I/O
  • 並行執行

例如,我們可以把

$ cdo timavg ifile1 tmp1
$ cdo dayavg ifile2 tmp2
$ cdo sub tmp2 tmp1 ofile
$ rm tmp1 tmp2

替換成

$ cdo sub -dayavg ifile2 -timavg ifile1 ofile

 

組合運算符:例子2

以下三個命令是計算一個多年逐日滑動百分率,需要多步:

$ cdo ydrunmin,5 ifile minfile
$ cdo ydrunmax,5 ifile maxfile
$ cdo ydrunpctl,90,5 ifile minfile maxfile ofile

可以通過一個簡單的命令替換

$ cdo ydrunpctl,90,5 ifile -ydrunmin ifile -ydrunmax ifile ofile

 

更多信息 

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf

CDO Home page:  https://code.zmaw.de/projects/cdo

CDO Tutorial:  https://code.zmaw.de/projects/cdo/wiki/Tutorial

CDO Documentation:  https://code.zmaw.de/projects/cdo/wiki#Documentation


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM