How to disaggregate an accumulated netcdf variable in time using ncl, cdo or nco?

687 Views Asked by At

I have a 3D netcdf variable PP = (time, lat, lon) of accumulated precipitation for an entire year and I want to calculate daily values.

I want to do something link in the example, but couldn't find any examples.

I've tried to do a loop in which the subtraction should be between the values with [index+1] minus value [index] (like below)

t = f->time(:)   ;size = 365

pp = f->TOTALRAIN(:,:,:) ; time, lat, lon dimensions


do i = 0,dimsizes(t)-1

DailyPp = pp(i,:,:) - pp(i-1,:,:)

end do

but that way produces an error.

I need the daily values and only have accumulated precipitation as input information, and thought that a loop like that should be the best way.

How can I do the calculation from the variable???

I'm working with ncl but if you have cdo or nco propositions they're welcome.

2

There are 2 best solutions below

0
On

you can do this with two nco shell commands

the ncks command shifts the records up by one

ncks -v TOTALRAIN --msa_usr_rdr -d time,1,364 -d time,364 in.nc shift.nc

now use ncbo to find the difference

ncbo -v TOTALRAIN shift.nc in.nc diff.nc

now the netcdf file diff should contain your daily pp The final record of TOTALRAIN in this file will be zero's.

0
On

In cdo you can disaggregate accumulated variables using

cdo deltat in.nc diff.nc 

This is related to this question, please refer to the answers there for more details, including inserting the initial timestep.