Project

General

Profile

yearsum with offset (Oct1 -> Nov 30)

Added by ken mankoff over 6 years ago

Dear CDO list,

I've recently discovered CDO and it has been extremely helpful for re-projecting from a strange rotated pole grid to a standard grid. I've also use it to calculate annual sums from daily data, using

cdo yearsum in.nc out.nc

I'd now like to calculate annual sums, but for a "hydrologic year", meaning from 1 OCT to 30 SEP. Is this possible with CDO?

Thank you,

Ken Mankoff


Replies (1)

RE: yearsum with offset (Oct1 -> Nov 30) - Added by Karin Meier-Fleischer over 6 years ago

Hi Ken,

IMO there is no easy way but you can use a shell script to select the months and then do a timsum:

#!/bin/ksh

  infile=data.nc
  outfile=data_Oct_to_Sep_sum

  ntimes=$(cdo -s ntime $infile)

  firstt=$(cdo -s -showyear -seltimestep,1 $infile)
  lastt=$(cdo -s -showyear -seltimestep,$ntimes $infile)
  lastt=`expr $lastt - 1`

  echo "$firstt $lastt" 

  for year in $(seq -w $firstt 1 $lastt);
    do
      next=`expr $year + 1`
      cdo -s -O -selmon,10/12 -selyear,$year $infile tmp_1.nc
      cdo -s -O -selmon,1/9 -selyear,$next $infile tmp_2.nc
      cdo -s -O -mergetime tmp_1.nc tmp_2.nc tmp.nc
      cdo -s -O timsum tmp.nc ${outfile}_${year}.nc
    done

exit

It generates for each Oct-Sep (12 months) one file containing the time sum, the time stamp
is the Sep, 30th.

Hope this will help.

-Karin

    (1-1/1)