1

I have a netCDF file for temperature going back the last 22 thousand years at a decadal average (TraCE dataset). I want to calculate 100 or 1000 year averages.

I am really stuck, if anyone could help then that would be great. I am mostly using R, but if it is simple in cdo then I can try this too.

I don't have any code to show as I really don't know where to start. Most examples I have seen have been on daily or yearly data... not decadal

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • I should also add that the time units are in ka BP (thousand years before present) therefore making it harder to use a normal function in CDO – LAURA BOYALL Nov 10 '22 at 17:13
  • any chance to can post a link to an example file so we can try to resolve the date stamp issue? Actually, maybe you want to post that as a separate question i.e. "How to change Kybp into CF compliant dates?" With a link to an example file – ClimateUnboxed Nov 15 '22 at 07:50

2 Answers2

1

Your data is decadal averages, so it should be easy to do this in CDO. You want to calculate a rolling average which is averaged over every 10 time steps. For this runmean is your friend. Just do the following:

cdo runmean,10 infile.nc outfile.nc

You might need to subset time afterwards, depending on the exact output you want. It sounds like the time you have may be non-standard, but runmean should still be OK.

Robert Wilson
  • 3,192
  • 11
  • 19
1

Robert's solution is useful if you want a smoothed output at the 100 or 1000 year timescale. Your original dataset has 2200 timesteps, and runmean,10 smooths this and produces an output with 2200-9=2191 timesteps, each of which is an average over a 100 year window either centered on the slice itself or lagged/lead, depending on the option used.

However, from your question, I think you are more likely to want an output where the first slice is the average over the first century, the second is for the second century and so on, that is, an output with 220 timeslices, each a century average (or 22 time-slices of 1000 year averages). In other words, you want a command analogous to daymean, monmean and yearmean, but as there is no command called centurymean, then you can instead resort to the more generic command timselmean and manually define your window length:

# Centurial average:
cdo timselmean,10 infile.nc outfile.nc 

# Millennial Average:
cdo timselmean,100 infile.nc outfile.nc 

I think this should still work despite the non-CF compliant time units you mention in the comment (but let us know if it doesn't)

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Thanks both of you. But when I run Adrian's code I get an error message: Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable time_written! setBaseTime : Unsupported TIMEUNIT: ka BP! cdo timselmean (Abort): Fields have different size (vfarsum) – LAURA BOYALL Nov 11 '22 at 18:09
  • Also, I am really sorry about the format of this comment, I am unsure how to add in a block of code... very new to stack overflow. – LAURA BOYALL Nov 11 '22 at 18:10
  • Ok, that's a warning for the non-CF compliant time units, I'm trying to see if I can find a cdo based soln but unfortunately the MPI web server seems to be down since yesterday. – ClimateUnboxed Nov 12 '22 at 12:04
  • in the meantime, would an adaptation of this nco solution help to resolve the time units ? https://stackoverflow.com/questions/64624632/change-time-axis-units-from-years-since-to-days-since-in-netcdf-file – ClimateUnboxed Nov 12 '22 at 12:04
  • Thank you for trying! I had tried nco previously and had no luck but I will try again using an adaptation of this, thanks. I am going to try in ferret too as I have done it in there before I just cannot find the script I used!! – LAURA BOYALL Nov 12 '22 at 13:51
  • haha know that feeling all too well... when the server comes up at mpi i'll see if i can dig around and find a soln... – ClimateUnboxed Nov 12 '22 at 14:19
  • That would be amazing, thank you so much – LAURA BOYALL Nov 13 '22 at 09:59