Project

General

Profile

Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts

Added by Sandro Calmanti over 5 years ago

Hi all,

I'm trying to use CDO for the computation of time derivatives in NETCDF.
The problem arises in the processing ECMWF model output for seasonal forecasts where rainfall is provided as cumulated from the beginning of the forecast, whereas I'm looking for daily values and I would like to include this in the CDO pre-processing.

I'm trying to play with timeshift and setaxis but I'm wondering if anyone has already worked on similar problems or if any simple solution already exists in CDO.
Attached, the netcdf file I'm trying to process

Best!

Sandro


Replies (6)

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Karin Meier-Fleischer over 5 years ago

Hi Sandro,

you can write a shell script and loop through time. Here is an example which extracts level 50, subtracts the fields of the timesteps n and n-1, and merge the temporary files to the output file outfile_daily_values_totprec_201710_075.nc.

#!/bin/ksh

#-- de-compute the single daily values of variable tp from cumulative data

infile=totprec_201710_075.nc
outfile=outfile_daily_values_totprec_201710_075.nc

#-- use -b 32 because tp is of type short

cdo -b 32 -select,level=50 $infile tmp_50.nc

#-- save first timestep

cdo -seltimestep,1 tmp_50.nc tmp_N_1.nc

#-- loop through the timestep and subtract field1 from field 2

for j in $(seq 2 215)
do
   i=$(expr $j - 1)
   cdo -seltimestep,$i tmp_50.nc tmp_$i.nc
   cdo -seltimestep,$j tmp_50.nc tmp_$j.nc
   cdo -sub tmp_$j.nc tmp_$i.nc tmp_N_$j.nc
done

cdo -O mergetime tmp_N_*.nc $outfile
rm -rf tmp_N_*.nc

exit

-Karin

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Sandro Calmanti over 5 years ago

Thank you Karin.

I was trying with a set of instructions using shift time.
It seems to work nicely.
Thanks for helping!

#Shift time axis and remove the first record
cdo -delete,timestep=1 -shifttime,-1day $FILEIN $WDIR/${BASENAME}_B.nc
#Remove the last record
cdo -delete,timestep=-1 $FILEIN $WDIR/${BASENAME}_A.nc
#Store the cumulated during first day in a separate file
cdo -b 32 -shifttime,-1day -seltimestep,1 $FILEIN $WDIR/${BASENAME}_A1.nc
#Compute daily cumulated
cdo -b 32 -sub $WDIR/${BASENAME}_B.nc $WDIR/${BASENAME}_A.nc ${WDIR}/${BASENAME}_C.nc
#Merge back the first day
cdo -O -mergetime $WDIR/${BASENAME}_A1.nc ${WDIR}/${BASENAME}_C.nc ${WDIR}/${BASENAME}.nc

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Ralf Mueller over 5 years ago

please checkout the operator deltat. it;s not documented, but computes differences between consecutive timesteps

hth
ralf

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Sandro Calmanti over 5 years ago

Thank you Ralf, this is what we where looking for.

Best!

S.

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Silvana Bolaños about 5 years ago

Ralf Mueller wrote:

please checkout the operator deltat. it;s not documented, but computes differences between consecutive timesteps

hth
ralf

Hi Ralf,

Thanks for you help, the operator deltat worked in a computer with the last version of Ubuntu (18.04), but in mine, which version is 16.04 the operator deltat doesn't work, and I see that the cdo version is 1.7.0. When I tried to upgrate to the last version, nothing happens, it stills in 1.7.0. So, this is due to the version of Ubuntu?? or there is another thing that I can do to upgrate cdo and use the operator?

Kind regards,

Silvana

RE: Time derivative with CDO: from cumulated to daily rainfall with ECMWF forecasts - Added by Ralf Mueller about 5 years ago

Hi Silvana!

the debian package for the debian-based distros is usually outdated because of the long release cycle of debian.

Anaconda is an easy option to install cdo on your own. does this work for you?

hth
ralf

    (1-6/6)