用戶手冊,參考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>
基本用法
- 顯示文件的變量Display variables of a file
cdo -showname <infile>
- 顯示文件的時間步數目Display number of timesteps of a file
cdo -ntime <infile>
- 顯示格點信息?Display Information about the underlying grid: griddes does the following:
cdo -griddes tsurf.nc
- 文件轉換到不同類型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
- 選擇變量Select variables from file: select variable tas
cdo -selname,tas <infile> <outfile>
select variables u10 and v10cdo -selname,u10,v10 <infile> <outfile>
- 選擇時間步Select timesteps from file: e.g. select only the 3rd time step
cdo -seltimestep,3 <infile> <outfile>
or select 3 timestepscdo -seltimestep,1,13,25 <infile> <outfile>
or select a time range from 1 to 12cdo -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>
- 選取子區域Select only data of the northern hemisphere (sub-region):
cdo -sellonlatbox,-180,180,0,90 <infile> <outfile>
- 經緯度網格重新排列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>
- 經緯度反轉Invert the latitudes from north-south to south-north:
cdo -invertlat <infile> <outfile>
- 轉換成攝氏度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>
- 設置缺測值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>
- 計算各月的平均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>
- 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:沒有中間文件
- 並行處理:在一個工作鏈中的所有運算符並行運行
- 簡單組合:
cdo -sub -dayavg ifile2 -timavg ifile1 ofile
而不是
cdo -timavg ifile1 tmp1 cdo -dayavg ifile2 tmp2 cdo -sub tmp2 tmp1 ofile rm tmp1 tmp2
- 高級組合:
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>
select和delete操作符
我們已經看到了一些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的方法類似