I have a netcdf-file with about 100 timesteps on a grid with one variable, which is accumulated over the timesteps. I am now interested in calculating the contribution of each timestep to the variable's value (i.e. the difference of consecutive timesteps).
Currently I use the following sequence:
- To extract every single timestep into a new file I use
cdo seltimestep,$i ...
, - calculate each difference into a new file with
cdo sub $i ${i-1} ...
- and merge those new files in the end with
cdo mergetime ...
into one single result file.
That seems to me to be very cumbersome and not ideal regarding to performance. Because of the amount of timesteps I cannot use a cdo pipeline and need to create many files in the meantime therefore.
Is there one better solution to convert an accumulated variable to timestep values with cdo (or something else like nco/ncl?)
numpy's diff computes the difference of consecutive entries.
I suspect you have a multi-dimension variable in your file, so here is a generic example of how to do it: