简体   繁体   English

使用 CDO 从 netcdf 计算月平均和年降水量总和

[英]Calculate monthly average and annual sum of precipitation from netcdf with CDO

I am learning netCDF and CDO with a CRU ts_4.04 data.我正在使用 CRU ts_4.04 数据学习 netCDF 和 CDO。 I want to calculate the monthly average and annual sum of precipitation in London.我想计算伦敦的月平均降水量和年降水量总和。 I wrote:我写:

#!/usr/bin/bash
lon=-0.11
lat=51.49
PREFNAME="/myHD/CRU4.04/pre/cru_ts4.04.1901.2019.pre.dat.nc"
OUTFNAME="outfile-"
echo "1970-2000 monthly average and annual sum of precipitations in London"
cdo remapnn,lon=$lon/lat=$lat $PREFNAME               $OUTFNAME"place.nc"
cdo selvar,pre                $OUTFNAME"place.nc"     $OUTFNAME"var.nc"
cdo selyear,1970/2000         $OUTFNAME"var.nc"       $OUTFNAME"years.nc"
cdo ymonmean                  $OUTFNAME"years.nc"     $OUTFNAME"yearsmean.nc"
cdo timcumsum                 $OUTFNAME"yearsmean.nc" $OUTFNAME"yearsum.nc"
cdo info $OUTFNAME"yearsum.nc"
cdo info $OUTFNAME"yearsmean.nc"
exit

I get:我得到:

MyPC:~/workbench01$ ./gotit2.sh 
1970-2000 monthly average and annual sum of precipitations in London
cdo    remapnn: Nearest neighbor weights from lonlat (720x360) to lonlat (1x1) grid, with source mask (67420)
cdo    remapnn: Processed 2 variables over 1428 timesteps [2.64s 60MB].
cdo    selname: Processed 2 variables over 1428 timesteps [0.01s 52MB].
cdo    selyear: Processed 1 variable over 1428 timesteps [0.00s 51MB].
cdo    ymonmean: Processed 1 variable over 372 timesteps [0.00s 51MB].
cdo    timcumsum: Processed 1 variable over 12 timesteps [0.00s 51MB].
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
     1 : 2000-01-16 00:00:00       0        1       0 :                  81.229             : -1            
     2 : 2000-02-15 00:00:00       0        1       0 :                  132.26             : -1            
     3 : 2000-03-16 00:00:00       0        1       0 :                  189.70             : -1            
     4 : 2000-04-16 00:00:00       0        1       0 :                  244.82             : -1            
     5 : 2000-05-16 00:00:00       0        1       0 :                  298.52             : -1            
     6 : 2000-06-16 00:00:00       0        1       0 :                  356.92             : -1            
     7 : 2000-07-16 00:00:00       0        1       0 :                  402.39             : -1            
     8 : 2000-08-16 00:00:00       0        1       0 :                  456.03             : -1            
     9 : 2000-09-16 00:00:00       0        1       0 :                  527.19             : -1            
    10 : 2000-10-16 00:00:00       0        1       0 :                  605.04             : -1            
    11 : 2000-11-16 00:00:00       0        1       0 :                  682.58             : -1            
    12 : 2000-12-16 00:00:00       0        1       0 :                  762.59             : -1            
cdo    info: Processed 1 variable over 12 timesteps [0.00s 50MB].
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
     1 : 2000-01-16 00:00:00       0        1       0 :                  81.229             : -1            
     2 : 2000-02-15 00:00:00       0        1       0 :                  51.032             : -1            
     3 : 2000-03-16 00:00:00       0        1       0 :                  57.439             : -1            
     4 : 2000-04-16 00:00:00       0        1       0 :                  55.116             : -1            
     5 : 2000-05-16 00:00:00       0        1       0 :                  53.700             : -1            
     6 : 2000-06-16 00:00:00       0        1       0 :                  58.400             : -1            
     7 : 2000-07-16 00:00:00       0        1       0 :                  45.471             : -1            
     8 : 2000-08-16 00:00:00       0        1       0 :                  53.642             : -1            
     9 : 2000-09-16 00:00:00       0        1       0 :                  71.161             : -1            
    10 : 2000-10-16 00:00:00       0        1       0 :                  77.845             : -1            
    11 : 2000-11-16 00:00:00       0        1       0 :                  77.545             : -1            
    12 : 2000-12-16 00:00:00       0        1       0 :                  80.006             : -1            
cdo    info: Processed 1 variable over 12 timesteps [0.00s 51MB].

It looks very well, but they aren't the same results as shown in https://climatecharts.net/ for London between 1970-2000 years with CRU ts4.04.它看起来非常好,但它们与 1970-2000 年间伦敦的 CRU ts4.04中显示的结果不同。

My question is: Am I calculating the monthly average and the yearly sum of precipitations?.我的问题是:我是否在计算月平均值和年降水量总和?

Thank you for any help.感谢您的任何帮助。

cdo functions: cdo 功能:

ymonmean 

calculates the average of each calendar month, ie the average of all the Januarys, the average of all the February etc... the resulting file will have 12 time steps.计算每个日历月的平均值,即所有一月的平均值、所有二月的平均值等...生成的文件将有 12 个时间步长。

timcumsum

then produces the cumulative sum over these 12 steps.然后产生这 12 个步骤的累积和。 So step 1 is still your January average, then the 2nd step has the sum of the January and February averages and so on, the resulting file still has 12 timesteps, and the result you need should be the last step.所以第 1 步仍然是您的 1 月平均值,然后第 2 步具有 1 月和 2 月平均值的总和,依此类推,生成的文件仍然有 12 个时间步长,您需要的结果应该是最后一步。

However, if you simply want to know what the mean average annual rainfall is, then you can simply calculate it directly with但是,如果您只是想知道平均年平均降雨量是多少,那么您可以直接使用

cdo yearsum in.nc out.nc  # calculate total for each year
cdo timmean out.nc year_average.nc # average over the totals

or piped using one line:或使用一条线管道:

cdo timmean -yearsum in.nc year_average.nc

A word of warning with the above, make sure your series has full calendar years.上面的警告,确保你的系列有完整的日历年。 If the first year starts in eg July, then that year's sum would obviously only have 6 months worth of rainfall, which would impact your statistics, likewise with the final month of the final year.如果第一年从 7 月开始,那么该年的总和显然只有 6 个月的降雨量,这将影响您的统计数据,最后一年的最后一个月也是如此。

Last thing, I see on the data page of the climatecharts that it uses observations directly and not the gridded cru, so you can anyway not expect the results to be exactly the same.最后一件事,我在气候图表的数据页面上看到它直接使用观察结果而不是网格 cru,所以无论如何你不能期望结果完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM