Project

General

Profile

Properly weighted seasonal means from monthly data

Added by Joe Hamman over 11 years ago

There is a function to properly weight yearly means from monthly data (yearmonmean) but I can't seem to find one for seasonal means? Has anyone done this using CDO and what's the best way to go about it?

Thanks,

Joe


Replies (11)

RE: Properly weighted seasonal means from monthly data - Added by Matt Thompson over 11 years ago

Joe,

Does an operator like seasmean or yseasmean do what you want? If not, you could probably use timselmean to do it as there is an example that seems to echo what you want:

Assume an input dataset has monthly means over several years. To compute seasonal means from monthly means the first two month have to be skipped:
  cdo timselmean,3,2 ifile ofile

RE: Properly weighted seasonal means from monthly data - Added by Joe Hamman over 11 years ago

yseasmean does what I want except it does not take into account the different weights (days per month) of individual months. yearmonmean does do this for yearly averages but I don't think there is a yseasmonmean. I've tried, unsuccessfully to string together yseasmean something like muldpm. I'm sure there is a way to do this but I'm not sure what the right chain of operators would be.

RE: Properly weighted seasonal means from monthly data - Added by François Roberge over 7 years ago

Hi Joe,

Did you ever find a solution for this? There doesn't seem to be any cdo command that does it.

Thank you,

François Roberge

RE: Properly weighted seasonal means from monthly data - Added by Karin Meier-Fleischer over 7 years ago

Hi Françoise,

try

cdo -ymonmean infile.nc outfile_ymm.nc

cdo -seasmean outfile_ymm.nc outfile.nc

-Karin

RE: Properly weighted seasonal means from monthly data - Added by François Roberge over 7 years ago

Hi Karin,

Yes but by doing this way, the seasonal means won’t be weighted according to the number of days per each month.

Thank you,

François

RE: Properly weighted seasonal means from monthly data - Added by XR Chua over 5 years ago

Here is one workaround, using DJF as an example:

cdo -ymonmean infile.nc tmp1.nc
cdo -selmon,12,1,2 tmp1.nc tmp2.nc
cdo -timmean tmp2.nc outfile.nc

RE: Properly weighted seasonal means from monthly data - Added by François Roberge over 5 years ago

XR Chua wrote:

Here is one workaround, using DJF as an example:

cdo -ymonmean infile.nc tmp1.nc
cdo -selmon,12,1,2 tmp1.nc tmp2.nc
cdo -timmean tmp2.nc outfile.nc

HI Xr Chua,

tmp1.nc contains only one timestep per month so by doing timmean, you are doing the mean over three time steps which doesn't consider the weights according to the number of days per each month.

Thank you,

François

RE: Properly weighted seasonal means from monthly data - Added by XR Chua over 5 years ago

My bad, I meant yearmonmean instead of timmean:


cdo -ymonmean infile.nc tmp1.nc
cdo -selmon,12,1,2 tmp1.nc tmp2.nc
cdo -yearmonmean tmp2.nc outfile.nc

Thanks for the catch!

RE: Properly weighted seasonal means from monthly data - Added by XR Chua 9 days ago

Upon revisiting this, I realize that the above does not account for leap days. A preferred way would be to calculate the mean for each season and averaging over the years.

This shows an example of weighting the time series by the number of days in each month.

(research) chuaxr@x1002c3s5b1n1:~$ cdo -s outputtab,date,value -selseason,DJF -seldate,0003-01-01,0003-12-31 -monmean -seq,1,1461
#      date    value
 0003-01-16      746
 0003-02-14    775.5
 0003-12-16     1080
(research) chuaxr@x1002c3s5b1n1:~$  cdo -s outputtab,date,value -selseason,DJF -seldate,0004-01-01,0004-12-31 -monmean -seq,1,1461
#      date    value
 0004-01-16     1111
 0004-02-15     1141
 0004-12-16     1446
(research) chuaxr@x1002c3s5b1n1:~$ python -c "print((746*31+775.5*28+1080*31)/90)" 
870.2222222222222
(research) chuaxr@x1002c3s5b1n1:~$ python -c "print((1111*31+1141*29+1446*31)/91)" 
1234.6813186813188
(research) chuaxr@x1002c3s5b1n1:~$ python -c "print((870.222+1234.68)/2)" 
1052.451

This shows the numbers calculated by using ymonmean as compared to calculating each year separately.

(research) chuaxr@x1002c3s5b1n1:~$ cdo -s output -yearmonmean -ymonmean -selseason,DJF -seldate,0003-01-01,0004-12-31 -monmean -seq,1
,1461
      1051.93
(research) chuaxr@x1002c3s5b1n1:~$ cdo -s output -yearmonmean -selseason,DJF -seldate,0003-01-01,0003-12-31 -monmean -seq,1,1461
      870.222
(research) chuaxr@x1002c3s5b1n1:~$ cdo -s output -yearmonmean -selseason,DJF -seldate,0004-01-01,0004-12-31 -monmean -seq,1,1461
      1234.68

RE: Properly weighted seasonal means from monthly data - Added by Uwe Schulzweida 8 days ago

You're right, the two functions yearmonmean and ymonmean need to be swapped. So first calculate the weighted monthly averages with yearmonmean and then the simple average over the years:

cdo -s output -ymonmean -yearmonmean -selseason,DJF -seldate,0003-01-01,0004-12-31 -monmean -seq,1,1461
      1052.45

RE: Properly weighted seasonal means from monthly data - Added by XR Chua 8 days ago

Thanks Uwe. Directly swopping yearmonmean and ymonmean does work for the example above, but for the case that the data does not span calendar years it seems that calculating chunk by chunk might stil be required.

For example if I had the time series from 0003-07-01 to 0004-06-30 and wanted to calculate the mean over DJF it seems treating the year separately is still needed:

(research) chuaxr@x1003c4s1b0n0:~$ cdo -s outputtab,date,value -selseason,DJF -seldate,0003-07-01,0004-06-30 -monmean -seq,1,1461
#      date    value
 0003-12-16     1080
 0004-01-16     1111
 0004-02-15     1141
(research) chuaxr@x1003c4s1b0n0:~$ python -c "print((1080*31+1111*31+1141*29)/91)" 
1110.0
(research) chuaxr@x1003c4s1b0n0:~$ cdo -s output -ymonmean -yearmonmean -selseason,DJF -seldate,0003-07-01,0004-06-30 -monmean -seq,1,1461
       1125.5
         1080
(research) chuaxr@x1003c4s1b0n0:~$ cdo -s output -ymonmean -yearmonmean -selseason,DJF -setyear,0004 -seldate,0003-07-01,0004-06-30 -
monmean -seq,1,1461
cdo(4) setyear (Warning): Time bounds unsupported by this operator, removed!
         1110

    (1-11/11)