1

I have a .nc file that contains data every 6 hours of precipitation for 1 full year, my interest is to calculate the daily precipitation and compare with observed data, for this I must make them coincide temporally. To achieve this, the precipitation should accumulate between 12 utc of one day and 12 utc of the next day. Does anyone have a suggestion on how to achieve this with CDO?

Thank you!

2 Answers2

2

Well if the first slice covers 12-18 UTC, then essentially you want to average the timeseries 4 slices at a time, (right?) in which case you can use this

cdo timselmean,4 infile.nc outfile.nc  

If the timeseries starts instead at 00, you may need to remove the first two timeslices before you start (cdo seltimestep)

Another method is a bit more of a fudge, in that you can shift the series by 12 hours, and then use the day mean function. This would have the advantage of working for any frequency of data (i.e. you don't hardwire the factor "4" based on the data frequency)

cdo daymean -shifttime,-12hours infile.nc outfile.nc 
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Adrian, thanks for your help again!, I want to do the same thing that you taught me here: https://stackoverflow.com/questions/71639492/calculate-daily-precipitation-between-12pm-and-12pm-of-the-other-day. But now instead of having one data per hour (24 data) I have 4 data (one data every 6 hours) starting at 00:00 utc – Fernando Primo Forgioni Jan 11 '23 at 13:26
  • yes that's what the answers do.... – ClimateUnboxed Jan 11 '23 at 13:31
  • 1
    The second answer sounds better to me, and not a fudge at all. `shfitime` could also be used to shift the day depending on how the output dates should be aligned – Robert Wilson Jan 12 '23 at 11:27
2

The answer Adrian Tompkins gives should work well. One additional point to note is that you can remove time steps in CDO. So, if your time starts at 0 UTC ands at 24 UTC, you do not want the first and last time step of Adrian's first answer, but you could modify it as follows:

cdo -timselmean,4 -delete,timestep=-1,-2,1,2 infile.nc outfile.nc

This will require a 2.x version of CDO.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Robert Wilson
  • 3,192
  • 11
  • 19
  • hi Robert, I switched your commands as you need to delete the odd steps before averaging no? If you do the averaging first all the steps will be wrong, not only the first and last. – ClimateUnboxed Jan 11 '23 at 18:54
  • Correct. Actually I was really thinking of your second answer. Where the first and last time step of the output will only have half a day of input. Seem to have got mixed up when I wrote the answer. – Robert Wilson Jan 12 '23 at 06:41